Skip to content
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

Require double click (or just two clicks) for editing. #2863

Merged
merged 52 commits into from
Aug 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
2eea533
Add isEditing state for displaying the edit view.
miina Jul 22, 2019
fd0c74d
Adjust classnames.
miina Jul 22, 2019
ef06b2a
Remove text_block_padding constant.
miina Jul 22, 2019
23f56e4
Fix style.
miina Jul 22, 2019
0baa280
Disallow dragging in edit mode.
miina Jul 23, 2019
a3600d9
Add comment.
miina Jul 23, 2019
5488bb1
Add placeholder logic.
miina Jul 23, 2019
cebff8b
Fix amp-fit-text.
miina Jul 23, 2019
d9a8748
Fix jscs.
miina Jul 23, 2019
a782d35
Reduce duplication.
miina Jul 23, 2019
cb88011
Fix styling.
miina Jul 23, 2019
ebc5b71
Fix classname.
miina Jul 23, 2019
127a5ff
Fix resizing with amp-fit-text.
miina Jul 23, 2019
a6e2788
Also fix resizing for non-amp-fit-text.
miina Jul 23, 2019
9d9b8f9
Prevent text selection after doubleclikc.
miina Jul 23, 2019
4269bf5
Fix jscs.
miina Jul 23, 2019
38b2b17
Merge remote-tracking branch 'origin/develop' into add/2783-double_cl…
miina Jul 25, 2019
fe8782e
Enter edit mode with one click only.
miina Jul 25, 2019
764ac14
Add overay logic.
miina Jul 25, 2019
ec5a330
Fix CSS.
miina Jul 25, 2019
6d79c81
Merge develop & resolve conflicts.
miina Aug 1, 2019
bd533cd
Remove non-working key inreactions.
miina Aug 1, 2019
bfdb00b
Revert some changes.
miina Aug 1, 2019
95f4112
Add some tests.
miina Aug 1, 2019
49609a9
Add missing file.
miina Aug 1, 2019
22e795e
Merge branch 'develop' into add/2783-double_click_edit
swissspidy Aug 6, 2019
482873b
Add getBlocksOnPage helper util
swissspidy Aug 6, 2019
b629057
Improve dragging tests a bit (still skipped)
swissspidy Aug 6, 2019
7c46483
Merge develop & resolve conflicts.
miina Aug 7, 2019
f89d5fe
Merge remote-tracking branch 'origin/develop' into add/2783-double_cl…
miina Aug 7, 2019
db4fc34
Fix merging issues.
miina Aug 7, 2019
8808caa
Add key events.
miina Aug 7, 2019
509c07e
Use event instead of e for consistency.
miina Aug 7, 2019
3a1bf6d
Merge develop & resolve conflicts.
miina Aug 7, 2019
e73352b
Use rawHTML for displaying non editable text.
miina Aug 8, 2019
c28e9c2
Merge develop & resolve conflicts.
miina Aug 8, 2019
eeaa2ea
Merge remote-tracking branch 'origin/develop' into add/2783-double_cl…
miina Aug 13, 2019
86a48d8
Resolve conflicts.
miina Aug 13, 2019
d719023
Restore srcBlockName usage.
miina Aug 13, 2019
ffb8d8c
Fix CTA style.
miina Aug 13, 2019
4764190
Separate draggable text component.
miina Aug 13, 2019
80e2362
Use DraggableText in Text block, too.
miina Aug 13, 2019
876522f
Add missing file.
miina Aug 13, 2019
0836688
Fix linting issues.
miina Aug 13, 2019
840bdc3
Update tests.
miina Aug 13, 2019
76dc27d
Add additional selector wait for ensuring it being available.
miina Aug 13, 2019
f4fe1a0
Fix editor test.
miina Aug 13, 2019
cb3c68a
Move setting input selection to the end to helpers.
miina Aug 13, 2019
7bc681e
Ensure selecting the first page before removing the block.
miina Aug 14, 2019
483c72d
Another try to fix tests.
miina Aug 14, 2019
78d6275
Merge branch 'develop' into add/2783-double_click_edit
swissspidy Aug 16, 2019
eb13a6b
Tiny prop-types fix
swissspidy Aug 16, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion assets/src/stories-editor/blocks/amp-story-cta/edit.css
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ div[data-type="amp/amp-story-cta"] .amp-overlay {
--cta-margin: 3px;
height: calc(100% + calc(var(--cta-margin) * 2));
width: 100%;
bottom: calc(var(--cta-margin) * -1);
bottom: var(--cta-margin);
}

.block-editor-block-list__layout .block-editor-block-list__block[data-type="amp/amp-story-cta"] .block-editor-block-list__block-edit::before {
Expand Down
131 changes: 45 additions & 86 deletions assets/src/stories-editor/blocks/amp-story-cta/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import PropTypes from 'prop-types';
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { Component, RawHTML } from '@wordpress/element';
import { Component } from '@wordpress/element';
import {
Dashicon,
IconButton,
Expand All @@ -23,9 +23,9 @@ import {
*/
import './edit.css';
import { select } from '@wordpress/data';
import { getUniqueId } from '../../helpers';
import { getUniqueId, setInputSelectionToEnd } from '../../helpers';
import { getBackgroundColorWithOpacity } from '../../../common/helpers';
import { StoryBlockMover } from '../../components';
import { DraggableText } from '../../components';

class CallToActionEdit extends Component {
constructor( props ) {
Expand Down Expand Up @@ -78,16 +78,7 @@ class CallToActionEdit extends Component {
this.toggleOverlay( true );
}
if ( this.state.isEditing && ! prevState.isEditing ) {
const textInput = document.querySelector( '.is-selected .amp-block-story-cta__link' );
if ( textInput ) {
// Create selection, collapse it in the end of the content.
const range = document.createRange();
range.selectNodeContents( textInput );
range.collapse( false );
const selection = window.getSelection();
selection.removeAllRanges();
selection.addRange( range );
}
setInputSelectionToEnd( '.is-selected .amp-block-story-cta__link' );
}
}

Expand Down Expand Up @@ -132,81 +123,49 @@ class CallToActionEdit extends Component {
};
return (
<>
<StoryBlockMover
clientId={ clientId }
blockName={ name }
blockElementId={ `amp-story-cta-button-${ clientId }` }
isDraggable={ ! isEditing }
isMovable={ true }
>
<div className="amp-story-cta-button" id={ `amp-story-cta-button-${ clientId }` } style={ { top: `${ btnPositionTop }%`, left: `${ btnPositionLeft }%` } } >
<div className={ className } ref={ this.bindRef } style={ { backgroundColor: appliedBackgroundColor } }>
{ isEditing && (
<RichText
placeholder={ placeholder }
value={ text }
onChange={ ( value ) => setAttributes( { text: value } ) }
className={ textWrapperClass }
style={ textStyle }
/>
) }
{ /* eslint-disable-next-line jsx-a11y/click-events-have-key-events */ }
{ ! isEditing && <div
role="textbox"
tabIndex="-1"
className="is-not-editing editor-rich-text block-editor-rich-text"
onClick={ () => {
if ( isSelected ) {
this.toggleIsEditing( true );
}
} }
onMouseDown={ ( event ) => {
// Prevent text selection on double click.
if ( 1 < event.detail ) {
event.preventDefault();
}
} }
>
{ /* eslint-disable-next-line jsx-a11y/click-events-have-key-events */ }
{ hasOverlay && ( <div
role="textbox"
tabIndex="-1"
className="amp-overlay"
onClick={ ( e ) => {
this.toggleOverlay( false );
e.stopPropagation();
} }
></div>
) }
<div
role="textbox"
className={ textWrapperClass }
style={ textStyle }>
{ text && text.length ?
<RawHTML>{ text }</RawHTML> : (
<span className="amp-text-placeholder">
{ placeholder }
</span>
) }
</div>
</div>
}
</div>
{ isSelected && (
<form
className="amp-block-story-cta__inline-link"
onSubmit={ ( event ) => event.preventDefault() }>
<Dashicon icon="admin-links" />
<URLInput
value={ url }
onChange={ ( value ) => setAttributes( { url: value } ) }
autoFocus={ false /* eslint-disable-line jsx-a11y/no-autofocus */ }
/>
<IconButton icon="editor-break" label={ __( 'Apply', 'amp' ) } type="submit" />
</form>
<div className="amp-story-cta-button" id={ `amp-story-cta-button-${ clientId }` } style={ { top: `${ btnPositionTop }%`, left: `${ btnPositionLeft }%` } } >
<div className={ className } ref={ this.bindRef } style={ { backgroundColor: appliedBackgroundColor } }>
{ isEditing && (
<RichText
placeholder={ placeholder }
value={ text }
onChange={ ( value ) => setAttributes( { text: value } ) }
className={ textWrapperClass }
style={ textStyle }
/>
) }
{ ! isEditing &&
<DraggableText
blockElementId={ `amp-story-cta-button-${ clientId }` }
clientId={ clientId }
name={ name }
isDraggable={ true }
isEditing={ isEditing }
isSelected={ isSelected }
hasOverlay={ hasOverlay }
toggleIsEditing={ this.toggleIsEditing }
toggleOverlay={ this.toggleOverlay }
text={ text }
textStyle={ textStyle }
textWrapperClass={ textWrapperClass }
placeholder={ placeholder }
/>
}
</div>
</StoryBlockMover>
{ isSelected && isEditing && (
<form
className="amp-block-story-cta__inline-link"
onSubmit={ ( event ) => event.preventDefault() }>
<Dashicon icon="admin-links" />
<URLInput
value={ url }
onChange={ ( value ) => setAttributes( { url: value } ) }
autoFocus={ false /* eslint-disable-line jsx-a11y/no-autofocus */ }
/>
<IconButton icon="editor-break" label={ __( 'Apply', 'amp' ) } type="submit" />
</form>
) }
</div>
</>
);
}
Expand Down
35 changes: 25 additions & 10 deletions assets/src/stories-editor/blocks/amp-story-text/edit.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,39 @@
width: 100%;
}

.is-not-editing .wp-block-amp-amp-story-text.block-editor-rich-text__editable.editor-rich-text__editable {
cursor: grab;
}

.wp-block-amp-story-text-wrapper.is-empty-draggable-text,
.wp-block-amp-story-text-wrapper:not(.with-line-height) {
height: 100%;
}

.wp-block-amp-story-text-wrapper .amp-overlay {
height: 100%;
width: 100%;
z-index: 1000;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
}

.wp-block-amp-story-text-wrapper.is-empty-draggable-text .amp-text-placeholder {
opacity: 0.62;
}

.wp-block[data-type="amp/amp-story-text"] .amp-story-resize-container .components-resizable-box__handle-right {
right: -10px;
right: -13px;
}

.wp-block[data-type="amp/amp-story-text"] .amp-story-resize-container .components-resizable-box__handle-right::before {
margin: 0;
}

.wp-block[data-type="amp/amp-story-text"] .amp-story-resize-container .components-resizable-box__handle-bottom {
bottom: -8px;
width: 50px;
left: calc(50% - 25px);
}
Expand Down Expand Up @@ -67,14 +90,6 @@ div[data-type="amp/amp-story-page"] .block-editor-inner-blocks .block-editor-blo

.editor-block-list__layout .wp-block[data-type="amp/amp-story-text"] .editor-block-list__block-edit::before {
position: absolute;
top: 2px;
left: 2px;
right: 2px;
bottom: 2px;
}

.wp-block[data-type="amp/amp-story-text"] div[draggable="true"] {
border: 5px solid transparent;
}

.wp-block[data-type="amp/amp-story-text"] .amp-story-editor__rotate-container,
Expand Down
Loading