-
Notifications
You must be signed in to change notification settings - Fork 1
/
editor.html
212 lines (172 loc) · 6.68 KB
/
editor.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Current Page Editor</title>
<link rel="icon" href="./img/favicon.ico" />
<script src="./js/lib/tailwind.js"></script>
<link rel="stylesheet" href="./css/style.css" />
<link href="./css/quill.min.css" rel="stylesheet" />
<style>
#preview .quill-editor {
display: none;
}
.ql-toolbar.ql-snow {
background: #f5eedb;
font-size: 0.9em;
}
div.block-wrapper.highlight-border {
outline: 3px dotted #6445e2;
box-shadow: 0 0 5px rgba(51, 1, 231, 0.5);
}
.highlight-border {
outline: 3px dotted #0ea5e8;
box-shadow: 0 0 5px rgba(0, 123, 255, 0.5);
}
</style>
<style type="text/tailwindcss">
@layer base {
:root {
--background: 0 0% 100%;
--foreground: 240 10% 3.9%;
--card: 0 0% 100%;
--card-foreground: 240 10% 3.9%;
--popover: 0 0% 100%;
--popover-foreground: 240 10% 3.9%;
--primary: 142.1 76.2% 36.3%;
--primary-foreground: 355.7 100% 97.3%;
--secondary: 240 4.8% 95.9%;
--secondary-foreground: 240 5.9% 10%;
--muted: 240 4.8% 95.9%;
--muted-foreground: 240 3.8% 46.1%;
--accent: 240 4.8% 95.9%;
--accent-foreground: 240 5.9% 10%;
--destructive: 0 84.2% 60.2%;
--destructive-foreground: 0 0% 98%;
--border:240 5.9% 90%;
--input:240 5.9% 90%;
--ring:142.1 76.2% 36.3%;
--radius: 0.75rem;
}
.dark {
--background:20 14.3% 4.1%;
--foreground:0 0% 95%;
--card:24 9.8% 10%;
--card-foreground:0 0% 95%;
--popover:0 0% 9%;
--popover-foreground:0 0% 95%;
--primary:142.1 70.6% 45.3%;
--primary-foreground:144.9 80.4% 10%;
--secondary:240 3.7% 15.9%;
--secondary-foreground:0 0% 98%;
--muted:0 0% 15%;
--muted-foreground:240 5% 64.9%;
--accent:12 6.5% 15.1%;
--accent-foreground:0 0% 98%;
--destructive:0 62.8% 30.6%;
--destructive-foreground:0 85.7% 97.3%;
--border:240 3.7% 15.9%;
--input:240 3.7% 15.9%;
--ring:142.4 71.8% 29.2%;
}
}
</style>
</head>
<body class="font-sans bg-slate-50 text-slate-900 dark:bg-slate-900 dark:text-slate-100 transition-colors duration-200">
<div id="builder" class="flex h-[calc(100vh-64px)] overflow-hidden">
<div id="preview" class="flex-grow overflow-y-auto p-4 bg-white dark:bg-slate-900"></div>
</div>
<div id="modal-overlay" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center hidden z-20">
<div id="editor-container" class="bg-white dark:bg-slate-900 p-4 rounded-lg w-full max-w-2xl">
<div>
<h3 class="text-2xl font-bold mb-4 text-slate-800 dark:text-white">Edit Content</h3>
<div id="editor-area"
class="bg-white dark:bg-slate-950 text-slate-800 dark:text-white rounded-b-[.5em] h-64 mb-4 code language-html"></div>
<div class="flex justify-end">
<button id="save-edit" class="px-3 py-1 bg-sky-500 text-white text-[.75em] rounded-[.5em]">Save</button>
<button id="cancel-edit"
class="ml-2 px-3 py-1 bg-slate-500 text-white text-[.75em] rounded-[.5em]">Cancel</button>
</div>
</div>
</div>
</div>
</div>
<script defer src="./js/lib/quill.js"></script>
<script defer src="./js/default.js"></script>
<script defer src="./js/classes.js"></script>
<script defer src="./js/editor.js"></script>
<script>
// Get Current FontFamily
function safeGet(obj, path) {
return path.split('.').reduce((acc, part) => acc && acc[part], obj);
}
function currentFontFamily() {
const currentPage = JSON.parse(localStorage.getItem("currentState"));
//const configString = JSON.stringify(currentState.sceleton.config);
let config;
const configString = safeGet(currentPage, 'sceleton.config');
try {
config = JSON.parse(configString);
} catch (error) {
console.error('Error config process: ', error);
return;
}
const sans = safeGet(config, 'theme.fontFamily.sans');
if (sans) {
const fontFamily = Array.isArray(config.theme.fontFamily.sans)
? config.theme.fontFamily.sans[0]
: config.theme.fontFamily.sans;
const systemFonts = ['sans-serif', 'serif', 'monospace', 'cursive', 'fantasy', 'system-ui', 'ui-sans-serif', 'ui-serif', 'ui-monospace', 'ui-rounded'];
if (typeof fontFamily === 'string' && !systemFonts.includes(fontFamily.toLowerCase())) {
return fontFamily;
}
}
}
function setFontLink() {
const fontFamily = currentFontFamily();
if (fontFamily) {
const linkElement = document.createElement('link');
linkElement.href = `https://fonts.googleapis.com/css2?family=${fontFamily}:wght@400;500;600;700&display=swap`;
linkElement.rel = 'stylesheet';
const titleElement = document.querySelector('title');
if (titleElement) {
titleElement.insertAdjacentElement('afterend', linkElement);
} else {
document.head.appendChild(linkElement);
}
}
}
setFontLink();
function addSectionControls(section) {
const controlButton = document.createElement('div');
controlButton.style.position = 'absolute';
controlButton.style.top = '5px';
controlButton.style.right = '5px';
controlButton.style.width = '20px';
controlButton.style.height = '20px';
controlButton.style.backgroundColor = 'rgba(0, 123, 255, 0.8)';
controlButton.style.cursor = 'pointer';
controlButton.style.zIndex = '1000';
controlButton.title = 'Select Section';
controlButton.addEventListener('click', (event) => {
event.stopPropagation(); // Останавливаем распространение клика, чтобы избежать открытия внутреннего div
handleSectionClick(section); // Обрабатываем клик по секции
});
section.style.position = 'relative'; // Делаем секцию позиционируемой
section.appendChild(controlButton);
}
function handleSectionClick(section) {
// Здесь добавьте логику для открытия секции в редакторе
console.log('Section clicked:', section);
}
function initializeSectionControls() {
document.querySelectorAll('section').forEach(addSectionControls);
}
// Вызывайте функцию при загрузке контента
document.addEventListener('DOMContentLoaded', () => {
initializeSectionControls();
});
</script>
</body>
</html>