2.1.61 • Published 10 months ago

@serpstat/pagebuilder v2.1.61

Weekly downloads
-
License
-
Repository
-
Last release
10 months ago

Page builder

Dev Documentation

User Documntation

Development

npm install npm run start

Open:

http://localhost:8085/

Add new component

  1. Create new forlder in src/components.
  2. Add index.js
export default function NewComponent(editor) {
}
  1. Add style file for component (optional). Naming by template NewComponent.style.scss.

  2. Add new component to file src/components/index.js

 ...
 require('./NewComponent').default(editor);
}

Usage Serpstat admin panel

For example see file backend/views/pagebuilder_script/pagebuilder_script.php in prodvigator repo.

<link href="https://unpkg.com/grapesjs/dist/css/grapes.min.css" rel="stylesheet">
<link href="https://unpkg.com/@serpstat/pagebuilder@2.1.39/dist/css/pagebuilderStyles.css" rel="stylesheet">
<script src="https://unpkg.com/grapesjs@0.19.5/dist/grapes.min.js"></script>
<script src="https://unpkg.com/@serpstat/pagebuilder@2.1.39/dist/dist/pagebuilder.min.js"></script>

<script>
{
  const openPageBuilderBtn = document.querySelectorAll('.open-in-page-builder');

  function setReadyHtmlCss({ destinationResultHtmlId, html, css }) {
    const el = document.getElementById(destinationResultHtmlId);

    el.value = [
      `<style>${css}</style>`,
      html.replace('<body>', '').replace('</body>', ''),
    ].join('');
  }

  const builderVisibility = {
    hide(pagebilderContainerId) {
      const editorWrapp = document.getElementById(pagebilderContainerId);

      editorWrapp.style.display = 'none';
      document.querySelector('html').style.fontSize = '10px';
    },
    show(pagebilderContainerId) {
      const editorWrapp = document.getElementById(pagebilderContainerId);
      editorWrapp.style.display = 'block';
      editorWrapp.style.width = '100%';
      editorWrapp.style.position = 'fixed';
      editorWrapp.style.zIndex = '10000';
      editorWrapp.style.left = 0;
      editorWrapp.style.top = 0;
      document.querySelector('html').style.fontSize = '16px';
    }
  };

  try {
    for (const btn of openPageBuilderBtn) {
      let gEditor = null;

      function runEditorOnClick({
        storageDocId,
        destinationResultHtmlId,
        pagebilderContainerId,
        storageTextareaSelector,
      }) {
        return runEditor({
          container: `#${pagebilderContainerId}`,
          storageDocId: `${window.location.hostname}_${storageDocId}`,
          dependenciesStyles: [
            'https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700&amp;subset=latin,cyrillic&amp;display=swap',
            'https://serpstat.com/css/base_global.css',
            'https://serpstat.com/css/dialog.css?518901310',
            'https://unpkg.com/@serpstat/pagebuilder@2.1.39/dist/css/pagebuilder.css'
          ],
          saveAndCloseCallback() {
            const html = gEditor.getHtml({ cleanId: true });
            const css = gEditor.getCss();

            setReadyHtmlCss({
              destinationResultHtmlId, html, css
            });

            builderVisibility.hide(pagebilderContainerId);
          },
          assetManagerConfig: {
            upload: '/site/upload_image',
            uploadName: 'uploadfile',
            multiUpload: false,
            customFetch(url, fetchOpts) {
              return fetch(url, fetchOpts).then(res =>
                ((res.status / 200) | 0) == 1 ?
                  res.json().then(res => {
                    return {
                      data: [res.filelink],
                    }
                  }) :
                  res.text().then(text => Promise.reject(text)
                  )
              );
            }
          },
          storageManager: {
            type: 'textarea-storage',
            options: {
              ['textarea-storage']: {
                selector: storageTextareaSelector,
              }
            }
          }
        });
      }

      btn.addEventListener('click', function () {
        const {
          storageDocId,
          destinationResultHtmlId,
          pagebilderContainerId,
          storageTextareaSelector,
        } = this.dataset;

        if (!gEditor) {
          if (typeof runEditor === 'undefined') {
            const initContent = btn.innerText;
            btn.setAttribute('disable', true);
            btn.innerText = 'Loading builder...';

            const internal = setInterval(() => {
              if (
                typeof runEditor === 'undefined' ||
                typeof grapesjs === 'undefined'
              ) {
                return;
              };

              btn.setAttribute('disable', false);
              btn.innerText = initContent;
              gEditor = runEditorOnClick({
                storageDocId,
                destinationResultHtmlId,
                pagebilderContainerId,
                storageTextareaSelector,
              });
              builderVisibility.show(pagebilderContainerId);

              clearInterval(internal);
            }, 1000);

          } else {
            gEditor = runEditorOnClick({
              storageDocId,
              destinationResultHtmlId,
              pagebilderContainerId,
              storageTextareaSelector,
            });
            builderVisibility.show(pagebilderContainerId);
          }

          return;
        };

        builderVisibility.show(pagebilderContainerId);
      });
    }
  } catch (e) {
    console.error(e);
  }
}
</script>
2.1.58

10 months ago

2.1.59

10 months ago

2.1.57

10 months ago

2.1.61

10 months ago

2.1.60

10 months ago

2.1.56

10 months ago

2.1.54

11 months ago

2.1.55

11 months ago

2.1.49

1 year ago

2.1.47

1 year ago

2.1.48

1 year ago

2.1.46

1 year ago

2.1.52

1 year ago

2.1.53

1 year ago

2.1.50

1 year ago

2.1.51

1 year ago

2.1.45

1 year ago

2.1.43

1 year ago

2.1.44

1 year ago

2.1.41

1 year ago

2.1.42

1 year ago

2.1.40

1 year ago

2.1.39

1 year ago

2.1.38

1 year ago

2.1.37

1 year ago

2.1.35

1 year ago

2.1.27

2 years ago

2.1.28

2 years ago

2.1.29

2 years ago

2.1.34

1 year ago

2.1.32

1 year ago

2.1.33

1 year ago

2.1.30

2 years ago

2.1.31

2 years ago

2.1.23

2 years ago

2.1.9

2 years ago

2.1.18

2 years ago

2.1.2

2 years ago

2.1.17

2 years ago

2.1.1

2 years ago

2.1.4

2 years ago

2.1.3

2 years ago

2.1.12

2 years ago

2.1.6

2 years ago

2.1.5

2 years ago

2.1.21

2 years ago

2.1.10

2 years ago

2.1.8

2 years ago

2.1.11

2 years ago

2.1.7

2 years ago

2.0.1

2 years ago

1.3.17

2 years ago

1.3.16

2 years ago

1.3.15

2 years ago

1.0.1

2 years ago