-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e8a7c95
commit 686ea35
Showing
12 changed files
with
534 additions
and
152 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,23 +4,26 @@ import { Placeholder, Spinner, ToolbarGroup } from '@wordpress/components'; | |
import { isBlobURL } from '@wordpress/blob'; | ||
import { ImagePrimitive, ImagePrimitiveValue } from '../shared/types.js'; | ||
import { useBlockPrimitiveProps } from './block.js'; | ||
import FrontEndImagePrimitive from '../primitives/image.js'; | ||
|
||
/** | ||
Check warning on line 9 in packages/block-primitives/src/block-editor/image.tsx GitHub Actions / eslint (20.x)
Check warning on line 9 in packages/block-primitives/src/block-editor/image.tsx GitHub Actions / eslint (20.x)
|
||
* The Image Block Editor Primitive | ||
* | ||
* Expects an attribute of type {@link ImagePrimitiveValue} | ||
*/ | ||
const Image = ({ | ||
name, | ||
onPrimitiveSelect, | ||
mediaURL, | ||
mediaId, | ||
title = 'Edit Media', | ||
value, | ||
accept = 'image/*,video/*', | ||
allowedTypes = ['image'], | ||
...rest | ||
}: ImagePrimitive) => { | ||
const Image = (props: ImagePrimitive) => { | ||
const { | ||
name, | ||
onPrimitiveSelect, | ||
mediaURL, | ||
mediaId, | ||
title = 'Edit Media', | ||
value, | ||
accept = 'image/*,video/*', | ||
allowedTypes = ['image'], | ||
...rest | ||
} = props; | ||
|
||
const { attributes, setAttributes } = useBlockPrimitiveProps(); | ||
|
||
const defaultOnPrimitive: ImagePrimitive['onPrimitiveSelect'] = ( | ||
|
@@ -35,7 +38,7 @@ const Image = ({ | |
}; | ||
|
||
const attribute: ImagePrimitiveValue = attributes[name] ?? value ?? {}; | ||
const { id, url, alt } = attribute; | ||
const { id, url } = attribute; | ||
|
||
const isUploading = !id && isBlobURL(url); | ||
|
||
|
@@ -68,8 +71,8 @@ const Image = ({ | |
)} | ||
</Placeholder> | ||
) : null} | ||
{/* TOOD: Maybe just use the front-end primitive here */} | ||
{!isUploading && id ? <img src={url} alt={alt ?? ''} /> : null} | ||
|
||
{!isUploading && id ? <FrontEndImagePrimitive {...props} value={attribute} /> : null} | ||
</> | ||
); | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { FC } from 'react'; | ||
import { Link as LinkBlockComponent } from '@10up/block-components'; | ||
import { useBlockProps } from '@wordpress/block-editor'; | ||
import { LinkPrimitiveValue, LinkProps } from '#shared/types.js'; | ||
import { useBlockPrimitiveProps } from './block.js'; | ||
|
||
const Link: FC<LinkProps> = ({ | ||
name, | ||
value, | ||
className, | ||
placeholder = 'Enter Link Text here...', | ||
}) => { | ||
const blockProps = useBlockProps(); | ||
const { attributes, setAttributes } = useBlockPrimitiveProps(); | ||
|
||
const attribute: LinkPrimitiveValue = attributes[name] ?? value ?? {}; | ||
const { url, opensInNewTab, title } = attribute; | ||
|
||
const defaultOnPrimitiveChange = (_name, _value: LinkPrimitiveValue, _setAttributes) => | ||
_setAttributes({ [_name]: _value }); | ||
|
||
const _onPrimitiveChange = defaultOnPrimitiveChange; | ||
|
||
return ( | ||
<div {...blockProps}> | ||
<LinkBlockComponent | ||
value={title} | ||
url={url} | ||
opensInNewTab={opensInNewTab} | ||
onTextChange={(text) => | ||
_onPrimitiveChange(name, { ...attribute, text }, setAttributes) | ||
} | ||
onLinkChange={(link) => | ||
_onPrimitiveChange(name, { ...attribute, ...link }, setAttributes) | ||
} | ||
onLinkRemove={() => { | ||
_onPrimitiveChange( | ||
name, | ||
{ url: '', text: '', title: '', opensInNewTab: false }, | ||
setAttributes, | ||
); | ||
}} | ||
className={className} | ||
placeholder={placeholder} | ||
/> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Link; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { FC } from 'react'; | ||
import { LinkProps } from '#shared/types.js'; | ||
|
||
const Link: FC<LinkProps> = ({ className, value }) => { | ||
if (typeof value === 'undefined') { | ||
return null; | ||
} | ||
|
||
return ( | ||
<a | ||
href={value.url} | ||
className={className} | ||
title={value.title} | ||
target={value.opensInNewTab ? '_blank' : '_self'} | ||
rel="noreferrer" | ||
> | ||
{value.text ?? value.text} | ||
</a> | ||
); | ||
}; | ||
|
||
export default Link; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,9 @@ | |
}, | ||
"image": { | ||
"type": "object" | ||
}, | ||
"link": { | ||
"type": "object" | ||
} | ||
}, | ||
"example": { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters