-
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
move page template modal into its own package #49661
Merged
Merged
Changes from 11 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
d51fa38
move page template modal into its own package
roo2 7cc0c1a
pr feedback, specify dependency versions
roo2 b47858b
use the page template modal package
roo2 08f86c1
fix package.json
roo2 7ed0642
import change from https://github.com/Automattic/wp-calypso/pull/49695
roo2 965eaaa
add i18n_text_domain global
roo2 5ae086b
extract only the page template modal
roo2 961d6d0
fix imports
roo2 2d60524
include css in build
roo2 d5d7b8b
minor refactor remove unnecessary code
roo2 a94a5a6
update to use transpile, correct import order
roo2 80119dd
remove outdated code
roo2 2905733
remove redundant comment
roo2 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
31 changes: 31 additions & 0 deletions
31
apps/editing-toolkit/editing-toolkit-plugin/starter-page-templates/index.scss
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,31 @@ | ||
@import '~@automattic/page-template-modal/src/styles/page-template-modal'; | ||
|
||
// Sidebar modal opener goo. | ||
.sidebar-modal-opener { | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
justify-content: center; | ||
} | ||
|
||
.sidebar-modal-opener__warning-modal { | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: center; | ||
align-items: center; | ||
} | ||
|
||
.sidebar-modal-opener__warning-text { | ||
max-width: 300px; | ||
font-size: 1rem; | ||
line-height: 1.5rem; | ||
} | ||
|
||
.sidebar-modal-opener__warning-options { | ||
float: right; | ||
margin-top: 20px; | ||
|
||
.components-button { | ||
margin-left: 12px; | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
apps/editing-toolkit/editing-toolkit-plugin/starter-page-templates/page-template-plugin.js
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,77 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { stubTrue } from 'lodash'; | ||
import '@wordpress/nux'; | ||
import { compose } from '@wordpress/compose'; | ||
import { withDispatch, withSelect } from '@wordpress/data'; | ||
import { addFilter, removeFilter } from '@wordpress/hooks'; | ||
import { PageTemplateModal } from '@automattic/page-template-modal'; | ||
|
||
const INSERTING_HOOK_NAME = 'isInsertingPageTemplate'; | ||
const INSERTING_HOOK_NAMESPACE = 'automattic/full-site-editing/inserting-template'; | ||
|
||
export const PageTemplatesPlugin = compose( | ||
withSelect( ( select ) => { | ||
const getMeta = () => select( 'core/editor' ).getEditedPostAttribute( 'meta' ); | ||
const { _starter_page_template } = getMeta(); | ||
const { isOpen } = select( 'automattic/starter-page-layouts' ); | ||
const currentBlocks = select( 'core/editor' ).getBlocks(); | ||
return { | ||
isOpen: isOpen(), | ||
getMeta, | ||
_starter_page_template, | ||
currentBlocks, | ||
currentPostTitle: select( 'core/editor' ).getCurrentPost().title, | ||
postContentBlock: currentBlocks.find( ( block ) => block.name === 'a8c/post-content' ), | ||
isWelcomeGuideActive: select( 'core/edit-post' ).isFeatureActive( 'welcomeGuide' ), // Gutenberg 7.2.0 or higher | ||
areTipsEnabled: select( 'core/nux' ) ? select( 'core/nux' ).areTipsEnabled() : false, // Gutenberg 7.1.0 or lower | ||
}; | ||
} ), | ||
withDispatch( ( dispatch, ownProps ) => { | ||
const editorDispatcher = dispatch( 'core/editor' ); | ||
const { setOpenState } = dispatch( 'automattic/starter-page-layouts' ); | ||
return { | ||
setOpenState, | ||
saveTemplateChoice: ( name ) => { | ||
// Save selected template slug in meta. | ||
const currentMeta = ownProps.getMeta(); | ||
editorDispatcher.editPost( { | ||
meta: { | ||
...currentMeta, | ||
_starter_page_template: name, | ||
}, | ||
} ); | ||
}, | ||
insertTemplate: ( title, blocks ) => { | ||
// Add filter to let the tracking library know we are inserting a template. | ||
addFilter( INSERTING_HOOK_NAME, INSERTING_HOOK_NAMESPACE, stubTrue ); | ||
|
||
// Set post title. | ||
if ( title ) { | ||
editorDispatcher.editPost( { title } ); | ||
} | ||
|
||
// Replace blocks. | ||
const postContentBlock = ownProps.postContentBlock; | ||
dispatch( 'core/block-editor' ).replaceInnerBlocks( | ||
postContentBlock ? postContentBlock.clientId : '', | ||
blocks, | ||
false | ||
); | ||
|
||
// Remove filter. | ||
removeFilter( INSERTING_HOOK_NAME, INSERTING_HOOK_NAMESPACE ); | ||
}, | ||
hideWelcomeGuide: () => { | ||
if ( ownProps.isWelcomeGuideActive ) { | ||
// Gutenberg 7.2.0 or higher. | ||
dispatch( 'core/edit-post' ).toggleFeature( 'welcomeGuide' ); | ||
} else if ( ownProps.areTipsEnabled ) { | ||
// Gutenberg 7.1.0 or lower. | ||
dispatch( 'core/nux' ).disableTips(); | ||
} | ||
}, | ||
}; | ||
} ) | ||
)( PageTemplateModal ); |
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,8 @@ | ||
module.exports = { | ||
rules: { | ||
'react/react-in-jsx-scope': 0, | ||
}, | ||
globals: { | ||
__i18n_text_domain__: true, | ||
}, | ||
}; |
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,8 @@ | ||
# Page Template Modal | ||
|
||
A modal for choosing a starting template for a new page, extracted from the editing toolkit | ||
|
||
## Development Workflow | ||
|
||
This package is developed as part of the Calypso monorepo. Run `yarn` | ||
in the root of the repository to get the required `devDependencies`. |
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,56 @@ | ||
{ | ||
"name": "@automattic/page-template-modal", | ||
"version": "1.0.0-alpha.0", | ||
"description": "Automattic Page Template Modal", | ||
"homepage": "https://github.com/Automattic/wp-calypso", | ||
"license": "GPL-2.0-or-later", | ||
"author": "Automattic Inc.", | ||
"main": "dist/cjs/index.js", | ||
"module": "dist/esm/index.js", | ||
"calypso:src": "src/index.js", | ||
"sideEffects": [ | ||
"*.css", | ||
"*.scss" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/Automattic/wp-calypso.git", | ||
"directory": "packages/page-template-modal" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/Automattic/wp-calypso/issues" | ||
}, | ||
"files": [ | ||
"dist", | ||
"src" | ||
], | ||
"dependencies": { | ||
roo2 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"@wordpress/api-fetch": "^3.3.0", | ||
"@wordpress/block-editor": "^5.2.1", | ||
"@wordpress/blocks": "^6.25.1", | ||
"@wordpress/components": "^12.0.1", | ||
"@wordpress/compose": "^3.23.1", | ||
"@wordpress/data": "^4.26.1", | ||
"@wordpress/editor": "^9.25", | ||
"@wordpress/element": "^2.19.01", | ||
"@wordpress/i18n": "^3.17.0", | ||
"@wordpress/nux": "^3.24.1", | ||
"@wordpress/url": "^2.21.0", | ||
"classnames": "^2.2.6", | ||
"lodash": "^4.17.19" | ||
}, | ||
"devDependencies": { | ||
roo2 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"@automattic/calypso-build": "^7.0.0" | ||
}, | ||
"peerDependencies": { | ||
"react": "^16.8" | ||
}, | ||
"scripts": { | ||
"clean": "npx rimraf dist", | ||
"build": "transpile && copy-assets", | ||
"prepack": "yarn run clean && yarn run build" | ||
} | ||
} |
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
File renamed without changes.
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.
goo? :) As in glue that is holding something together? That might not be clear to next dev who comes along. :)