-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Add reusable blocks data layer #3017
Changes from all commits
d8400a8
19c86aa
ae8fc05
d6e0cf2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,11 @@ import { | |
find, | ||
} from 'lodash'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
|
@@ -116,3 +121,19 @@ export function switchToBlockType( block, name ) { | |
uid: index === firstSwitchedBlock ? block.uid : result.uid, | ||
} ) ); | ||
} | ||
|
||
/** | ||
* Creates a new reusable block. | ||
* | ||
* @param {String} type The type of the block referenced by the reusable block | ||
* @param {Object} attributes The attributes of the block referenced by the reusable block | ||
* @return {Object} A reusable block object | ||
*/ | ||
export function createReusableBlock( type, attributes ) { | ||
return { | ||
id: uuid(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The apparent overlap yet disconnect between a reusable block's Do you have any thoughts? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd be into aligning them so long as we're explicit when writing code that interacts with both types of ID, e.g: const blockId = block.id;
const reusableBlockId = block.attributes.ref; This would be a breaking change though, since there might be third party code that references |
||
name: __( 'Untitled block' ), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would there ever be a case where we want to create a reusable block and assign its name immediately? A bit awkward to achieve now, since name is not accepted as an argument of the function. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No such case was in our design so I figured you aren't gonna need it. We could add an optional argument in the future if it comes up. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should support this and have UI that focus on the name input before saving. cc @jasmussen |
||
type, | ||
attributes, | ||
}; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,3 +22,4 @@ import './text-columns'; | |
import './verse'; | ||
import './video'; | ||
import './audio'; | ||
import './reusable-block'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { registerBlockType } from '../../api'; | ||
|
||
registerBlockType( 'core/reusable-block', { | ||
title: __( 'Reusable Block' ), | ||
category: 'reusable-blocks', | ||
isPrivate: true, | ||
|
||
attributes: { | ||
ref: { | ||
type: 'string', | ||
}, | ||
}, | ||
|
||
edit: () => <div>{ __( 'Reusable Blocks are coming soon!' ) }</div>, | ||
save: () => null, | ||
} ); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<!-- wp:core/reusable-block {"ref":"358b59ee-bab3-4d6f-8445-e8c6971a5605"} /--> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[ | ||
{ | ||
"uid": "_uid_0", | ||
"name": "core/reusable-block", | ||
"isValid": true, | ||
"attributes": { | ||
"ref": "358b59ee-bab3-4d6f-8445-e8c6971a5605" | ||
}, | ||
"originalContent": "" | ||
} | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[ | ||
{ | ||
"blockName": "core/reusable-block", | ||
"attrs": { | ||
"ref": "358b59ee-bab3-4d6f-8445-e8c6971a5605" | ||
}, | ||
"rawContent": "" | ||
}, | ||
{ | ||
"attrs": {}, | ||
"rawContent": "\n" | ||
} | ||
] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<!-- wp:reusable-block {"ref":"358b59ee-bab3-4d6f-8445-e8c6971a5605"} /--> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These should probably be allocated in another "tab" (like recent, blocks, embeds) rather than a category. The names should probably be "Saved". cc @jasmussen