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: (#1729) Make attributes field optional #1730

Merged
merged 4 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 5 additions & 0 deletions .changeset/spicy-doors-lie.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@faustwp/blocks': patch
---

Make attributes field optional to comply with the WordPressBlock interface
blakewilson marked this conversation as resolved.
Show resolved Hide resolved
4 changes: 2 additions & 2 deletions packages/blocks/src/blocks/CoreButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ContentBlock } from '../components/WordPressBlocksViewer.js';
import { getStyles } from '../utils/index.js';

export type CoreButtonFragmentProps = ContentBlock & {
attributes: {
attributes?: {
anchor?: string;
backgroundColor?: string;
cssClassName?: string;
Expand All @@ -28,7 +28,7 @@ export function CoreButton(props: CoreButtonFragmentProps) {
const theme = useBlocksTheme();
const style = getStyles(theme, { ...props });
const { attributes } = props;
const linkTarget = attributes.linkTarget ? '_blank' : undefined;
const linkTarget = attributes?.linkTarget ? '_blank' : undefined;
if (attributes?.url) {
return (
<div
Expand Down
2 changes: 1 addition & 1 deletion packages/blocks/src/blocks/CoreButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
} from '../components/WordPressBlocksViewer.js';

export type CoreButtonsFragmentProps = ContentBlock & {
attributes: {
attributes?: {
cssClassName?: string;
align?: string;
anchor?: string;
Expand Down
2 changes: 1 addition & 1 deletion packages/blocks/src/blocks/CoreCode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ContentBlock } from '../components/WordPressBlocksViewer.js';
import { getStyles } from '../utils/index.js';

export type CoreCodeFragmentProps = ContentBlock & {
attributes: {
attributes?: {
anchor?: string;
backgroundColor?: string;
borderColor?: string;
Expand Down
2 changes: 1 addition & 1 deletion packages/blocks/src/blocks/CoreColumn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
} from '../components/WordPressBlocksViewer.js';

export type CoreColumnFragmentProps = ContentBlock & {
attributes: {
attributes?: {
cssClassName?: string;
align?: string;
anchor?: string;
Expand Down
2 changes: 1 addition & 1 deletion packages/blocks/src/blocks/CoreColumns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
} from '../components/WordPressBlocksViewer.js';

export type CoreColumnsFragmentProps = ContentBlock & {
attributes: {
attributes?: {
cssClassName?: string;
align?: string;
anchor?: string;
Expand Down
2 changes: 1 addition & 1 deletion packages/blocks/src/blocks/CoreHeading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ContentBlock } from '../components/WordPressBlocksViewer.js';
import { getStyles } from '../utils/index.js';

export type CoreHeadingFragmentProps = ContentBlock & {
attributes: {
attributes?: {
align?: string;
anchor?: string;
backgroundColor?: string;
Expand Down
6 changes: 3 additions & 3 deletions packages/blocks/src/blocks/CoreImage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ContentBlock } from '../components/WordPressBlocksViewer.js';
import { getStyles } from '../utils/index.js';

export type CoreImageFragmentProps = ContentBlock & {
attributes: {
attributes?: {
align?: string;
alt?: string;
anchor?: string;
Expand Down Expand Up @@ -34,7 +34,7 @@ export type CoreImageFragmentProps = ContentBlock & {
function LinkWrapper(props: PropsWithChildren<CoreImageFragmentProps>) {
const { attributes, children } = props;

if (!attributes.href) {
if (!attributes?.href) {
/**
* Fragment is used to fix the following TS error:
* 'LinkWrapper' cannot be used as a JSX component.
Expand Down Expand Up @@ -66,7 +66,7 @@ function ImgWrapper(props: PropsWithChildren<CoreImageFragmentProps>) {
const style = getStyles(theme, { ...props });
const { attributes } = props;

if (!attributes.src) {
if (!attributes?.src) {
return null;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/blocks/src/blocks/CoreList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ContentBlock } from '../components/WordPressBlocksViewer.js';
import { getStyles } from '../utils/index.js';

export type CoreListFragmentProps = ContentBlock & {
attributes: {
attributes?: {
anchor?: string;
backgroundColor?: string;
className?: string;
Expand Down
2 changes: 1 addition & 1 deletion packages/blocks/src/blocks/CoreParagraph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { useBlocksTheme } from '../components/WordPressBlocksProvider.js';
import { ContentBlock } from '../components/WordPressBlocksViewer.js';

export type CoreParagraphFragmentProps = ContentBlock & {
attributes: {
attributes?: {
cssClassName?: string;
backgroundColor?: string;
content?: string;
Expand Down
8 changes: 4 additions & 4 deletions packages/blocks/src/blocks/CoreQuote.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ContentBlock } from '../components/WordPressBlocksViewer.js';
import { getStyles } from '../utils/index.js';

export type CoreQuoteFragmentProps = ContentBlock & {
attributes: {
attributes?: {
align?: string;
anchor?: string;
backgroundColor?: string;
Expand All @@ -27,19 +27,19 @@ export function CoreQuote(props: CoreQuoteFragmentProps) {
const style = getStyles(theme, { ...props });
const { attributes } = props;

if (!attributes.value) {
if (!attributes?.value) {
return null;
}

let innerHtml = attributes.value;

if (attributes.citation) {
if (attributes?.citation) {
innerHtml += `<cite>${attributes.citation}</cite>`;
}

return (
<blockquote
className={attributes.cssClassName}
className={attributes?.cssClassName}
style={style}
// eslint-disable-next-line react/no-danger
dangerouslySetInnerHTML={{ __html: innerHtml }}
Expand Down
2 changes: 1 addition & 1 deletion packages/blocks/src/blocks/CoreSeparator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ContentBlock } from '../components/WordPressBlocksViewer.js';
import { getStyles } from '../utils/index.js';

export type CoreSeparatorFragmentProps = ContentBlock & {
attributes: {
attributes?: {
align?: string;
anchor?: string;
backgroundColor?: string;
Expand Down
Loading