diff --git a/includes/class-iceberg-settings.php b/includes/class-iceberg-settings.php index fb29c17..ab8b475 100644 --- a/includes/class-iceberg-settings.php +++ b/includes/class-iceberg-settings.php @@ -80,6 +80,7 @@ public static function register_settings() { }, ) ); + } /** diff --git a/src/components/editor/editor.js b/src/components/editor/editor.js index f8f1443..78b0fa2 100644 --- a/src/components/editor/editor.js +++ b/src/components/editor/editor.js @@ -5,6 +5,7 @@ */ import BlockLimiter from '../block-limiter'; import ThemeSwitcher from '../theme-switcher'; +import PostSettings from '../post-settings'; import MoreMenu from '../more-menu'; import Shortcuts from '../shortcuts'; import RegisterShortcuts from '../shortcuts/shortcuts'; @@ -214,6 +215,7 @@ class IcebergEditor extends Component { /> { isActive && } + diff --git a/src/components/post-settings/index.js b/src/components/post-settings/index.js new file mode 100644 index 0000000..8dcc201 --- /dev/null +++ b/src/components/post-settings/index.js @@ -0,0 +1,308 @@ +/** + * External dependencies + */ +import { get } from 'lodash'; + +/** + * WordPress dependencies + */ +import { __ } from '@wordpress/i18n'; +import { withDispatch, withSelect } from '@wordpress/data'; +import { compose } from '@wordpress/compose'; +import { Fragment, Component, render } from '@wordpress/element'; +import { safeDecodeURIComponent, cleanForSlug } from '@wordpress/url'; +import { + PostFeaturedImageCheck, + PostFeaturedImage, + PostTaxonomies, + PostTaxonomiesCheck, + PostExcerpt as PostExcerptForm, + PostSchedule, + PostScheduleLabel, +} from '@wordpress/editor'; +import { + withSpokenMessages, + Dropdown, + Modal, + Button, + TextControl, + ExternalLink, +} from '@wordpress/components'; + +class PostSettings extends Component { + constructor( { postSlug, postTitle, postID } ) { + super( ...arguments ); + + this.addPostSettings = this.addPostSettings.bind( this ); + this.setSlug = this.setSlug.bind( this ); + this.switchView = this.switchView.bind( this ); + + this.state = { + isEnabled: false, + isSettingsOpen: false, + title: __( 'Post Settings', 'iceberg' ), + currentScreen: 'settings', + editedSlug: + safeDecodeURIComponent( postSlug ) || + cleanForSlug( postTitle ) || + postID, + }; + } + + componentDidMount() { + this.addPostSettings(); + } + + componentDidUpdate() { + this.addPostSettings(); + } + + onRequestClose() { + const { isSettingsOpen } = this.state; + + this.setState( { + isSettingsOpen: ! isSettingsOpen, + } ); + + if ( isSettingsOpen ) { + this.props.closePostSettings(); + } + } + + setSlug( event ) { + const { postSlug, onUpdateSlug } = this.props; + const { value } = event.target; + + const editedSlug = cleanForSlug( value ); + + if ( editedSlug === postSlug ) { + return; + } + + onUpdateSlug( editedSlug ); + } + + switchView( screen, title ) { + this.setState( { currentScreen: screen, title } ); + } + + addPostSettings() { + const { isActive } = this.props; + + const MoreMenuDropdown = () => { + return ( + + + + ) } + renderContent={ () => } + /> + + + + { + if ( + taxonomy.slug !== 'post_tag' + ) { + return false; + } + return content; + } } + /> + + + + + { + if ( + taxonomy.slug !== 'category' + ) { + return false; + } + return content; + } } + /> + + + + ) } + + ) } + + ); + } +} + +export default compose( [ + withSelect( ( select ) => { + const { + getCurrentPost, + getCurrentPostType, + getEditedPostAttribute, + getPermalinkParts, + } = select( 'core/editor' ); + + const { getPostType } = select( 'core' ); + const { id, link } = getCurrentPost(); + + return { + postType: getPostType( getCurrentPostType() ), + postSlug: getEditedPostAttribute( 'slug' ), + postTitle: getEditedPostAttribute( 'title' ), + postExcerpt: getEditedPostAttribute( 'excerpt' ), + permalinkParts: getPermalinkParts(), + postLink: link, + postID: id, + }; + } ), + withDispatch( ( dispatch ) => { + const { editPost } = dispatch( 'core/editor' ); + + return { + closePostSettings() { + // dispatch( 'core/editor' ).savePost(); + }, + onUpdateSlug( slug ) { + editPost( { slug } ); + }, + }; + } ), + withSpokenMessages, +] )( PostSettings ); diff --git a/src/components/post-settings/media-uploader.js b/src/components/post-settings/media-uploader.js new file mode 100644 index 0000000..6916fc1 --- /dev/null +++ b/src/components/post-settings/media-uploader.js @@ -0,0 +1,145 @@ +/** + * External dependencies + */ +import { get } from 'lodash'; + +/** + * WordPress dependencies + */ +import { __ } from '@wordpress/i18n'; +import { compose } from '@wordpress/compose'; +import { withDispatch } from '@wordpress/data'; +import { Fragment, Component } from '@wordpress/element'; +import { MediaUpload, MediaUploadCheck } from '@wordpress/block-editor'; +import { + withSpokenMessages, + Button, + DropZone, + ResponsiveWrapper, +} from '@wordpress/components'; + +class MediaUploader extends Component { + render() { + const { screen, onUpdateImage, onDropImage, seoMetaData } = this.props; + + const getImageID = get( seoMetaData, [ screen, 'image' ], '' ); + + const getImageSrc = get( seoMetaData, [ screen, 'image_src' ], '' ); + + const getImageSize = get( seoMetaData, [ screen, 'image_size' ], '' ); + + return ( + +
+ + { + onUpdateImage( screen, 'image', image.id ); + onUpdateImage( screen, 'image_src', image.url ); + onUpdateImage( screen, 'image_size', { + width: image.width, + height: image.height, + } ); + } } + unstableFeaturedImageFlow + allowedTypes={ [ 'image' ] } + render={ ( { open } ) => ( +
+ + +
+ ) } + value={ getImageID } + /> +
+ { getImageID && ( + +
+
+ ); + } +} + +export default compose( [ + withDispatch( + ( dispatch, { noticeOperations, onUpdateImage }, { select } ) => { + return { + onDropImage( filesList ) { + select( 'core/block-editor' ) + .getSettings() + .mediaUpload( { + allowedTypes: [ 'image' ], + filesList, + onFileChange( [ image ] ) { + onUpdateImage( screen, 'image', image.id ); + onUpdateImage( screen, 'image_src', image.url ); + onUpdateImage( screen, 'image_size', { + width: image.width, + height: image.height, + } ); + }, + onError( message ) { + noticeOperations.removeAllNotices(); + noticeOperations.createErrorNotice( message ); + }, + } ); + }, + }; + } + ), + withSpokenMessages, +] )( MediaUploader ); diff --git a/src/components/post-settings/style.scss b/src/components/post-settings/style.scss new file mode 100644 index 0000000..feb4976 --- /dev/null +++ b/src/components/post-settings/style.scss @@ -0,0 +1,218 @@ +#components-iceberg-post-settings { + .components-button.components-iceberg-post-settings__trigger { + color: var(--iceberg--color--accent); + } +} + + +.components-iceberg-post-settings__content { + width: 380px; + left: auto; + bottom: auto; + top: 5px; + right: 5px; + transform: none; + min-height: calc(100vh - 10px); + + .components-modal__content { + > div:not(.components-modal__header) { + margin-bottom: 25px; + } + } + + .components-base-control__label { + display: block; + width: 100%; + } + + .post-settings__featured-image { + position: relative; + + .components-button { + &.is-secondary { + display: none; + } + &.is-destructive { + position: absolute; + margin: 0; + top: 10px; + right: 10px; + text-indent: -999px; + overflow: hidden; + min-height: 30px !important; + height: 30px !important; + width: 30px; + color: #fff; + fill: currentColor; + background-image: url('data:image/svg+xml,'); + background-repeat: no-repeat; + background-color: rgba(0, 0, 0, 0.6); + background-position: center center; + &:hover { + background-color: #f05230; + } + + } + } + + .editor-post-featured-image__preview { + padding: 0 !important; + border-radius: 0; + } + } + + .components-iceberg-post-settings__metadata-menu { + border-radius: 4px; + border: 1px solid var(--iceberg--color--accent--light); + + .components-button { + text-align: left; + flex-direction: row-reverse; + height: auto; + padding: 9px 10px 10px 12px; + border-radius: 0; + + &:not(:last-of-type) { + border-bottom: 1px solid var(--iceberg--color--accent--light); + } + + .components-menu-item__info-wrapper { + width: 100%; + } + } + } + + .components-base-control__label { + text-transform: capitalize; + } + + .components-base-control__help { + margin-top: 0; + strong { + span { + color: rgb(159, 187, 88); + } + .to-red { + color: rgb(226, 84, 64); + } + } + } +} + +.components-iceberg-seo-preview { + font-family: Arial, sans-serif; + background: #fff; + border: 1px solid #e5eff5; + padding: 10px 12px; + + .iceberg-seo-preview-title { + color: #1e0fbe; + font-size: 18px; + line-height: 1.3; + text-overflow: ellipses; + word-wrap: break-word; + -webkit-text-overflow: ellipsis; + } + + .iceberg-seo-preview-link { + margin: 1px 0 2px; + color: #006621; + font-size: 13px; + line-height: 1.3; + word-wrap: break-word; + } + + .iceberg-seo-preview-desc { + color: #545454; + font-size: 13px; + line-height: 1.58; + word-wrap: break-word; + } +} + +.components-iceberg-twitter-preview, +.components-iceberg-facebook-preview { + .iceberg-seo-preview-image { + div { + width: 100%; + height: 160px; + background-size: cover; + background-position: 50%; + } + } +} + +.components-iceberg-twitter-preview { + overflow: hidden; + border: 1px solid #e1e8ed; + color: #292f33; + font-family: Helvetica Neue, Helvetica, Arial, sans-serif; + font-size: 14px; + line-height: 1.3; + background: #fff; + border-radius: 0.42857em; + -webkit-font-smoothing: antialiased; + + .iceberg-seo-preview-content { + background: #fff; + padding: 12px 14px; + } + .iceberg-seo-preview-title { + max-height: 1.3em; + overflow: hidden; + margin: 0 0 0.15em; + font-weight: 700; + text-overflow: ellipsis; + white-space: nowrap; + } + .iceberg-seo-preview-link { + max-height: 1.3em; + overflow: hidden; + color: #8899a6; + text-transform: lowercase; + text-overflow: ellipsis; + white-space: nowrap; + } +} + +.components-iceberg-facebook-preview { + background: #fff; + box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.1), inset 0 -1px 0 0 rgba(0, 0, 0, 0.06), 0 1px 4px rgba(0, 0, 0, 0.1); + + .iceberg-seo-preview-content { + padding: 10px 12px; + } + + .iceberg-seo-preview-title { + color: #1d2129; + max-height: 110px; + overflow: hidden; + margin-bottom: 5px; + font-family: Georgia, serif; + font-size: 18px; + line-height: 22px; + font-weight: 500; + word-wrap: break-word; + } + + .iceberg-seo-preview-desc { + color: #4b4f56; + max-height: 80px; + overflow: hidden; + font-size: 12px; + line-height: 16px; + letter-spacing: -0.1px; + } + + .iceberg-seo-preview-link { + overflow: hidden; + padding-top: 18px; + color: #90949c; + font-size: 11px; + line-height: 11px; + letter-spacing: -0.1px; + text-transform: uppercase; + text-overflow: ellipsis; + white-space: nowrap; + } +} diff --git a/src/style.scss b/src/style.scss index 1c6546c..8bbec54 100644 --- a/src/style.scss +++ b/src/style.scss @@ -18,6 +18,7 @@ @import "./components/settings/style.scss"; @import "./components/block-indicator/style.scss"; @import "./components/contextual-toolbar/style.scss"; + @import "./components/post-settings/style.scss"; //Editor styling @import "./styles/ui/hidden.scss"; diff --git a/src/styles/ui/hidden.scss b/src/styles/ui/hidden.scss index 0377006..86d40df 100644 --- a/src/styles/ui/hidden.scss +++ b/src/styles/ui/hidden.scss @@ -61,7 +61,7 @@ .edit-post-header__settings { > div { - &:nth-last-child(2) { + &:nth-last-child(3) { display: none !important; } }