npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@frontkom/g-media-attributes

v1.0.5

Published

A set of extensions for core media blocks in order to support Drupal's media attributes.

Downloads

7

Readme

Gutenberg JS Media Attributes

A set of extensions for core media blocks in order to support Drupal's media attributes.

How to use

Install the package from NPM.

$ npm install @frontkom/g-media-attributes

Add to the editor before the core blocks are loaded:

import '@frontkom/g-media-attributes';

Motivation

In order to fully support Drupal's file entity when handling images on Gutenberg editor, the tags on core media blocks need to have the data-entity-uuid and data-entity-type attributes.

The block resulting HTML must be something like this:

<figure class="wp-block-image">
  <img data-entity-uuid="f398bc3b-1c50-4394-bf80-3af0f72fef42" data-entity-type="file" src="..."
    alt="Picture" class="wp-image-1">
</figure>

The data-* attributes are provided by api-fetch's upload method.

The following core blocks needed to be updated:

  • core/image
  • core/video
  • core/media-text
  • core/cover
  • core/gallery

Solution

The solution we found was to wrap the Edit and Save components with Higher Order Components's (HOC) that handle the fetching and printing of these media attributes.

settings.edit = editWithMediaAttrs(settings.edit);
settings.save = saveWithMediaAttrs(settings.save);

When an image is selected, the Edit HOC captures that event and fecthes the additional data required from the API.

On save, the Save HOC updates the rendered tree with the necessary attributes for each media element.

Known issues

  • core/gallery

Currently the block validation for core/gallery throws an error to the console. However, this does not affect the loading of the block itself. It seems to be caused by the difference in number of attributes present on each of the gallery items (expected vs actual). More discovery is needed.

License

MIT