Home logo
stupidly simple zoom controller for grapesjs

stupidly simple zoom controller for grapesjs

by Gx Anshu | Sat Jul 15 2023

Tech Stack

GrapesJS is an incredible no-code editor, widely renowned for its amazing features and the fact that it’s open source.

While GrapesJS offers a wide range of APIs to customize the editor, there are times when modifying certain functionalities can be a bit challenging. One such challenge arises when trying to add zoom in and zoom out functionality to the editor. To address this issue, I created the Zoom controller Plugin as a simple and effective solution.

All you need to do is install the plugin, and voila! You’ll have access to two handy buttons in the editor panel, as well as a convenient keyboard shortcut (Shift + and Shift -) to effortlessly zoom in and out of the canvas.

With this plugin, zooming becomes a breeze, enhancing your editing experience and streamlining your workflow.

DEMO

<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-zoom-plugin"></script>

<div id="gjs"></div>
const editor = grapesjs.init({
  container: "#gjs",
  height: "100%",
  fromElement: true,
  storageManager: false,
  plugins: ["grapesjs-zoom-plugin"],
});
body,
html {
  margin: 0;
  height: 100%;
}
  • CDN

    • https://unpkg.com/grapesjs-zoom-plugin
  • NPM

    • npm i grapesjs-zoom-plugin
  • GIT

    • git clone https://github.com/gxnanshu/grapesjs-zoom-plugin.git

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-zoom-plugin.min.js"></script>

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

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

Modern javascript

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

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