-
Notifications
You must be signed in to change notification settings - Fork 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
Gutenberg: start editor shell in Calypso #26438
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
ad60591
Gutenberg: import @wordpress/editor package
vindl 436b3e2
Copy over edit-post folder
vindl 1ed3cca
Mock registerCoreBlocks call
vindl 84cbab5
Initialize core/edit-post store
vindl bc078c4
Reduce the number of edit-post components used
vindl 581feac
Move css imports
vindl 85c62b5
Import @wordpress/core-data to initialize core store
vindl 827868d
Override core API requests
vindl 8f94cd5
Noop API requests for now
vindl 9f46016
Reinstate some of the edit-post components
vindl 1719c75
Fix or ignore eslint errors
vindl dcd9f7a
Remove obsolete globals
vindl a11e6fd
Rebase and update
vindl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import React from 'react'; | ||
import { range } from 'lodash'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __, sprintf } from '@wordpress/i18n'; | ||
import { Fragment } from '@wordpress/element'; | ||
import { PanelBody, Toolbar } from '@wordpress/components'; | ||
import { createBlock } from '@wordpress/blocks'; | ||
import { RichText, BlockControls, InspectorControls, AlignmentToolbar } from '@wordpress/editor'; | ||
|
||
export default function HeadingEdit( { | ||
attributes, | ||
setAttributes, | ||
mergeBlocks, | ||
insertBlocksAfter, | ||
onReplace, | ||
className, | ||
} ) { | ||
const { align, content, level, placeholder } = attributes; | ||
const tagName = 'h' + level; | ||
|
||
function createLevelControl( targetLevel ) { | ||
return { | ||
icon: 'heading', | ||
// translators: %s: heading level e.g: "1", "2", "3" | ||
title: sprintf( __( 'Heading %d' ), targetLevel ), | ||
isActive: targetLevel === level, | ||
onClick: () => setAttributes( { level: targetLevel } ), | ||
subscript: String( targetLevel ), | ||
}; | ||
} | ||
|
||
return ( | ||
<Fragment> | ||
<BlockControls> | ||
<Toolbar controls={ range( 2, 5 ).map( createLevelControl ) } /> | ||
</BlockControls> | ||
<InspectorControls> | ||
<PanelBody title={ __( 'Heading Settings' ) }> | ||
<p>{ __( 'Level' ) }</p> | ||
<Toolbar controls={ range( 1, 7 ).map( createLevelControl ) } /> | ||
<p>{ __( 'Text Alignment' ) }</p> | ||
<AlignmentToolbar | ||
value={ align } | ||
onChange={ ( nextAlign ) => { | ||
setAttributes( { align: nextAlign } ); | ||
} } | ||
/> | ||
</PanelBody> | ||
</InspectorControls> | ||
<RichText | ||
wrapperClassName="wp-block-heading" | ||
tagName={ tagName } | ||
value={ content } | ||
onChange={ ( value ) => setAttributes( { content: value } ) } | ||
onMerge={ mergeBlocks } | ||
onSplit={ | ||
insertBlocksAfter ? | ||
( before, after, ...blocks ) => { | ||
setAttributes( { content: before } ); | ||
insertBlocksAfter( [ | ||
...blocks, | ||
createBlock( 'core/paragraph', { content: after } ), | ||
] ); | ||
} : | ||
undefined | ||
} | ||
onRemove={ () => onReplace( [] ) } | ||
style={ { textAlign: align } } | ||
className={ className } | ||
placeholder={ placeholder || __( 'Write heading…' ) } | ||
/> | ||
</Fragment> | ||
); | ||
} |
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,46 @@ | ||
.wp-block-heading { | ||
h1, | ||
h2, | ||
h3, | ||
h4, | ||
h5, | ||
h6 { | ||
margin: 0; | ||
} | ||
|
||
// These follow a Major Third type scale | ||
h1 { | ||
font-size: 2.44em; | ||
} | ||
|
||
h2 { | ||
font-size: 1.95em; | ||
} | ||
|
||
h3 { | ||
font-size: 1.56em; | ||
} | ||
|
||
h4 { | ||
font-size: 1.25em; | ||
} | ||
|
||
h5 { | ||
font-size: 1em; | ||
} | ||
|
||
h6 { | ||
font-size: 0.8em; | ||
} | ||
|
||
// Adjust line spacing for larger headings. | ||
h1.editor-rich-text__tinymce, | ||
h2.editor-rich-text__tinymce, | ||
h3.editor-rich-text__tinymce { | ||
line-height: 1.4; | ||
} | ||
|
||
h4.editor-rich-text__tinymce { | ||
line-height: 1.5; | ||
} | ||
} |
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,192 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import React from 'react'; | ||
import { omit } from 'lodash'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { | ||
createBlock, | ||
getPhrasingContentSchema, | ||
getBlockAttributes, | ||
getBlockType, | ||
children, | ||
} from '@wordpress/blocks'; | ||
import { RichText } from '@wordpress/editor'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import edit from './edit'; | ||
|
||
/** | ||
* Given a node name string for a heading node, returns its numeric level. | ||
* | ||
* @param {string} nodeName Heading node name. | ||
* | ||
* @return {number} Heading level. | ||
*/ | ||
export function getLevelFromHeadingNodeName( nodeName ) { | ||
return Number( nodeName.substr( 1 ) ); | ||
} | ||
|
||
const supports = { | ||
className: false, | ||
anchor: true, | ||
}; | ||
|
||
const schema = { | ||
content: { | ||
type: 'array', | ||
source: 'children', | ||
selector: 'h1,h2,h3,h4,h5,h6', | ||
}, | ||
level: { | ||
type: 'number', | ||
default: 2, | ||
}, | ||
align: { | ||
type: 'string', | ||
}, | ||
placeholder: { | ||
type: 'string', | ||
}, | ||
}; | ||
|
||
export const name = 'core/heading'; | ||
|
||
export const settings = { | ||
title: __( 'Heading' ), | ||
|
||
description: __( 'Insert a headline above your post or page content.' ), | ||
|
||
icon: 'heading', | ||
|
||
category: 'common', | ||
|
||
keywords: [ __( 'title' ), __( 'subtitle' ) ], | ||
|
||
supports, | ||
|
||
attributes: schema, | ||
|
||
transforms: { | ||
from: [ | ||
{ | ||
type: 'block', | ||
blocks: [ 'core/paragraph' ], | ||
transform: ( { content } ) => { | ||
return createBlock( 'core/heading', { | ||
content, | ||
} ); | ||
}, | ||
}, | ||
{ | ||
type: 'raw', | ||
selector: 'h1,h2,h3,h4,h5,h6', | ||
schema: { | ||
h1: { children: getPhrasingContentSchema() }, | ||
h2: { children: getPhrasingContentSchema() }, | ||
h3: { children: getPhrasingContentSchema() }, | ||
h4: { children: getPhrasingContentSchema() }, | ||
h5: { children: getPhrasingContentSchema() }, | ||
h6: { children: getPhrasingContentSchema() }, | ||
}, | ||
transform( node ) { | ||
return createBlock( 'core/heading', { | ||
...getBlockAttributes( | ||
getBlockType( 'core/heading' ), | ||
node.outerHTML | ||
), | ||
level: getLevelFromHeadingNodeName( node.nodeName ), | ||
} ); | ||
}, | ||
}, | ||
{ | ||
type: 'pattern', | ||
regExp: /^(#{2,6})\s/, | ||
transform: ( { content, match } ) => { | ||
const level = match[ 1 ].length; | ||
|
||
return createBlock( 'core/heading', { | ||
level, | ||
content, | ||
} ); | ||
}, | ||
}, | ||
], | ||
to: [ | ||
{ | ||
type: 'block', | ||
blocks: [ 'core/paragraph' ], | ||
transform: ( { content } ) => { | ||
return createBlock( 'core/paragraph', { | ||
content, | ||
} ); | ||
}, | ||
}, | ||
], | ||
}, | ||
|
||
deprecated: [ | ||
{ | ||
supports, | ||
attributes: { | ||
...omit( schema, [ 'level' ] ), | ||
nodeName: { | ||
type: 'string', | ||
source: 'property', | ||
selector: 'h1,h2,h3,h4,h5,h6', | ||
property: 'nodeName', | ||
default: 'H2', | ||
}, | ||
}, | ||
migrate( attributes ) { | ||
const { nodeName, ...migratedAttributes } = attributes; | ||
|
||
return { | ||
...migratedAttributes, | ||
level: getLevelFromHeadingNodeName( nodeName ), | ||
}; | ||
}, | ||
save( { attributes } ) { | ||
const { align, nodeName, content } = attributes; | ||
|
||
return ( | ||
<RichText.Content | ||
tagName={ nodeName.toLowerCase() } | ||
style={ { textAlign: align } } | ||
value={ content } | ||
/> | ||
); | ||
}, | ||
}, | ||
], | ||
|
||
merge( attributes, attributesToMerge ) { | ||
return { | ||
content: children.concat( | ||
attributes.content, | ||
attributesToMerge.content | ||
), | ||
}; | ||
}, | ||
|
||
edit, | ||
|
||
save( { attributes } ) { | ||
const { align, level, content } = attributes; | ||
const tagName = 'h' + level; | ||
|
||
return ( | ||
<RichText.Content | ||
tagName={ tagName } | ||
style={ { textAlign: align } } | ||
value={ content } | ||
/> | ||
); | ||
}, | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
SCSS variables and helpers from the
assets
folder could probably be published to npm as its own package. What do you think?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.
It would probably help us in the short term, but given that we are supposed to re-implement Calypso specific versions of edit post components, I'm not sure if we'll be reusing them in the long run.
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.
not worth the effort then
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.
Depends on if core wants to eventually publish
edit-post
we'll untangle this in a bit otherwise in follow up PRs.