Skip to content
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
4 changes: 4 additions & 0 deletions api/register-block-extension/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@
return blockType === blockName;
};

if (blockName === '*') {
blockName = 'all';
}

const blockNamespace = isMultiBlock ? blockName.join('-') : blockName;

Check failure on line 56 in api/register-block-extension/index.tsx

View workflow job for this annotation

GitHub Actions / Cypress

Property 'join' does not exist on type 'string | string[]'.

Check failure on line 56 in api/register-block-extension/index.tsx

View workflow job for this annotation

GitHub Actions / build

Property 'join' does not exist on type 'string | string[]'.

const addAttributesToBlock = (settings: Record<string, any>, name: string) => {
if (!shouldApplyBlockExtension(name)) {
Expand Down
34 changes: 26 additions & 8 deletions components/post-meta/index.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,35 @@
import { RichText } from '@wordpress/block-editor';
import { __experimentalNumberControl as NumberControl, ToggleControl } from '@wordpress/components';
import type { ToggleControlProps } from '@wordpress/components/src/toggle-control/types';
import { usePostMetaValue, useIsSupportedMetaField } from '../../hooks';
import { usePostMetaValue, useIsSupportedMetaField, usePost } from '../../hooks';
import { toSentence } from './utilities';

interface MetaStringProps
extends Omit<React.ComponentPropsWithoutRef<typeof RichText>, 'value' | 'onChange'> {
extends Omit<
React.ComponentPropsWithoutRef<typeof RichText>,
'value' | 'onChange' | 'multiline'
> {
/**
* The meta key to use.
*/
metaKey: string;
}

const MetaString: React.FC<MetaStringProps> = (props) => {
const { metaKey, tagName = 'p' } = props;
const { metaKey, tagName = 'p', ...rest } = props;
const [metaValue, setMetaValue] = usePostMetaValue<string>(metaKey);
const { isEditable } = usePost();

if (!isEditable) {
return <RichText.Content value={metaValue ?? ''} tagName={tagName} {...props} />;
}

return (
<RichText
value={metaValue ?? ''}
onChange={(value: string) => setMetaValue(value)}
tagName={tagName}
{...props}
{...rest}
/>
);
};
Expand All @@ -34,14 +42,16 @@ interface MetaNumberProps {
}

const MetaNumber: React.FC<MetaNumberProps> = (props) => {
const { metaKey } = props;
const { metaKey, ...rest } = props;
const [metaValue, setMetaValue] = usePostMetaValue<number>(metaKey);
const { isEditable } = usePost();

return (
<NumberControl
value={metaValue}
onChange={(value) => setMetaValue(parseInt(value ?? '', 10))}
{...props}
disabled={!isEditable}
{...rest}
/>
);
};
Expand All @@ -54,10 +64,18 @@ interface MetaBooleanProps extends Pick<ToggleControlProps, 'label'> {
}

const MetaBoolean: React.FC<MetaBooleanProps> = (props) => {
const { metaKey } = props;
const { metaKey, ...rest } = props;
const [metaValue, setMetaValue] = usePostMetaValue<boolean>(metaKey);
const { isEditable } = usePost();

return <ToggleControl checked={metaValue} onChange={setMetaValue} {...props} />;
return (
<ToggleControl
checked={metaValue}
onChange={setMetaValue}
disabled={!isEditable}
{...rest}
/>
);
};

interface PostMetaProps {
Expand Down
Loading