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

3773 add has block functions #8340

Closed

Conversation

andreilupu
Copy link
Contributor

Description

I know that #3781 is there, but it's a stale PR for these handy functions, and I could not manage to fix that conflicting branch to continue the job from there.

I managed to address some changes requested in the comments there and some PHPUnit tests.
But, I'm not sure that if these functions should have a _type suffix since they are block types, not just blocks.( I would vote for gutenberg_content_has_block_type ).

Intentionally, I've switched the parameters order because it is more natural to have the required parameters first( the block name) and the optional ones after.

I stick to the idea that these functions should be fast, and if in later versions there will be a need for strict matching we could build functions like wp_block_match where we could also match block attributes.

With all the props to @ideadude for inspiration and idea.

How has this been tested?

It's a PHP feature, so I tested it via PHPUnit.

Screenshots

Types of changes

New feature (a non-breaking change which adds functionality)

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.

andreilupu and others added 30 commits August 1, 2018 02:38
…ality on server side.

Also, added some phpunit tests for these functions.

For WordPress#3773
* Fix regression with button active style.

* Move from 1px to using $border-width

This is sort of some cleanup work across the files.

* Try new input focus style.

Fixes WordPress#7053.
…action (WordPress#8357)

* Data Module: Adding The queried data handling into the entities abstraction

Co-authored-by: aduth <andrew.duthie@automattic.com>

* Fix a single entity fetch

* Data: Vary received entities action by query presence

* Data: Normalize queried pagination values as numeric

* Data: Support deep value serialization of query key
Translate Gutenberg demo content

Fixes WordPress#8547.
)

* API: Replace all withAPIData usage and deprecate the HoC

* Replace withAPIData usage in docs

* Fix unit tests
* Inserter: Try making the inline tokens less important

* Move the inline elements after the most used blocks

* Fix inline tokens test
* Add a note about handling blocks with `save`

Fixes WordPress#6356. Adds documentation about how to handle blocks with `save` that don't support an `id` prop noted in WordPress#6356.

* Docs: Add note about handling attributes in custom save components
…p` (WordPress#8596)

## Description

This PR updates `npm-package-json-lint` to the latest version and adds newly introduced rules. Props to @tclindner for making it possible:

> Hey! I just released v3.3.0 of npm-package-json-lint with a new description-format rule. It has two options:
> 
> requireCapitalFirstLetter - Throws an error if the first character in the description isn't capitalized.
> requireEndingPeriod - Throws an error if the description doesn't end with a period.
> Hopefully this works well for your team!

With this change, we can integrate new linting rule which will ensure that `description` inside `package.json` file will have proper formatting.

I took advantage of the fact that we are changing deps and bumped also `jest` which had also minor release.

I also downgraded `read-pkg-up` to avoid having it installed locally in the package. Instead, we can use the older version which is used with other packages. It doesn't break anything and keeps our setup simpler.

## How has this been tested?
`npm test` should cover all tools.
* Add a failing test for removing an empty first line.

* DOM: Restore horizontal edge traversal implementation

Co-Authored-By: iseulde
* Fix iframe JavaScript indendation

* Fix unrecognised `forwardedRef` prop error

Have `withGlobalEvents` omit the `forwardedRef` prop. This prevents the
prop being added to HTML in some cases, e.g. when used in
`FocusableIframe`.
…ress#8096)

* Packages: Add package `redux-routine`

* Packages: Throw rejected promise as error to generator

* Data: Add support for controls via redux-routine

* Core Data: Partially reimplement resolvers as controls

* Data: Port controls as data plugin

* Data: Revert deprecation of async generator

* Docs: Add note about plugin opt-in for controls

* ReduxRoutine: Improve isGenerator accuracy

* Fix redux-routine unit tests
…tribute (WordPress#8593)

* Add wp-image-ID class to gallery to make images reponsive

* edit tests to include class name
@aduth
Copy link
Member

aduth commented Aug 15, 2018

I tend to slightly disagree with unifying these functions because we lose consistency with the ol' core functions like has_shortcode.

This assumes there is consistency 😄 See also has_excerpt.

@aduth
Copy link
Member

aduth commented Aug 15, 2018

So pluralization is good to raise. The function here is has_block (single, presence of one of a given type by argument), while the function in #8631 is has_blocks (plural, presence of any, no arguments). To me, this seems like a sensible separation.

Edit: In retrospect, I realize I'm effectively restating what @obenland already mentioned. tl;dr 👍

@aduth
Copy link
Member

aduth commented Aug 15, 2018

The tests look well written to me 👍

Mahmoud Saeed and others added 3 commits August 15, 2018 23:58
* Edit Post: Reset active sidebar tab on initial load

* Edit Post: Set default active general sidebar in reducer

* Testing: Add E2E test case for sidebar dismissed preference
This deprecates `gutenberg_post_has_blocks()`.

See WordPress#4418, WordPress#8352.
@pento
Copy link
Member

pento commented Aug 16, 2018

Yah, let's merge the functions into a single has_block() function that takes a content string or a post/post ID, same as #8631.

@andreilupu: Would you mind rebasing and making use of has_blocks(), too, now that #8631 has been merged?

johngodley and others added 19 commits August 16, 2018 06:39
* Crash block: fix min height

Needs to be twice as tall otherwise it will overlap other blocks

* Crash block: allow inserter to appear over block
* Fix input and focus style for permalink slug

* Fix regression with horizontal scrollbar on mobile.

* Use serious flexing to scale the permalink editor.

* chore: Fix typo

* chore: Wording tweak

* Clarify comments.

* Address feedback.

* chore: Fix failing CSS Lint test
* Release font-size for code.

This addresses feedback in this comment https://github.com/WordPress/gutenberg/pull/710/files/3096d0bebe5d64142a84511b954d89ea6599e4f3#r208286450

Previously, the font size for any element in the `code` tag was fixed to 14px. Now it's released, free, and can be any size the parent container suggests to it.

Note that the `inherit` is necessary here to override code from upstream.

* Add comment to note the reason for inherit.
* Let the menu grow

This PR lets the menu grow to accommodate long text. Already now in Spanish, the "Code Editor" wraps having to fit both the spanish label and keyboard shortcut. As we add more keyboard shortcuts as well as hints, we need to let the menu grow to accommodate that, up to the mobile breakpoint in width.

This PR accomplishes that using auto widths, nowrap whitespace, and a little Nacin' Spacin' thrown in for code cleanup while I was there.

* Add case for mobile

* Try and clarify comment.
The plugin code relies on the RegistryProvider to be able to add
functionality to the registry. `withSelect` uses the RegistryConsumer,
but code outside of `@wordpress/data` can't access this modified
registry at all (even though it can create it!).
This solves the incongruence by simply exporting RegistryConsumer as
well.
* feat: Hide keyboard shortcuts on mobile screens

Fix WordPress#9050.

* docs: Clarify reasoning for wanting more space

* Add min-width to menu.

This fixes a regression I introduced in https://github.com/WordPress/gutenberg/pull/8756/files#diff-dcb8eefee4aaf82c9ddb042494547527R158.
…Press#8964)

* IE11: Fix The metaboxes area position (overlapping the content)

* Remove unnecessary CSS rule
* Fix the block styles in IE11

* Remove extra padding
* Fix the heading level buttons in IE11

* Fix mobile toolbars

* Fix heading buttons in IE11
* feat: Show sidebar in HTML edit mode for blocks (fix WordPress#4413)

* docs: Update inspector docs

* docs: Add docs to component

* docs: Improve image in inspector docs

* chore: Improve conditional and fix unintended isSelected prop

* docs: Change docs from master
* Shared Blocks: Add deprecation notices for deprecated shared blocks

* Framework: Remove deprecations slated for 3.6 removal
* Custom icons for Blocks

Uses custom svgs at a 24px base, 36px upscale for the inserter.
WordPress should signal that block icons ought to be custom for the
sake of clarity for users.

* Update some more icons.

* Add icons for several core blocks.

* Use service icons for embeds.

* Adjust embed icons.

* Expand width of inserter, use lighter design.

* Use ligher line arrow for panel collapse / expand.

* Adjust inserter design giving more paddings.

* Update more block icons and use color API for embeds.

* Adjust svg sizes for non-dashicon icons.

* Adjust block icon stack.

* Use different icons for embed fallback.

* Add more embed logos (WordPress, Tumblr).

* Add remaining icons for code, shortcode, inline image.

* Simplify image SVG and add new Heading icon.

* Polish inline image & block chip

This changes the icon for inline images to be bigger, and consistent with the image block.

It also polishes the block chip to ensure it has the same size in the inspector and in the toolbar, and have the right size.

* Cleanup SVG declarations.

* Fix appender icons

* Normalize SVGs and fix slash command

* Normalize focus style in library.

* Fix test issues.

* Clean "Classic" icon and linter issues.

* Polish focus, hover styles.

* Tweak how scrolling area works, and add grid units.

* It's padding, not margin. Sigh.

* Fix switcher

* Fix style variations.

* Fix unit tests

* Refactoring block icons rendering

* Fix style lint

* Remove debug code :) Sorry

* Fix icon styles

* Fix block icons e2e test

* Make sure the e2e icons test validates the colors properly
Initially used when generating excerpts to avoid infinite loops when dynamic blocks generate excerpts, and to add parity with `strip_shortcodes()`.

Fixes WordPress#5572, WordPress#7268.
…ality on server side.

Also, added some phpunit tests for these functions.

For WordPress#3773
@andreilupu
Copy link
Contributor Author

My "rebase" went horribly wrong and I can't manage to clean it properly.

In lack of time I recreated the PR here #9058; I hope it's ok

@andreilupu andreilupu closed this Aug 16, 2018
@pento
Copy link
Member

pento commented Aug 17, 2018

Thanks @andreilupu. Just for reference, it's okay if the you accidentally include a bunch of commits while rebasing, we squash PRs when they're merged, so it doesn't have an effect on what's actually committed.

To do a clean rebase of a PR, you can run this command: git pull --rebase origin master

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.