DmitrMakeev
commited on
Upload 5 files
Browse files
editor /plugins/custom-code-editor.js
ADDED
@@ -0,0 +1,154 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
function customCodeEditor(editor) {
|
2 |
+
const stylePrefix = editor.getConfig().stylePrefix;
|
3 |
+
|
4 |
+
// let code placeholder
|
5 |
+
let selectedComponent = '';
|
6 |
+
|
7 |
+
// Div set up
|
8 |
+
let codeDivEditor = document.createElement('div');
|
9 |
+
codeDivEditor.setAttribute("class", "gjs-cm-editor-c");
|
10 |
+
|
11 |
+
let codeDiv = document.createElement('div');
|
12 |
+
codeDiv.setAttribute("class", "gjs-cm-editor");
|
13 |
+
codeDiv.setAttribute("id", "gjs-cm-htmlmixed");
|
14 |
+
|
15 |
+
let codeDivTitle = document.createElement('div');
|
16 |
+
codeDivTitle.setAttribute("id", "gjs-cm-title");
|
17 |
+
codeDivTitle.innerHTML = "HTML";
|
18 |
+
|
19 |
+
let codeDivHTML = document.createElement('div');
|
20 |
+
codeDivHTML.setAttribute("id", "gjs-cm-code");
|
21 |
+
|
22 |
+
let btnSave = document.createElement('button');
|
23 |
+
btnSave.innerHTML = 'Apply <span class="dotted-white-bottom-border">HTML</span> Changes';
|
24 |
+
btnSave.className = stylePrefix + 'btn-prim ' + stylePrefix + 'btn-import ' + stylePrefix + 'btn--full';
|
25 |
+
|
26 |
+
codeDiv.appendChild(codeDivTitle);
|
27 |
+
codeDiv.appendChild(codeDivHTML);
|
28 |
+
codeDiv.appendChild(btnSave);
|
29 |
+
|
30 |
+
codeDivEditor.appendChild(codeDiv);
|
31 |
+
|
32 |
+
const command = editor.Commands
|
33 |
+
const modal = editor.Modal;
|
34 |
+
|
35 |
+
// CodeMirror setup
|
36 |
+
var htmlCodeViewer = editor.CodeManager.getViewer('CodeMirror').clone();
|
37 |
+
htmlCodeViewer.set({
|
38 |
+
codeName: 'htmlmixed',
|
39 |
+
readOnly: 0,
|
40 |
+
theme: 'hopscotch',
|
41 |
+
autoBeautify: true,
|
42 |
+
autoCloseTags: true,
|
43 |
+
autoCloseBrackets: true,
|
44 |
+
lineWrapping: true,
|
45 |
+
styleActiveLine: true,
|
46 |
+
smartIndent: true,
|
47 |
+
indentWithTabs: true,
|
48 |
+
tabSize: 3,
|
49 |
+
indentUnit: 3
|
50 |
+
});
|
51 |
+
|
52 |
+
// Save code changes
|
53 |
+
btnSave.onclick = function() {
|
54 |
+
// Get the new component code
|
55 |
+
let htmlComponentCode = htmlCodeViewer.editor.getValue();
|
56 |
+
|
57 |
+
// On the sleced component update the new htmlComponentCode
|
58 |
+
let replacedComponent = selectedComponent.replaceWith(htmlComponentCode.trim());
|
59 |
+
// Now select the replacedComponent
|
60 |
+
editor.select(replacedComponent);
|
61 |
+
|
62 |
+
// Make message
|
63 |
+
let msg = `
|
64 |
+
<div class="uk-text-left uk-text-truncate uk-animation-slide-top-small">
|
65 |
+
<div class="uk-flex uk-flex-middle">
|
66 |
+
<span class="uk-margin-remove uk-text-small">
|
67 |
+
<span uk-icon="icon: check; ratio: 0.95;"></span>
|
68 |
+
<span>You've updated <span class="dotted-white-bottom-border">${replacedComponent.getName()}</span> component.</span>
|
69 |
+
</span>
|
70 |
+
</div>
|
71 |
+
</div>
|
72 |
+
`;
|
73 |
+
|
74 |
+
// Send notification
|
75 |
+
UIkit.notification({
|
76 |
+
message: msg,
|
77 |
+
status: 'primary',
|
78 |
+
pos: 'bottom-right',
|
79 |
+
group: 'message',
|
80 |
+
timeout: 3000
|
81 |
+
});
|
82 |
+
|
83 |
+
// close popup
|
84 |
+
modal.close();
|
85 |
+
};
|
86 |
+
|
87 |
+
// Command for opening the edit
|
88 |
+
command.add('edit-component-code', {
|
89 |
+
run: function(editor, sender) {
|
90 |
+
let component = editor.getSelected();
|
91 |
+
|
92 |
+
// Make sure component is selected
|
93 |
+
if (component == undefined) {
|
94 |
+
console.log("Warnning: No component was selected when executing 'edit-component-code' command");
|
95 |
+
return;
|
96 |
+
}
|
97 |
+
|
98 |
+
if (modal.isOpen())
|
99 |
+
modal.close();
|
100 |
+
|
101 |
+
let htmlViewer = htmlCodeViewer.editor;
|
102 |
+
if (!htmlViewer) {
|
103 |
+
let txtarea = document.createElement('textarea');
|
104 |
+
codeDivHTML.appendChild(txtarea);
|
105 |
+
htmlCodeViewer.init(txtarea);
|
106 |
+
htmlViewer = htmlCodeViewer.editor;
|
107 |
+
}
|
108 |
+
|
109 |
+
let htmlCode = component.toHTML();
|
110 |
+
|
111 |
+
// Set the current component of the component to selectedComponent
|
112 |
+
// so we can compare old and replace with new
|
113 |
+
selectedComponent = component;
|
114 |
+
|
115 |
+
// Now the set the component code
|
116 |
+
htmlCodeViewer.setContent(htmlCode);
|
117 |
+
|
118 |
+
modal.setTitle('Component Code');
|
119 |
+
modal.setContent(codeDivEditor);
|
120 |
+
modal.open();
|
121 |
+
|
122 |
+
htmlViewer.refresh();
|
123 |
+
}
|
124 |
+
});
|
125 |
+
|
126 |
+
// Open component settings on selection
|
127 |
+
editor.on('component:selected', () => {
|
128 |
+
const component = editor.getSelected();
|
129 |
+
|
130 |
+
// Switch view to open-tm (open trait manager)
|
131 |
+
editor.Panels.getButton('views', 'open-tm').set('active', true);
|
132 |
+
|
133 |
+
// Get the trait manger code button existance
|
134 |
+
const tmCodeBtn = component.get('traits').where({
|
135 |
+
name: 'tm-code-btn'
|
136 |
+
});
|
137 |
+
|
138 |
+
// Is the array empty?
|
139 |
+
if (tmCodeBtn.length == 0) {
|
140 |
+
|
141 |
+
// Adding button to trait manager
|
142 |
+
component.addTrait({
|
143 |
+
name: 'tm-code-btn', // Name is how we ref the trait
|
144 |
+
type: 'button',
|
145 |
+
text: 'Edit <span class="dotted-white-bottom-border">' + component.getName() + '</span> Code',
|
146 |
+
full: true, // Full width button
|
147 |
+
label: false,
|
148 |
+
command: 'edit-component-code'
|
149 |
+
}, {
|
150 |
+
at: 0
|
151 |
+
});
|
152 |
+
}
|
153 |
+
});
|
154 |
+
};
|
editor /plugins/custom-page-manager.js
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
function customPageManager(editor) {
|
2 |
+
const panelManager = editor.Panels;
|
3 |
+
|
4 |
+
var pages = {
|
5 |
+
current: 1,
|
6 |
+
pages: [
|
7 |
+
{ components: [], style: [] },
|
8 |
+
]
|
9 |
+
}
|
10 |
+
|
11 |
+
// Adding new button
|
12 |
+
panelManager.addButton('views', [{
|
13 |
+
id: 'manage-pages',
|
14 |
+
className: 'gjs-pn-btn',
|
15 |
+
command: '',
|
16 |
+
active: false,
|
17 |
+
label: `<span uk-icon="list" uk-tooltip="title: Manage Pages; pos: right"></span>`
|
18 |
+
}]);
|
19 |
+
|
20 |
+
}
|
editor /plugins/customize-devices.js
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
function customizeDevices(editor) {
|
2 |
+
const panelManager = editor.Panels;
|
3 |
+
|
4 |
+
// Hide default devices
|
5 |
+
editor.getConfig().showDevices = 0;
|
6 |
+
|
7 |
+
// Device icons manager
|
8 |
+
panelManager.addPanel({ id: "devices-c" }).get("buttons").add([
|
9 |
+
{
|
10 |
+
id: "set-device-desktop",
|
11 |
+
command: function(e) { return e.setDevice("Desktop") },
|
12 |
+
className: "gjs-dekstop-device",
|
13 |
+
active: true,
|
14 |
+
label: `<span uk-icon="icon: desktop; ratio: 1" uk-tooltip="title: Desktop Layout; pos: top"></span>`
|
15 |
+
},
|
16 |
+
{
|
17 |
+
id: "set-device-tablet",
|
18 |
+
command: function(e) { return e.setDevice("Tablet") },
|
19 |
+
className: "gjs-tablet-device",
|
20 |
+
label: `<span uk-icon="icon: tablet; ratio: 1" uk-tooltip="title: Tablet Layout; pos: top"></span>`
|
21 |
+
},
|
22 |
+
{
|
23 |
+
id: "set-device-mobile",
|
24 |
+
command: function(e) { return e.setDevice("Mobile portrait") },
|
25 |
+
className: "gjs-mobile-portrait-device",
|
26 |
+
label: `<span uk-icon="icon: phone; ratio: 1" uk-tooltip="title: Phone Layout; pos: top"></span>`
|
27 |
+
},
|
28 |
+
]);
|
29 |
+
|
30 |
+
}
|
editor /plugins/customize-options.js
ADDED
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
function customizeOptions(editor) {
|
2 |
+
const panelManager = editor.Panels;
|
3 |
+
const command = editor.Commands
|
4 |
+
|
5 |
+
// Command for opening the edit
|
6 |
+
command.add('custom-clear-canvas', {
|
7 |
+
run: function(editor, sender) {
|
8 |
+
// Clear components
|
9 |
+
editor.DomComponents.clear();
|
10 |
+
// Clear styles
|
11 |
+
editor.CssComposer.clear();
|
12 |
+
// Clear undo history
|
13 |
+
editor.UndoManager.clear();
|
14 |
+
|
15 |
+
// Make message
|
16 |
+
let msg = `
|
17 |
+
<div class="uk-text-left uk-text-truncate uk-animation-slide-top-small">
|
18 |
+
<div class="uk-flex uk-flex-middle">
|
19 |
+
<span class="uk-margin-remove uk-text-small">
|
20 |
+
<span uk-icon="icon: check; ratio: 0.95;"></span>
|
21 |
+
<span>You've cleared your canvas.</span>
|
22 |
+
</span>
|
23 |
+
</div>
|
24 |
+
</div>
|
25 |
+
`;
|
26 |
+
|
27 |
+
// Send notification
|
28 |
+
UIkit.notification({
|
29 |
+
message: msg,
|
30 |
+
status: 'primary',
|
31 |
+
pos: 'bottom-right',
|
32 |
+
group: 'message',
|
33 |
+
timeout: 3000
|
34 |
+
});
|
35 |
+
}
|
36 |
+
});
|
37 |
+
|
38 |
+
// Options button manager
|
39 |
+
panelManager.getButton('options', 'sw-visibility').set({
|
40 |
+
id: "sw-visibility",
|
41 |
+
className: 'gjs-pn-btn',
|
42 |
+
command: "sw-visibility",
|
43 |
+
active: true,
|
44 |
+
label: `<span uk-icon="thumbnails" uk-tooltip="title: Guide Lines; pos: bottom"></span>`
|
45 |
+
});
|
46 |
+
panelManager.getButton('options', 'preview').set({
|
47 |
+
id: "preview",
|
48 |
+
className: 'gjs-pn-btn',
|
49 |
+
command: "preview",
|
50 |
+
active: false,
|
51 |
+
label: `<span uk-icon="push" uk-tooltip="title: Preview; pos: bottom"></span>`
|
52 |
+
});
|
53 |
+
panelManager.getButton('options', 'fullscreen').set({
|
54 |
+
id: "fullscreen",
|
55 |
+
className: 'gjs-pn-btn',
|
56 |
+
command: "fullscreen",
|
57 |
+
active: false,
|
58 |
+
label: `<span uk-icon="expand" uk-tooltip="title: Set Fullscreen; pos: bottom"></span>`
|
59 |
+
});
|
60 |
+
panelManager.getButton('options', 'export-template').set({
|
61 |
+
id: "export-template",
|
62 |
+
className: 'gjs-pn-btn',
|
63 |
+
command: "export-template",
|
64 |
+
active: false,
|
65 |
+
label: `<span uk-icon="code" uk-tooltip="title: Show Code; pos: bottom"></span>`
|
66 |
+
});
|
67 |
+
|
68 |
+
// Adding new button
|
69 |
+
panelManager.addButton('options', [{
|
70 |
+
id: 'clear-canvas',
|
71 |
+
className: 'gjs-pn-btn',
|
72 |
+
command: 'custom-clear-canvas',
|
73 |
+
active: false,
|
74 |
+
label: `<span uk-icon="trash" uk-tooltip="title: Clear Canvas; pos: bottom"></span>`
|
75 |
+
}, ]);
|
76 |
+
|
77 |
+
}
|
editor /plugins/customize-views.js
ADDED
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
function customizeViews(editor) {
|
2 |
+
const panelManager = editor.Panels;
|
3 |
+
|
4 |
+
// Views button manager
|
5 |
+
panelManager.getButton('views', 'open-sm').set({
|
6 |
+
id: "open-sm",
|
7 |
+
className: 'gjs-pn-btn',
|
8 |
+
command: "open-sm",
|
9 |
+
active: true,
|
10 |
+
attributes: {
|
11 |
+
title: "Open Style Manager"
|
12 |
+
},
|
13 |
+
label: `<span uk-icon="paint-bucket" uk-tooltip="title: Customization; pos: right"></span>`
|
14 |
+
});
|
15 |
+
panelManager.getButton('views', 'open-tm').set({
|
16 |
+
id: "open-tm",
|
17 |
+
className: 'gjs-pn-btn',
|
18 |
+
command: "open-tm",
|
19 |
+
active: false,
|
20 |
+
attributes: {
|
21 |
+
title: "Open Settings"
|
22 |
+
},
|
23 |
+
label: `<span uk-icon="settings" uk-tooltip="title: Settings; pos: right"></span>`
|
24 |
+
});
|
25 |
+
panelManager.getButton('views', 'open-layers').set({
|
26 |
+
id: "open-layers",
|
27 |
+
className: 'gjs-pn-btn',
|
28 |
+
command: "open-layers",
|
29 |
+
active: false,
|
30 |
+
attributes: {
|
31 |
+
title: "Open Layers"
|
32 |
+
},
|
33 |
+
label: `<span uk-icon="table" uk-tooltip="title: Layers; pos: right"></span>`
|
34 |
+
});
|
35 |
+
panelManager.getButton('views', 'open-blocks').set({
|
36 |
+
id: "open-blocks",
|
37 |
+
className: 'gjs-pn-btn',
|
38 |
+
command: "open-blocks",
|
39 |
+
active: false,
|
40 |
+
attributes: {
|
41 |
+
title: "Open Blocks"
|
42 |
+
},
|
43 |
+
label: `<span uk-icon="grid" uk-tooltip="title: Blocks; pos: right"></span>`
|
44 |
+
});
|
45 |
+
}
|