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

volto-subblocks

v2.0.0

Published

A widget for Volto to edit a block with subblocks

Downloads

2,165

Readme

volto-subblocks

A widget for Volto to have a block with subblocks

To be used with mrs-developer, see Volto docs for further usage informations.

If you are using Volto < 16, then use v1.2.3.

Usage

This is meant to edit blocks with sub-blocks, where the sub-blocks are all of the same type.

SubblocksEdit

The edit component of the parent block must extend the class SubblocksEdit. If you want to enable drag&drop to reorder subblocks, you have to use the HOC 'withDNDContext'.

export default withDNDContext(Edit);

In the render() function of this component, you have to:

  • wrap all content with 'SubblocksWrapper' component:
<SubblocksWrapper node={this.node}>...</SubblocksWrapper>
  • iterate on this.state.subblocks to draw subblocks.
  • render each subblock passing this props:
    <EditBlock
      data={subblock}
      index={subindex}
      selected={this.isSubblockSelected(subindex)}
      {...this.subblockProps}
    />

Usage

  • You could insert the add button simply writing {this.renderAddBlockButton()}
  • this.state.subblocks: contains subblocks. Used to iterate on subblocks
  • this.state.subIndexSelected: contains the index of the current selected subblock
  • this.onChangeSubblocks(subblockIndex, subblock): function to call when a subblock value is changed.
    • subblockIndex: is the index of the subblock in subblocks array
    • subblock: is the subblock object with new value/values.
  • this.onMoveSubblock(dragIndex, hoverIndex): function to call when a subblock changes his position / order in subblock list.
    • dragIndex: initial index of the item
    • hoverIndex: destination index of the item.
  • this.onSubblockChangeFocus(index): called when the focus on subblocks changes.
    • index: is the index of the focused subblock.
  • this.deleteSubblock(index): function to call to delete subblock at index position.
  • this.isSubblockSelected(index): return true if subblock ad index position is selected.
  • this.renderAddBlockButton(title): renders the add block button.
    • title: if given, the title is displayed on button. Default the title is 'Add block'.
  • this.subblockProps: it's an object that contains default props for edit each subblock.

Example

import React from 'react';
import {
  withDNDContext,
  SubblocksEdit,
  SubblocksWrapper,
} from 'volto-subblocks';
import EditBlock from './EditBlock';

class Edit extends SubblocksEdit {
  render() {
    if (__SERVER__) {
      return <div />;
    }

    return (
      <SubblocksWrapper node={this.node}>
        ...
        {this.state.subblocks.map((subblock, subindex) => (
          <EditBlock
            data={subblock}
            index={subindex}
            selected={this.isSubblockSelected(subindex)}
            {...this.subblockProps}
            openObjectBrowser={this.props.openObjectBrowser}
          />
        ))}
        {this.props.selected && this.renderAddBlockButton()}
        ...
      </SubblocksWrapper>
    );
  }
}

export default React.memo(withDNDContext(Edit));

SubblockEdit

The edit component of the subblock must extend the class SubblockEdit

If you want to enable drag&drop to reorder subblocks, you have to compose with injectDNDSubblocks.

export default compose(injectDNDSubblocks)(EditBlock);

In the render() function of this component, you have to:

  • wrap all content with 'Subblock' component. By default Subblock component is draggable. If you prefer not to make subblocks draggable, you could add the prop draggable={false}:
<Subblock subblock={this}>...</Subblock>

Example

import React from 'react';
import { compose } from 'redux';
import { injectDNDSubblocks, SubblockEdit, Subblock } from 'volto-subblocks';

class EditBlock extends SubblockEdit {
  render() {
    if (__SERVER__) {
      return <div />;
    }

    return <Subblock subblock={this}>...</Subblock>;
  }
}

export default React.memo(compose(injectDNDSubblocks)(EditBlock));

SubblocksWrapper

It's the wrapper to use in parent component. Properties:

  • node: the 'node' var that will contain ref for this node.
  • className: to add class or classes to the wrapper.

Example

<SubblocksWrapper node={this.node} className="additional_class">
  ....
</SubblocksWrapper>

Subblock

It's the wrapper for each subblock. Use it in subblock edit component. Properties:

  • subblock: the current class instance of subblock
  • className: to add class or classes to the wrapper.
  • draggable: default true. If you don't want to make your subblock sortable with drag&drop, you can pass false.

Example

<Subblock subblock={this} className="additional_class" draggable={false}>
  ....
</Subblock>

Authors

This product was developed by RedTurtle Technology team.

RedTurtle Technology Site