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

#4710 do not merge #5287

Closed
wants to merge 38 commits into from
Closed

Conversation

Lewiscowles1986
Copy link
Contributor

@Lewiscowles1986 Lewiscowles1986 commented Feb 27, 2018

gutenberg.zip

Description

Please don't merge this or close before Travis is done running. It's a test & feedback see #4710

How Has This Been Tested?

  • travis-ci
  • local composer run lint
  • local npm run lint
  • local npm run ci
  • local npm run package-plugin
  • Browser testing in WP 4.9.4
    • safari
    • ie 11
    • edge
    • firefox
    • chrome
    • process
      • create new post or page
      • add single shortcode (currently accepts non-shortcode noise surrounding if a shortcode is present)
      • save
      • page or post listing screen (depending on first-step)
      • edit page or post, and alter shortcode to multiple shortcodes (with [embed] shortcode)
      • defocus shortcode
      • change order of shortcodes
      • save post
      • back to listing
      • re-open
      • preview post
      • select (currently uses side-handle or re-positioning to re-gain focus. Not ideal)

Screenshots (jpeg or gifs if applicable):

image
image

Types of changes

Shortcode block to have previews

Checklist:

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

Not meant for merge

System Administrator and others added 30 commits January 25, 2018 04:49
This commit is towards rendering a front end preview for shortcode blocks. The shortcode block now implements a tabbed preview option, similar to HTML blocks. The user can edit their shortcodes, and previewing again will re-render the edited shortcode. Works for embed shortcodes too. Known issues - (1) playlist shortcode doesn't work (2) the iframe height/width in the preview tab needs to wrap content size. For example, the iframe is too big when previewing an audio player using audio shortcode (3) gallery shortcode preview stacks the images vertically instead of horizontally (4) video shortcode doesn't work for URLs supported by oembed
Previously, the post ID was fetched by processing the post's URL and parsing the post ID GET parameter. Now, a better approach is taken by reading the post ID value from the redux store.
In this revision, custom css and js files are injected as props to the iframe sandbox. Custom css and js is needed in certain cases, for example, [gallery] shortcode needs the parent theme style.css.
Shortcode content type (if it's a video or otherwise), and the shortcode's custom css and js (if any) are fetched and returned as parameters to the front end. In the case of [gallery] and [caption], for example, the theme's style.css is needed, else the shortcode preview will not render properly. [playlist] needs mediaelement JS to be able to render the playlist components.
1) Certain shortcodes, such as [gallery], [caption] and [playlist] need styles and JS inside of the sandbox iframe to be able to render content appropriately. The sandbox component didn't support injection of custom links for external stylesheets and scripts, so this revision attempts to fix that
2) [audio] shortcode fails to render since bounding client width is 0 (weird, I know). So, in this revision, I add a null check and set a minimum width if bounding client width or height is zero.
[playlist] shortcode was previously not rendering in the preview due to some missing scripts. This commit fixes this issue. Try using [playlist] in the shortcode block and enjoy the preview.
The jest tests failed since I was using a connected component in Shortcode, which caused the tests to act up. Followed the recommended fix and updated the snapshot to reflect the new UI for the shortcode block.
The shortcode preview result is cached using Transients, for quicker render times and avoiding processing overheads
Empty results are possible if the shortcode is given invalid attributes. In this case, we needn't unnecessarily store the empty string shortcode in transients, so I've added a check to take care of this scenario.
If shortcode output is empty, I've added a flow wherein we exit from the API immediately, and avoid some extra processing which won't apply to empty shortcode output data.
Added a couple of messages in cases when null values are sent as args to the API.
Refactored code to move Shortcode block code to a separate file. Also, preview code is rendered as a separate component called "ShortcodePreview", which capitalizes on the usage of withAPIData for making REST API requests to the shortcode preview API.
Concatenated html, js and css to a single prop
- Preview tab is disabled if text in shortcode block is empty
- Rearranged code a bit for better readability
@Lewiscowles1986
Copy link
Contributor Author

Just needed to see if the third task would pass. It doesn't on my own travis (and I'm unsure why)

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.

2 participants