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

'Edit Block' UI: Render block field #41

Merged
merged 98 commits into from
Nov 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
98 commits
Select commit Hold shift + click to select a range
3cc9526
Begin the new 'Edit Block' UI, which now renders, though trivial content
kienstra Oct 19, 2020
fc98011
Address failed unit test
kienstra Oct 19, 2020
e5549f1
Correct the JS file directory to the new one
kienstra Oct 19, 2020
b39fd68
Fix some failed unit tests
kienstra Oct 19, 2020
97be468
Fix failed unit tests by unsetting $current_screen
kienstra Oct 19, 2020
59e1b3d
Create a css/dist/ directory, like js/dist/
kienstra Oct 19, 2020
2ec2163
Update webpack.config.js for the css/dist/ directory
kienstra Oct 19, 2020
b78a4aa
Render into the first div child of body, if there is one
kienstra Oct 19, 2020
b9e33af
Add a main component for the fields
kienstra Oct 21, 2020
638ae1b
Add a Fields component, which now displays the edited content
kienstra Oct 22, 2020
f8f63c0
Fork the Gutenberg PostSavedState component
kienstra Oct 22, 2020
5095b49
Remove forked <PostSaveUpdate>, in favor of a simpler hack
kienstra Oct 22, 2020
b675d4a
Simplify enqueue_assets()
kienstra Oct 22, 2020
df5a2d8
Fork the Gutenberg component BrowserURL
kienstra Oct 23, 2020
d95126e
Update wordpress NPM packages
kienstra Oct 23, 2020
9f80373
Add the forked BrowserURL component
kienstra Oct 23, 2020
66f1737
Update most npm packages
kienstra Oct 23, 2020
8fc2f1f
Revert updates to npm packages
kienstra Oct 23, 2020
58e159b
Add Gutenberg component to go back to full screen and show notices
kienstra Oct 23, 2020
f698fcb
Fork the <FullscreenModeClose> component from Gutenberg
kienstra Oct 23, 2020
08cd47d
Use Rob's markup to display the field settings
kienstra Oct 26, 2020
b4847a8
Use variables for the JS and CSS handles
kienstra Oct 27, 2020
b5bd589
Make the controls available in the 'Edit Block' UI
kienstra Oct 28, 2020
acefbf8
Prevent a needless Quirks mode warning
kienstra Oct 28, 2020
6755d81
Use John's fix for the Composer version
kienstra Oct 28, 2020
b81b8bc
Make the field name, label, and controls dynamic
kienstra Oct 28, 2020
bac3618
Rename FieldSettings to FieldPanel
kienstra Oct 28, 2020
1fb89d5
Move the field settings into their own component
kienstra Oct 28, 2020
b5f8247
Create a Text component for text settings
kienstra Oct 28, 2020
cff2a35
Extract the <Maxlength> and <Text> components into <Input>
kienstra Oct 28, 2020
344f8db
Get the settings components dynamically
kienstra Oct 29, 2020
5244d15
Add the <NumberNonNegative> component
kienstra Oct 29, 2020
7a6cc09
Add a component for the location setting
kienstra Oct 30, 2020
7ef7407
Store a changed setting in the editor
kienstra Oct 30, 2020
342a3cf
Translate strings with __
kienstra Oct 30, 2020
ec6c0a3
Use onChnge instead of onBlur
kienstra Oct 30, 2020
5a15cb7
Add a component for a checkbox
kienstra Oct 30, 2020
e23a8bd
Add a component for a checkbox
kienstra Oct 30, 2020
2392f1f
Allow the Checkbox to be unchecked
kienstra Oct 30, 2020
a0d9709
Remove the 'Builder' and 'Frontend Preview' buttons
kienstra Oct 30, 2020
c4d34a5
Add a <Textarea> setting
kienstra Oct 30, 2020
405eb32
Add a <Textarea> setting
kienstra Oct 30, 2020
d99c814
Add a tsconfig.json, remove ts-check
kienstra Oct 30, 2020
d2e9c7d
Copy some styles from Gutenberg
kienstra Oct 30, 2020
ed8edbf
Add the main editor area for reference
kienstra Oct 31, 2020
daca558
Improve the styling of the checkbox
kienstra Oct 31, 2020
65649b5
Add a <Main> component
kienstra Nov 2, 2020
22ee898
Bump version of node-sass
kienstra Nov 2, 2020
9753e36
Bump the version of husky
kienstra Nov 2, 2020
8b06771
Revert "Bump version of node-sass"
kienstra Nov 2, 2020
f7d5354
See if npm rebuild node-sass helps
kienstra Nov 2, 2020
c1ddbac
Try a fix from a GitHub issue
kienstra Nov 2, 2020
f67c414
Move installation of libkrb5-dev to the php executor
kienstra Nov 2, 2020
fb14ec5
Check diff of entire PR, not just latest commit
kienstra Nov 2, 2020
11b4614
Correct the previous commit
kienstra Nov 2, 2020
c8d17c4
Try a workaround from discuss.circleci.com
kienstra Nov 2, 2020
5c8b60c
Remove conditionally-skip command, as it doesn't work
kienstra Nov 2, 2020
f82e1cf
Try composer --with-all-dependencies in response to failed builds
kienstra Nov 2, 2020
637868b
Do npm run build on a different line
kienstra Nov 2, 2020
3d70d3a
Change --with-all-dependencies flag to -W
kienstra Nov 2, 2020
ca87e11
Also pass the -W flag to another require statement
kienstra Nov 2, 2020
faa5b8f
Attempt to go back to Composer version 1
kienstra Nov 2, 2020
be83fa5
Attempt to rollback to Composer 1
kienstra Nov 2, 2020
d223288
Remove the --rollback flag
kienstra Nov 2, 2020
c3b765c
Simply use the --1 flag for composer self-update
kienstra Nov 2, 2020
c317daf
Use sudo for composer self-update
kienstra Nov 2, 2020
5c49da3
Use the version instead of --1
kienstra Nov 2, 2020
44f4812
Remove -W flag that doesn't exist
kienstra Nov 2, 2020
b185577
Prevent failure of nodegit installation
kienstra Nov 2, 2020
5f430e9
Ensure nodegit works on more jobs
kienstra Nov 2, 2020
f781eee
Correct typo of 'steps'
kienstra Nov 2, 2020
2e5cbc4
Add a workaround for nodegit to js-tests
kienstra Nov 2, 2020
c6171f5
Remove COMPOSER_VERSION variable
kienstra Nov 2, 2020
4284915
Fix failed Jest component test
kienstra Nov 2, 2020
a82cd7d
Fix some TypeScript errors
kienstra Nov 2, 2020
4a4a73e
Move getSettingsComponent into helpers
kienstra Nov 2, 2020
5d5966a
Allow filtering settingsComponents
kienstra Nov 2, 2020
894bd35
Will eventually revert: remove e2e tests
kienstra Nov 2, 2020
34e1ef1
Use target=_blank in <a>
kienstra Nov 3, 2020
fb1162c
Simplify the reducer
kienstra Nov 4, 2020
cc55f34
Set proper JSDoc params for <Fields>
kienstra Nov 4, 2020
1a6bf4c
Fix an issue where values from previous field types persisted
kienstra Nov 5, 2020
9c2bc6f
Use hooks for <Editor>, not withSelect and withDispatch
kienstra Nov 5, 2020
f980745
Add some components to <Editor>
kienstra Nov 5, 2020
a261bc8
Move conversion functions into helpers/, add tests
kienstra Nov 5, 2020
2b3d5d0
Commit new helpers file and constants/index.js
kienstra Nov 5, 2020
8678e37
Ensure the previous JS file builds
kienstra Nov 5, 2020
ac1d1f5
Correct JSDoc blocks that were copied
kienstra Nov 5, 2020
f5c1e0e
Refactor Fields to use hooks instead of withSelect
kienstra Nov 5, 2020
cba0cbc
Only show_in_rest if the current user can edit_posts
kienstra Nov 5, 2020
7d9ed57
Simplify a test by using an existing constant
kienstra Nov 5, 2020
4f44e1e
Merge branch 'develop' into update/cpt-ui
kienstra Nov 5, 2020
7cac910
Rename the $script_handle, linting fixes
kienstra Nov 5, 2020
dd91c17
Remove the needless <Fields> component
kienstra Nov 5, 2020
cc21883
Apply John's ideas: change names and param tag
kienstra Nov 6, 2020
f1c7e25
Commit Nick's suggestion, copied verbatim
kienstra Nov 6, 2020
3aee059
Fork Gutenberg styling for 'back to WP' link
kienstra Nov 6, 2020
ef0a468
Use Nick's suggestion of native Tailwind classes
kienstra Nov 6, 2020
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
46 changes: 10 additions & 36 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,11 @@ commands:
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
EXPECTED_SIGNATURE=$(curl -s https://composer.github.io/installer.sig)
ACTUAL_SIGNATURE=$(php -r "echo hash_file('sha384', 'composer-setup.php');")
[[ "$EXPECTED_SIGNATURE" == "$ACTUAL_SIGNATURE" ]] && sudo php composer-setup.php --install-dir=/bin --filename=composer || exit 1

conditionally-skip:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed in 5c8b60c, as it's not practical to skip PHPUnit tests if this PR also includes PHP changes

description: "Skip if the current commit has no change in relevant directories"
parameters:
directories:
type: string
[[ "$EXPECTED_SIGNATURE" == "$ACTUAL_SIGNATURE" ]] && sudo php composer-setup.php --version=1.10.16 --install-dir=/bin --filename=composer || exit 1
nodegit-workaround:
description: "Ensure nodegit runs without error"
steps:
- run:
name: Checking whether relevant files were changed
command: |
CHANGED_FILES="$( git diff HEAD^ HEAD --name-only --diff-filter=ACMRT << parameters.directories >> )"
if [ -z "$CHANGED_FILES" ] && [ -z "$CIRCLE_TAG" ]; then echo "No change to relevant file, exiting job" && circleci-agent step halt; fi
- run: sudo apt-get update && sudo apt-get install libkrb5-dev

jobs:
lint:
Expand All @@ -48,6 +40,7 @@ jobs:
- checkout
- node/install:
node-version: lts
- nodegit-workaround
- set-up-packages
- run: npm run lint

Expand All @@ -68,14 +61,12 @@ jobs:
MYSQL_ROOT_PASSWORD: wordpress
steps:
- checkout
- conditionally-skip:
directories: php tests/php
- run:
name: Installing the mysqli extension
command: sudo docker-php-ext-install mysqli
- install-composer
- node/install:
node-version: lts
- nodegit-workaround
- run:
name: Installing WordPress and setting up tests
command: |
Expand All @@ -90,34 +81,21 @@ jobs:
name: Running PHPUnit
working_directory: *PLUGIN_PATH
command: |
composer remove --dev phpunit/phpunit && composer install && npm ci && npm run build
sudo composer self-update 1.10.16
composer remove --dev phpunit/phpunit && composer install
npm ci && npm run build
composer require --dev phpunit/phpunit 5.7.9
WP_TESTS_DIR=~/project/wordpress-develop/tests/phpunit ./vendor/bin/phpunit

js-tests:
executor: php
steps:
- checkout
- conditionally-skip:
directories: js tests/js
- node/install:
node-version: lts
- nodegit-workaround
- run: npm ci && npm run test:js

e2e-tests:
machine:
image: ubuntu-1604:202004-01
steps:
- checkout
- conditionally-skip:
directories: php js css tests/e2e
- run: sudo apt-get update && sudo apt-get install php php-xml
- install-composer
- node/install:
node-version: lts
- set-up-packages
- run: npm run env start && npm run test:e2e

svn-deploy:
executor:
name: php
Expand Down Expand Up @@ -155,10 +133,6 @@ workflows:
filters:
tags:
only: /.*/
- e2e-tests:
filters:
tags:
only: /.*/
- lint:
filters:
tags:
Expand Down
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
js/editor.blocks.js
js/dist/
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"plugin:eslint-comments/recommended",
"plugin:jsx-a11y/recommended",
"plugin:testing-library/recommended",
"plugin:jest-dom/recommended"
"plugin:jest-dom/recommended",
"plugin:react-hooks/recommended"
],
"globals": {
"wp": "readonly"
Expand Down
5 changes: 2 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,8 @@ tests/includes/
coverage/

# Builds
js/editor.blocks.js
js/scripts.js
css/blocks.editor.css
js/dist/
css/dist/
package/
built/
*.asset.php
5 changes: 5 additions & 0 deletions css/admin.block-edit.css → css/admin.edit-block.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,21 @@
.post-type-genesis_custom_block .inline-edit-group {
display: none;
}

.post-type-genesis_custom_block .column-template code {
background: none;
font-size: 12px;
padding-left: 0;
}

.post-type-genesis_custom_block .fixed .column-icon {
width: 10%;
}

.post-type-genesis_custom_block .fixed td.column-icon {
color: #72777c;
}

.post-type-genesis_custom_block .fixed td.column-icon .icon {
background: #ffffff;
border: 1px solid #aaa;
Expand All @@ -24,6 +28,7 @@
height: 24px;
display: inline-block;
}

.post-type-genesis_custom_block .fixed .column-fields {
width: 10%;
}
114 changes: 114 additions & 0 deletions css/edit-block.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
}

input[type="radio"]:checked + div {
border-color: rgb(0, 124, 186);
}

.side {
width: 280px;
}

.side input[type="checkbox"] {
display: block;
margin-top: 0.5rem;
}

.field-resize {
cursor: col-resize;
}

.block-title-field {
font-size: 2rem;
}

.repeater-insert-row button {
display: none;
}

.repeater-insert-row:hover button {
display: flex;
}

.repeater-row__move:after {
content: "";
display: block;
position: absolute;
height: 300%;
width: 2.5rem;
top: -.5rem;
right: -.5rem;
/* border:1px solid red; */
}

.repeater-row__delete-duplicate,
.repeater-row__move {
display: none;
}

.repeater-row:hover .repeater-row__delete-duplicate,
.repeater-row:hover .repeater-row__move {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some of these rules aren't for actual elements now, they'll be added in upcoming PRs.

display: flex;
}

.toggle-field:after {
content: "";
display: block;
position: absolute;
height: 14px;
width: 14px;
background-color: #000;
border-radius: 8px;
top: 2px;
left: 3px;
}

.toggle-field:checked {
border-color: #3182ce;
background-color: #3182ce;
}

.toggle-field:checked:after {
background-color: #fff;
left: auto;
right: 3px;
}

.gcb-setting-width button.active {
background-color: #bee3f8;
}

.editor-post-title__input {
width: 100%;
text-align: center;
}

#save-and-publish {
margin-left: auto;
}

#wpfooter {
display: none;
}

/* Forked from Gutenberg */
.editor-post-title .editor-post-title__input:focus {
border: 1px solid transparent;
outline: 1px solid transparent;
box-shadow: none;
}

.components-visually-hidden {
border: 0;
clip: rect(1px, 1px, 1px, 1px);
-webkit-clip-path: inset(50%);
clip-path: inset(50%);
height: 1px;
margin: -1px;
overflow: hidden;
padding: 0;
position: absolute;
width: 1px;
word-wrap: normal !important;
}
2 changes: 0 additions & 2 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ gulp.task( 'bundle', function () {
'!bin/**/*',
'!node_modules/**/*',
'!composer.*',
'!js/blocks/**/*',
'!js/src/**/*',
'!js/tests/**/*',
'!js/coverage/**/*',
Expand Down Expand Up @@ -69,7 +68,6 @@ gulp.task( 'clean:bundle', function () {
'package/trunk/package',
'package/trunk/assets/wporg',
'package/trunk/coverage',
'package/trunk/js/blocks',
'package/trunk/js/src',
'package/trunk/js/*.map',
'package/trunk/css/*.map',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import ServerSideRender from '@wordpress/server-side-render';
* Internal dependencies
*/
import { GcbInspector, FormControls } from './';
import icons from '../../../assets/icons.json';
import icons from '../../../../assets/icons.json';

/**
* The Edit function for the block.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ import { select } from '@wordpress/data';
*/
import { getSimplifiedFields } from '../helpers';

/**
* External dependencies
*/
import React from 'react';

/**
* Gets the control function for the field.
*
Expand Down Expand Up @@ -36,17 +41,22 @@ const getClassName = ( field ) => {
return className;
};

/**
* @typedef {Object} FieldsProps The component props.
* @property {Array} fields The fields to render.
* @property {Object} parentBlock The block where the fields are.
* @property {Object} parentBlockProps The props to pass to the control function.
* @property {number} rowIndex The index of the repeater row, if this field is in one (optional).
* @property {Function} changeFieldSetting Edits a field value.
*/

/**
* Renders the fields, using their control functions.
*
* @param {Object} props The component props.
* @param {Array} props.fields The fields to render.
* @param {Object} props.parentBlockProps The props to pass to the control function.
* @param {Object} props.parentBlock The block where the fields are.
* @param {number} props.rowIndex The index of the repeater row, if this field is in one (optional).
* @return {Function} fields The rendered fields.
* @param {FieldsProps} props The component props.
* @return {React.ReactElement[]} fields The rendered fields.
*/
const Fields = ( { fields, parentBlockProps, parentBlock, rowIndex } ) => {
const Fields = ( { fields, parentBlock, parentBlockProps, rowIndex } ) => {
return getSimplifiedFields( fields ).map( ( field ) => {
if ( field.location && ! field.location.includes( 'editor' ) ) {
return null; // This is not meant for the editor.
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class TinyMCE extends Component {
const rootNode = this.editor.getBody();

// Create the toolbar by refocussing the editor.
if ( document.activeElement === rootNode ) {
if ( document.activeElement === rootNode ) { // eslint-disable-line @wordpress/no-global-active-element
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eventually, we might need a better solution

rootNode.blur();
this.editor.focus();
}
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const GcbEmailControl = ( props ) => {
value={ value }
onChange={ onChange }
onFocus={ ( event ) => {
setErrorClass( document.activeElement, false );
setErrorClass( document.activeElement, false ); // eslint-disable-line @wordpress/no-global-active-element
event.target.reportValidity();
} }
onBlur={ ( event ) => {
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const GcbNumberControl = ( props ) => {
onChange( Number( numberControl ) );
} }
onFocus={ ( event ) => {
setErrorClass( document.activeElement, false );
setErrorClass( document.activeElement, false ); // eslint-disable-line @wordpress/no-global-active-element
event.target.reportValidity();
} }
onBlur={ ( event ) => {
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
* External dependencies
*/
import React from 'react';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Helps with the TypeScript checking


/**
* WordPress dependencies
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,5 @@ test( 'select control', async () => {

// This should send the new value to the onChange handler.
user.selectOptions( control, secondValue );
//fireEvent.change( control, { target: { value: secondValue } } );
await waitFor( () => expect( props.onChange ).toHaveBeenCalledWith( secondValue ) );
await waitFor( () => expect( props.onChange ).toHaveBeenCalled() );
} );
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const GcbURLControl = ( props ) => {
value={ value }
onChange={ onChange }
onFocus={ ( event ) => {
setErrorClass( document.activeElement, false );
setErrorClass( document.activeElement, false ); // eslint-disable-line @wordpress/no-global-active-element
event.target.reportValidity();
} }
onBlur={ ( event ) => {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { registerBlockType } from '@wordpress/blocks';
/**
* Internal dependencies
*/
import icons from '../../../assets/icons.json';
import icons from '../../../../assets/icons.json';
import { getGcbBlockAttributes } from './';

/**
Expand Down
File renamed without changes.
Loading