Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

code editor closed when clicked another content/element #56

Open
thenotoriousgustav opened this issue Oct 15, 2024 · 0 comments
Open

code editor closed when clicked another content/element #56

thenotoriousgustav opened this issue Oct 15, 2024 · 0 comments

Comments

@thenotoriousgustav
Copy link

thenotoriousgustav commented Oct 15, 2024

"use client";

import React, { useState } from "react";

import grapesjs, { Editor } from "grapesjs";
import GjsEditor from "@grapesjs/react";
import pluginTailwind from "grapesjs-tailwind";
import pluginWebpage from "grapesjs-preset-webpage";
import pluginExport from "grapesjs-plugin-export";
import pluginCodeEditor from "grapesjs-component-code-editor";

import "grapesjs/dist/css/grapes.min.css";
import "grapesjs-component-code-editor/dist/grapesjs-component-code-editor.min.css";

import FormPublish from "./_components/form-publish";
import { componentsPlugin } from "@/components/grapesjs/plugins/components/modal";

export default function EditorPage() {
const [editor, setEditor] = useState();

function onEditor(newEditor: Editor) {
console.log("Editor loaded", { newEditor });
setEditor(newEditor);

const pn = newEditor.Panels;
const panelViews = pn.addPanel({
  id: "views",
});
panelViews.get("buttons")?.add([
  {
    attributes: {
      title: "Open Code",
    },
    className: "fa fa-file-code-o",
    command: "open-code",
    togglable: false, //do not close when button is clicked again
    id: "open-code",
  },
]);

componentsPlugin(newEditor);

}

return (
<>
<GjsEditor
grapesjs={grapesjs}
options={{
plugins: [
pluginWebpage,
pluginExport,
componentsPlugin,
pluginCodeEditor,
pluginTailwind,
],
pluginsOpts: {
[pluginWebpage]: {
// Ensure the correct reference here
modalImportTitle: "Import Template",
modalImportLabel:
'

Paste here your HTML/CSS and click Import
',
modalImportContent: function (editor: Editor) {
return (
editor.getHtml() + "<style>" + editor.getCss() + "</style>"
);
},
},
},
height: "100vh",
fromElement: true,
showOffsets: true,
storageManager: {
type: "local",
autosave: true,
autoload: true,
stepsBeforeSave: 1,
},
selectorManager: {
componentFirst: true,
},
}}
onEditor={onEditor}
/>

</>

);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant