Git Product home page Git Product logo

Comments (9)

Jean-Baptiste-Lasselle avatar Jean-Baptiste-Lasselle commented on May 28, 2024

An interesting Express tutorial :

from grapejs-server.

Jean-Baptiste-Lasselle avatar Jean-Baptiste-Lasselle commented on May 28, 2024

cf. GrapesJS/grapesjs#1438 👍

In your react component's componentDidMount() you can initialize the editor like below:

var editor;
componentDidMount{
 editor = grapesjs.init({
      container: "#editor-portal",
      allowScripts: 1,
      height: "100vh",
      canvas: {
        styles: selectedTemplateExternalStyles,
        scripts: selectedTemplateExternalScripts
      },
      plugins: ["gjs-preset-webpage", "grapesjs-custom-code"],
      pluginsOpts: {
        "gjs-preset-webpage": {
          exportOpts: {
            filenamePfx: "hc",
            filename: null,
            addExportBtn: 1,
            btnLabel: "Export to ZIP"
          }
        },
        "grapesjs-custom-code": {}
      },
      storageManager: {
        id: "gjs-",
        type: "remote",
        autosave: 1,
        autoload: 1,
        stepsBeforeSave: 1, // If autosave enabled, indicates how many steps (general changes to structure), need to be done before save. Useful with remoteStorage to reduce remote calls
        urlLoad: API_ROOT + "/template/get/" + this.state.editorType + "/" + this.props.templateId,// Endpoint where to fetch data
        urlStore: API_ROOT + "/template/save/" + this.props.templateId, // Endpoint where to save all stuff
        headers: { "x-apiKey": "XXXXXXXXXXXX" },
        contentTypeJson: true // false: 'x-www-form-urlencoded' // true: application/json; charset=utf-8'   // set contentType paramater of $.ajax
      }
    });
}

from grapejs-server.

Jean-Baptiste-Lasselle avatar Jean-Baptiste-Lasselle commented on May 28, 2024

https://grapesjs.com/docs/modules/Storage.html#store-and-load-templates

from grapejs-server.

Jean-Baptiste-Lasselle avatar Jean-Baptiste-Lasselle commented on May 28, 2024

J'ai pu vérifier que l'instruction suivante, permet de recharger le template dans le browser :

editor.load(res => console.log('Load callback'));
editor.load(res => console.log('Load callback with res : [' + res + '] '));

from grapejs-server.

Jean-Baptiste-Lasselle avatar Jean-Baptiste-Lasselle commented on May 28, 2024

En voilà un qui m'avzait caché cela... :

editor.load(res => console.log('Load callback with res : [' + res.html + '] '));
Load callback with res : [<div data-gjs="navbar" class="navbar"><div class="navbar-container"><a href="/" class="navbar-brand"></a><div id="id5ba-2" class="navbar-burger"><div class="navbar-burger-line"></div><div class="navbar-burger-line"></div><div class="navbar-burger-line"></div></div><div data-gjs="navbar-items" class="navbar-items-c"><nav data-gjs="navbar-menu" class="navbar-menu"><a href="#" class="navbar-menu-link">Home</a><a href="#" class="navbar-menu-link">About</a><a href="#" class="navbar-menu-link">Contact</a></nav></div></div></div><h1>Ok Vinse !</h1><div class="row"><div class="cell"></div><div class="cell"></div></div><script>var items = document.querySelectorAll('#id5ba-2');
        for (var i = 0, len = items.length; i < len; i++) {
          (function(){var e,t=0,n=function(){var e,t=document.createElement("void"),n={transition:"transitionend",OTransition:"oTransitionEnd",MozTransition:"transitionend",WebkitTransition:"webkitTransitionEnd"};for(e in n)if(void 0!==t.style[e])return n[e]}(),r=function(e){var t=window.getComputedStyle(e),n=t.display,r=(t.position,t.visibility,t.height,parseInt(t["max-height"]));if("none"!==n&&"0"!==r)return e.offsetHeight;e.style.height="auto",e.style.display="block",e.style.position="absolute",e.style.visibility="hidden";var i=e.offsetHeight;return e.style.height="",e.style.display="",e.style.position="",e.style.visibility="",i},i=function(e){t=1;var n=r(e),i=e.style;i.display="block",i.transition="max-height 0.25s ease-in-out",i.overflowY="hidden",""==i["max-height"]&&(i["max-height"]=0),0==parseInt(i["max-height"])?(i["max-height"]="0",setTimeout(function(){i["max-height"]=n+"px"},10)):i["max-height"]="0"},a=function(r){if(r.preventDefault(),!t){var a=this.closest("[data-gjs=navbar]"),o=a.querySelector("[data-gjs=navbar-items]");i(o),e||(o.addEventListener(n,function(){t=0;var e=o.style;0==parseInt(e["max-height"])&&(e.display="",e["max-height"]="")}),e=1)}};"gjs-collapse"in this||this.addEventListener("click",a),this["gjs-collapse"]=1}.bind(items[i]))();
        }</script>] debugger eval code:1:20

Donc (cf.

const LandingPage = {
) :

editor.load(res => console.log('Load callback with HTML : [' + res.html + '] '));
editor.load(res => console.log('Load callback with HTML : [' + res.css + '] '));
editor.load(res => console.log('Load callback with HTML : [' + res.style + '] '));
editor.load(res => console.log('Load callback with HTML : [' + res.components + '] '));

from grapejs-server.

Jean-Baptiste-Lasselle avatar Jean-Baptiste-Lasselle commented on May 28, 2024

Ok, trouvé une autre indication :

Are you able to see the ajax call in inspector?
Have you tried to add storage listeners?

editor.on('storage:load', function(e) {
      console.log('Loaded ', e);
})
editor.on('storage:store', function(e) {
      console.log('Stored ', e);
})

from grapejs-server.

Jean-Baptiste-Lasselle avatar Jean-Baptiste-Lasselle commented on May 28, 2024

ça y est , désormais, le index.html du template choisis au départ, est automatiquement chargé dans l'éditeur GrapesJS 👍

Pour en terminer avec un premier use case simple de webdesigner, je dois encore :

  • Avant de retourner le HTML au client, transformer les URL présentes dans les attributs de balise src et href , et ce sauf lorsque leur valeur commence par le caractère dièse #.
  • La transformation doit avoir lieu sur l'objet template, exactement à ce point du code, et consiste à :
const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
  • récupérer chaque attribut href et src, de balise HTML, à l'aide de cheerio (l'équivalent de jackson en java pour parser le XML)
const cheerio = require('cheerio')
const $ = cheerio.load('<h2 class="title">Hello world</h2>')
 
$('h2.title').text('Hello there!')
$('h2').addClass('welcome')
 
$.html()
  • si l'URL commence par un point : insérer /omega juste après le caractères point .

  • si l'URL commence par http:// ou https:// : alors il faut insérer /omega juste après le $HOSTNAME:PORT_NO

  • si l'URL ne commence ni par un point, ni par un http:// ou par un https:// , alors il faut insérer /omega en préfixe de la chaîne de caractères.

  • Faire usage du module replace-string pour faire les substitions des points précédents.

  • ajouter un composant graphique de type arbre de fichiers, pour sélectionner un des fichiers HTML que 'lon veut charger pour l'édition

  • Ce composant Graphqiue fera appel au endpoint serveur, pour récupérer le HTML, et devra mettre à jour l'éditeur , avec quelque chose comme 👍

  editor.html = "le HTML qui a été retourné du serveur"
  editor.css = null
  editor.style = null
  // editor.components = "le HMTL qui a été retourné du serveur"
  

Note :

Concernant les mails, il y a du templating qui semble boien efficace en NodeJS :

https://www.npmjs.com/package/string-template

The WHATWG URL API

La Classe URL parse bien l'URL renseignée, ds l'instanciation, et lève les exceptions nécessaires, s'il en est :

Content Security Policy: Ignoring ‘x-frame-options’ because of ‘frame-ancestors’ directive.
const myURL =
  new URL('https://user:[email protected]:8080/p/a/t/h?query=string#hash');
undefined
const myURL =
  new URL('\\https://user:[email protected]:8080/p/a/t/h?query=string#hash');
SyntaxError: redeclaration of const myURL debugger eval code:1:1
```- 

from grapejs-server.

Jean-Baptiste-Lasselle avatar Jean-Baptiste-Lasselle commented on May 28, 2024

Le traitement de substitution à 4 choix, doit se faire à ce point du code :

var new_src = "omega/" + old_src;

à noter de plus :

GrapesJS/grapesjs#597

  • cheerio donne des problèmes pour changer les valeurs d'attributs
  • jsdom ne me paraît pas évident à utilsier, je tombe difficilemet sur des docs claires, pour changer al valeur d'un attribut
  • Prochain candidat : https://github.com/mfahlandt/node-xml-stream-parser

from grapejs-server.

Jean-Baptiste-Lasselle avatar Jean-Baptiste-Lasselle commented on May 28, 2024

dernier tests faits avec :

https://templated.co/hielo

avec :

from grapejs-server.

Related Issues (5)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.