@documint/grapesjs-dynamic-components

1.0.3 • Public • Published

Grapesjs Dynamic Components

Switch component type based on where a block is dropped

HTML

<link href="https://unpkg.com/grapesjs/dist/css/grapes.min.css" rel="stylesheet">
<script src="https://unpkg.com/grapesjs"></script>
<script src="https://unpkg.com/grapesjs-dynamic-components"></script>

<div id="gjs"></div>

JS

const editor = grapesjs.init({
	container: '#gjs',
  height: '100%',
  fromElement: true,
  storageManager: false,
  plugins: ['grapesjs-dynamic-components'],
});

CSS

body, html {
  margin: 0;
  height: 100%;
}

Summary

  • Plugin name: grapesjs-dynamic-components
  • Components
    • dynamic

Options

Option Description Default
dynamicName Name of dynamic component dynamic
dynamicOpts Options for extending dynamic component {}

Download

  • CDN
    • https://unpkg.com/grapesjs-dynamic-components
  • NPM
    • npm i grapesjs-dynamic-components
  • GIT
    • git clone https://github.com/documint-me/grapesjs-dynamic-components.git

Defining Blocks

Define block with type dynamic and define which component to use for a given set of parent components

const bm = editor.Blocks;

bm.add('dynamic-content', {
  label: 'Dynamic Content',
  content: {
    type: 'dynamic',
    switch: [{
        parents: ['cont'], // List of parent component types 
        type: 'test' // Type to use given above parent components
      },
      {
        parents: ['cont2'],
        type: 'test2'
      }
    ]
  }
});

Usage

Directly in the browser

<link href="https://unpkg.com/grapesjs/dist/css/grapes.min.css" rel="stylesheet"/>
<script src="https://unpkg.com/grapesjs"></script>
<script src="path/to/grapesjs-dynamic-components.min.js"></script>

<div id="gjs"></div>

<script type="text/javascript">
  var editor = grapesjs.init({
      container: '#gjs',
      // ...
      plugins: ['grapesjs-dynamic-components'],
      pluginsOpts: {
        'grapesjs-dynamic-components': { /* options */ }
      }
  });
</script>

Modern javascript

import grapesjs from 'grapesjs';
import plugin from 'grapesjs-dynamic-components';
import 'grapesjs/dist/css/grapes.min.css';

const editor = grapesjs.init({
  container : '#gjs',
  // ...
  plugins: [plugin],
  pluginsOpts: {
    [plugin]: { /* options */ }
  }
  // or
  plugins: [
    editor => plugin(editor, { /* options */ }),
  ],
});

Development

Clone the repository

$ git clone https://github.com/documint-me/grapesjs-dynamic-components.git
$ cd grapesjs-dynamic-components

Install dependencies

$ npm i

Start the dev server

$ npm start

Build the source

$ npm run build

License

MIT

Readme

Keywords

Package Sidebar

Install

npm i @documint/grapesjs-dynamic-components

Weekly Downloads

0

Version

1.0.3

License

MIT

Unpacked Size

11.7 kB

Total Files

5

Last publish

Collaborators

  • ju99ernaut
  • joshmamroud