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

Fix image block schema #435

Merged
merged 9 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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/volto-light-theme/news/435.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix Image block schema @danalvrz
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@danalvrz Can you be more specific? This PR is hard to review because I don't know what you're trying to fix.

Copy link
Contributor Author

@danalvrz danalvrz Dec 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@davisagli I just updated it, thanks! With the new widget and image options on VLT 6 there was an issue with undefined properties when nesting an Image in a Grid block. With this change we enhance the Image schema more accurately based on its context.

40 changes: 24 additions & 16 deletions packages/volto-light-theme/src/components/Blocks/Image/schema.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { defineMessages } from 'react-intl';
import { insertInArray, reorderArray } from '@plone/volto/helpers/Utils/Utils';
import { insertInArray } from '@plone/volto/helpers/Utils/Utils';
import config from '@plone/volto/registry';

const messages = defineMessages({
Expand All @@ -19,7 +19,6 @@ const messages = defineMessages({

export const imageBlockSchemaEnhancer = ({ formData, schema, intl }) => {
if (formData.url) {
schema.fieldsets = reorderArray(schema.fieldsets, 2, 1);
schema.fieldsets[0].fields = insertInArray(
schema.fieldsets[0].fields,
'description',
Expand All @@ -31,6 +30,29 @@ export const imageBlockSchemaEnhancer = ({ formData, schema, intl }) => {
1,
);

schema.properties.description = {
title: intl.formatMessage(messages.Description),
widget: 'textarea',
};
schema.properties.title = {
title: intl.formatMessage(messages.Title),
};
}

return schema;
};

export const standAloneImageBlockSchemaEnhancer = ({
formData,
schema,
intl,
}) => {
if (formData.url) {
schema.properties.align.default = 'center';
schema.properties.align.actions = ['left', 'right', 'center'];

schema.properties.size.default = 'l';
schema.properties.size.disabled = formData.align === 'center';
schema.properties.styles.schema.fieldsets[0].fields = [
'blockWidth:noprefix',
'--image-aspect-ratio',
Expand All @@ -54,20 +76,6 @@ export const imageBlockSchemaEnhancer = ({ formData, schema, intl }) => {
],
};

schema.properties.description = {
title: intl.formatMessage(messages.Description),
widget: 'textarea',
};
schema.properties.title = {
title: intl.formatMessage(messages.Title),
};

schema.properties.align.default = 'center';
schema.properties.align.actions = ['left', 'right', 'center'];

schema.properties.size.default = 'l';
schema.properties.size.disabled = formData.align === 'center';

schema.properties.styles.schema.properties['blockWidth:noprefix'].disabled =
formData.align === 'left' || formData.align === 'right';
}
Expand Down
6 changes: 5 additions & 1 deletion packages/volto-light-theme/src/config/blocks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ import GridListingBlockTemplate from '../components/Blocks/Listing/GridTemplate'
import { ButtonStylingSchema } from '../components/Blocks/Button/schema';
import { SeparatorStylingSchema } from '../components/Blocks/Separator/schema';

import { imageBlockSchemaEnhancer } from '../components/Blocks/Image/schema';
import {
imageBlockSchemaEnhancer,
standAloneImageBlockSchemaEnhancer,
} from '../components/Blocks/Image/schema';
import { ImageBlockDataAdapter } from '../components/Blocks/Image/adapter';

import { AccordionSchemaEnhancer } from '../components/Blocks/Accordion/schema';
Expand Down Expand Up @@ -208,6 +211,7 @@ export default function install(config: ConfigType) {
schemaEnhancer: composeSchema(
defaultStylingSchema,
imageBlockSchemaEnhancer,
standAloneImageBlockSchemaEnhancer,
),
dataAdapter: ImageBlockDataAdapter,
};
Expand Down
4 changes: 2 additions & 2 deletions packages/volto-light-theme/src/theme/_variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,11 @@ $secondary-grey: #ececec !default;
--link-foreground-color: var(--link-color);

// It is possible to set an aspect ratio for all images, using the folowing CSS custom property:
// --image-aspect-ratio: 16/9;
// --image-aspect-ratio: calc(16 / 9);
}

// Image Aspect Ratio
$aspect-ratio: 16/9 !default;
$aspect-ratio: calc(16 / 9) !default;

// Weights
$thin: 100 !default;
Expand Down
Loading