-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Early List block implementation (no UI yet) #358
Changes from all commits
f565b8c
f35c593
3e96e6e
ecf4e28
a6b4e9f
ce33c03
374fb7b
7c7af5f
67ed22d
06c44d7
6a42a5d
c8bf285
69aa433
68427de
b00b4b8
821ac5d
e370326
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 |
---|---|---|
@@ -1,2 +1,4 @@ | ||
import './freeform'; | ||
import './text'; | ||
import './list'; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
const Editable = wp.blocks.Editable; | ||
const { html, prop } = wp.blocks.query; | ||
|
||
wp.blocks.registerBlock( 'core/list', { | ||
title: wp.i18n.__( 'List' ), | ||
icon: 'editor-ul', | ||
category: 'common', | ||
|
||
attributes: { | ||
listType: prop( 'ol,ul', 'nodeName' ), | ||
items: wp.blocks.query.query( | ||
'li', | ||
{ | ||
value: html() | ||
} | ||
) | ||
}, | ||
|
||
edit( { attributes, onChange } ) { | ||
const { listType = 'ol', items = [] } = attributes; | ||
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. When not default, |
||
const value = items.map( item => { | ||
return `<li>${ item.value }</li>`; | ||
} ).join( '' ); | ||
|
||
return ( | ||
<Editable | ||
tagName={ listType } | ||
value={ value } | ||
onChange={ onChange } /> | ||
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. We can improve this in a future pull request, but just FYI that this isn't really doing anything. You'll probably want to set this up so that |
||
); | ||
}, | ||
|
||
save( { attributes } ) { | ||
const { listType = 'ol', items = [] } = attributes; | ||
const children = items.map( ( item, index ) => ( | ||
<li key={ index } dangerouslySetInnerHTML={ { __html: item.value } } /> | ||
) ); | ||
return wp.element.createElement( listType.toLowerCase(), null, children ); | ||
} | ||
} ); |
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.
Should these be generic across the entire editor canvas or specific to the blocks we're implementing?
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.
I would keep these generic as these styles can be applied to the generic freeform block as well. In the future these might go away if we decide that the list block can support multiple styles of lists.
Without these styles the default list style type is none in the wp-admin page.