Skip to content

Commit

Permalink
fix: (#1729) Make attributes field optional (#1730)
Browse files Browse the repository at this point in the history
* fix: (#1729) Make attributes field optional

* Update .changeset/spicy-doors-lie.md

---------

Co-authored-by: Blake Wilson <[email protected]>
Co-authored-by: Blake Wilson <[email protected]>
  • Loading branch information
3 people authored Feb 7, 2024
1 parent c6dedc0 commit f6c6b0c
Show file tree
Hide file tree
Showing 12 changed files with 22 additions and 17 deletions.
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': major
---

**BREAKING**: Make `attributes` field on core blocks optional to comply with the `WordPressBlock` type interface. Thanks @traed!
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

0 comments on commit f6c6b0c

Please sign in to comment.