Skip to content
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

Improve @plone/types - Block*Props - Widgets #5876

Merged
merged 5 commits into from
Mar 16, 2024
Merged
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
1 change: 1 addition & 0 deletions packages/types/news/5876.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improve @plone/types - Block*Props and Widgets @sneridagh
4 changes: 4 additions & 0 deletions packages/types/src/blocks/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,8 @@ export interface BlockEditProps {
path: string;
className: string;
style: Record<`--${string}`, string>;
content: Content;
history: History;
location: Location;
token: string;
}
2 changes: 1 addition & 1 deletion packages/types/src/config/Blocks.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export interface BlocksConfigData {
listing: BlockConfigBase;
video: BlockConfigBase;
toc: BlockConfigBase;
hero: BlockConfigBase;
maps: BlockConfigBase;
html: BlockConfigBase;
table: BlockConfigBase;
Expand Down Expand Up @@ -116,6 +115,7 @@ export interface BlockConfigBase {
*/
// TODO: Improve extensions shape
extensions?: Record<string, BlockExtension>;
blocksConfig?: Partial<BlocksConfigData>;
}

export type BlockExtension = (
Expand Down
102 changes: 95 additions & 7 deletions packages/types/src/config/Widgets.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,95 @@
export type WidgetsConfig =
| {
[key: string]: {
[key: string]: React.ComponentType;
};
}
| { defaultWidget: React.ComponentType };
export interface WidgetsConfig {
default: React.ComponentType;
id: {
schema: React.ComponentType;
subjects: React.ComponentType;
query: React.ComponentType;
recurrence: React.ComponentType;
remoteUrl: React.ComponentType;
id: React.ComponentType;
site_logo: React.ComponentType;
};
widget: {
textarea: React.ComponentType;
datetime: React.ComponentType;
date: React.ComponentType;
password: React.ComponentType;
file: React.ComponentType;
align: React.ComponentType;
buttons: React.ComponentType;
url: React.ComponentType;
internal_url: React.ComponentType;
email: React.ComponentType;
array: React.ComponentType;
token: React.ComponentType;
query: React.ComponentType;
query_sort_on: React.ComponentType;
querystring: React.ComponentType;
object_browser: React.ComponentType;
object: React.ComponentType;
object_list: React.ComponentType;
vocabularyterms: React.ComponentType;
image_size: React.ComponentType;
select_querystring_field: React.ComponentType;
autocomplete: React.ComponentType;
color_picker: React.ComponentType;
select: React.ComponentType;
};
vocabulary: {
'plone.app.vocabularies.Catalog': React.ComponentType;
};
factory: {
'Relation List': React.ComponentType;
'Relation Choice': React.ComponentType;
};
choices: React.ComponentType;
type: {
boolean: React.ComponentType;
array: React.ComponentType;
object: React.ComponentType;
datetime: React.ComponentType;
date: React.ComponentType;
password: React.ComponentType;
number: React.ComponentType;
integer: React.ComponentType;
id: React.ComponentType;
};
views: {
getWidget: React.ComponentType;
default: React.ComponentType;
id: {
file: React.ComponentType;
image: React.ComponentType;
relatedItems: React.ComponentType;
subjects: React.ComponentType;
};
widget: {
array: React.ComponentType;
boolean: React.ComponentType;
choices: React.ComponentType;
date: React.ComponentType;
datetime: React.ComponentType;
description: React.ComponentType;
email: React.ComponentType;
file: React.ComponentType;
image: React.ComponentType;
password: React.ComponentType;
relation: React.ComponentType;
relations: React.ComponentType;
richtext: React.ComponentType;
string: React.ComponentType;
tags: React.ComponentType;
textarea: React.ComponentType;
title: React.ComponentType;
url: React.ComponentType;
internal_url: React.ComponentType;
object: React.ComponentType;
};
vocabulary: {};
choices: React.ComponentType;
type: {
array: React.ComponentType;
boolean: React.ComponentType;
};
};
}
1 change: 1 addition & 0 deletions packages/volto/news/5876.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Match props passed to the BlockView if reused from the BlockEdit @sneridagh
4 changes: 4 additions & 0 deletions packages/volto/src/components/manage/Add/Add.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,10 @@ class Add extends Component {
this.setState({ formSelected: 'addForm' });
}}
global
// Properties to pass to the BlocksForm to match the View ones
history={this.props.history}
location={this.props.location}
token={this.props.token}
/>
{this.state.isClient &&
createPortal(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ const BlocksForm = (props) => {
blocksConfig = config.blocks.blocksConfig,
editable = true,
direction = 'vertical',
history,
location,
token,
} = props;

const blockList = getBlocks(properties);
Expand Down Expand Up @@ -271,6 +274,11 @@ const BlocksForm = (props) => {
editable,
showBlockChooser: selectedBlock === childId,
detached: isContainer,
// Properties to pass to the BlocksForm to match the View ones
content: properties,
history,
location,
token,
};
return editBlockWrapper(
dragProps,
Expand Down
4 changes: 4 additions & 0 deletions packages/volto/src/components/manage/Edit/Edit.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,10 @@ class Edit extends Component {
this.setState({ formSelected: 'editForm' });
}}
global
// Properties to pass to the BlocksForm to match the View ones
history={this.props.history}
location={this.props.location}
token={this.props.token}
/>
);

Expand Down
4 changes: 4 additions & 0 deletions packages/volto/src/components/manage/Form/Form.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,10 @@ class Form extends Component {
showRestricted={this.props.showRestricted}
editable={this.props.editable}
isMainForm={this.props.editable}
// Properties to pass to the BlocksForm to match the View ones
history={this.props.history}
location={this.props.location}
token={this.props.token}
/>
{this.state.isClient &&
this.state.sidebarMetadataIsAvailable &&
Expand Down
Loading