psy_vk2 / builder.html
DmitrMakeev's picture
Update builder.html
404af27 verified
raw
history blame
4.12 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>GrapesJS Example</title>
<!-- GrapesJS CSS -->
<link rel="stylesheet" href="https://unpkg.com/grapesjs/dist/css/grapes.min.css">
</head>
<body>
<div id="gjs"></div>
<!-- GrapesJS JS -->
<script src="https://unpkg.com/grapesjs"></script>
<!-- Your Custom JS -->
<script>
const editor = grapesjs.init({
container: '#gjs',
fromElement: true,
height: '100vh',
storageManager: { type: 0 },
plugins: [],
pluginsOpts: {},
selectorManager: {
componentFirst: true,
},
});
const domc = editor.DomComponents;
const bm = editor.BlockManager;
// Add blocks for the first example
bm.add('component-css-block', {
label: 'Component with CSS',
content: {
type: 'component-css',
},
});
// Add blocks for the second example
bm.add('cmp-a-block', {
label: 'Component A',
content: {
type: 'cmp-a',
},
});
bm.add('cmp-b-block', {
label: 'Component B',
content: {
type: 'cmp-b',
},
});
bm.add('component-css-block-2', {
label: 'Component with CSS 2',
content: {
type: 'component-css',
},
});
// Define component types
domc.addType('component-css', {
model: {
defaults: {
attributes: { class: 'cmp-css' },
components: `
<span>Component with styles<span>
<div class="cmp-css-a">Component A</div>
<div class="cmp-css-b">Component B</div>
`,
styles: `
.cmp-css { color: red }
.cmp-css-a { color: green }
.cmp-css-b { color: blue }
@media (max-width: 992px) {
.cmp-css{ color: darkred; }
.cmp-css-a { color: darkgreen }
.cmp-css-b { color: darkblue }
}
`,
},
},
});
domc.addType('cmp-a', {
model: {
defaults: {
attributes: { class: 'cmp-css-a' },
components: 'Component A',
styles: `
.cmp-css-a { color: green }
@media (max-width: 992px) {
.cmp-css-a { color: darkgreen }
}
`,
}
},
});
domc.addType('cmp-b', {
model: {
defaults: {
attributes: { class: 'cmp-css-b' },
components: 'Component B',
styles: `
.cmp-css-b { color: blue }
@media (max-width: 992px) {
.cmp-css-b { color: darkblue }
}
`,
}
},
});
domc.addType('component-css', {
model: {
defaults: {
attributes: { class: 'cmp-css' },
components: [
'<span>Component with styles<span>',
{ type: 'cmp-a' },
{ type: 'cmp-b' },
],
styles: `
.cmp-css { color: red }
@media (max-width: 992px) {
.cmp-css{ color: darkred; }
}
`,
},
},
});
</script>
</body>
</html>