-
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 13 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 |
---|---|---|
|
@@ -25,6 +25,14 @@ body.toplevel_page_gutenberg { | |
svg { | ||
fill: currentColor; | ||
} | ||
|
||
ul { | ||
list-style-type: disc; | ||
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. 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 commentThe 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. |
||
} | ||
|
||
ol { | ||
list-style-type: decimal; | ||
} | ||
} | ||
|
||
.gutenberg__editor { | ||
|
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,43 @@ | ||
const Editable = wp.blocks.Editable; | ||
const { html, prop } = wp.blocks.query; | ||
|
||
function List( { nodeName, children } ) { | ||
// nodeName.toLowerCase() is used to map DOM nodeName values to proper tag. | ||
return wp.element.createElement( nodeName.toLowerCase(), null, children ); | ||
} | ||
|
||
wp.blocks.registerBlock( 'core/list', { | ||
title: '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( i => { | ||
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. In general I think we should avoid non-descript variable names like |
||
return `<li>${ i.value }</li>`; | ||
} ).join( '' ); | ||
|
||
return ( | ||
<Editable | ||
nodeName={ listType } | ||
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.
|
||
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( ( i, index ) => <li key={ index }>{ i.value }</li> ); | ||
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'll probably need to const children = items.map( ( item, index ) => (
<li dangerouslySetInnerHTML={ { __html: item.value } } />
) ); I'd be curious to know whether |
||
return <List nodeName={ listType }>{ children }</List>; | ||
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. Since we're not reusing the |
||
} | ||
} ); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,15 +3,15 @@ msgstr "" | |
"Content-Type: text/plain; charset=utf-8\n" | ||
"X-Generator: babel-plugin-wp-i18n\n" | ||
|
||
#: editor/blocks/freeform/index.js:4 | ||
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. See also: #377 We could probably skip these changes. I'll hope to tackle this in the next day. 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. Actually, on the topic of localization, we should localize the block's title. See text bock as example: https://github.com/WordPress/gutenberg/blob/f1b8d8d/editor/blocks/text/index.js#L5 |
||
msgid "Freeform" | ||
msgstr "" | ||
|
||
#: editor/header/mode-switcher/index.js:31 | ||
msgctxt "Name for the Text editor tab (formerly HTML)" | ||
msgid "Text" | ||
msgstr "" | ||
|
||
#: editor/blocks/freeform/index.js:4 | ||
msgid "Freeform" | ||
msgstr "" | ||
|
||
#: editor/header/mode-switcher/index.js:30 | ||
msgid "Visual" | ||
msgstr "" | ||
|
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.
There's no
nodeName
prop forEditable
and an effective default is already assigned in therender
. We can remove this set of lines.