Skip to content

Commit 7b34f3c

Browse files
committed
Exporting sheet into .nlx file
1 parent 65fd340 commit 7b34f3c

File tree

7 files changed

+135
-14
lines changed

7 files changed

+135
-14
lines changed

src/icons/export.svg

+24
Loading

src/icons/import.svg

+24
Loading

src/index.css

+33-4
Original file line numberDiff line numberDiff line change
@@ -222,14 +222,39 @@ body::-webkit-scrollbar, #input::-webkit-scrollbar, #code::-webkit-scrollbar, .s
222222
overflow: hidden;
223223
background-color: rgba(0, 0, 0, 0.4);
224224
}
225-
225+
.cont{
226+
display: flex
227+
}
226228
.settings-button{
229+
margin-right: 5px;
227230
background-image: url('./icons/settings.svg');
228231
background-size: 25px;
229232
background-repeat: no-repeat;
230233
border: none;
231234
color: #b0b0b0;
232-
padding: 10px;
235+
width: 25px;
236+
height: 45px;
237+
cursor: pointer;
238+
}
239+
.export{
240+
margin-right: 5px;
241+
background-image: url('./icons/export.svg');
242+
background-size: 25px;
243+
background-repeat: no-repeat;
244+
border: none;
245+
color: #b0b0b0;
246+
width: 25px;
247+
height: 45px;
248+
cursor: pointer;
249+
}
250+
251+
.import{
252+
margin-right: 5px;
253+
background-image: url('./icons/import.svg');
254+
background-size: 25px;
255+
background-repeat: no-repeat;
256+
border: none;
257+
color: #b0b0b0;
233258
width: 25px;
234259
height: 45px;
235260
cursor: pointer;
@@ -345,6 +370,7 @@ select{
345370
height: 100% !important;
346371
flex-grow: 1 !important;
347372
margin-top: 0 !important;
373+
width: 350px;
348374
}
349375

350376

@@ -374,8 +400,11 @@ select{
374400
}
375401

376402
.CodeMirror-placeholder {
377-
color: #5a5a5a !important; /* Custom color for the placeholder text */
378-
}
403+
color: #5a5a5a !important; /* Custom color for the placeholder text */
404+
white-space: pre-wrap !important;
405+
display: block !important;
406+
width: 100% !important;
407+
}
379408

380409
.CodeMirror div.CodeMirror-cursors .CodeMirror-cursor {
381410
border-left: 1px solid #ffffff; /* Custom color for the cursor */

src/index.html

+6-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@
2020
Subtotals
2121
</div>
2222
</div>
23-
<button class="settings-button" onclick="openSettings()"></button>
23+
<div class="cont">
24+
<button class="settings-button" onclick="openSettings()"></button>
25+
<button class="export" onclick="exportCurrentSheet()"></button>
26+
<input type="file" id="file-input" style="display:none" accept=".nlx" />
27+
<button class="import" onclick="document.getElementById('file-input').click()"></button>
28+
</div>
2429
</div>
2530
<div class="main">
2631
<div class="main-header">

src/script.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,15 @@ CodeMirror.defineMode('custom', function (config, parserConfig) {
5151
},
5252
}
5353
})
54-
54+
let placehold = 'Enter an expression to start'
5555
let editor = CodeMirror.fromTextArea(document.getElementById('input'), {
5656
lineNumbers: false,
5757
scrollbarStyle: 'null',
5858
theme: 'default', // Выберите тему редактора
5959
lint: true,
6060
mode: 'custom',
61-
placeholder: 'Enter an expression to start',
61+
placeholder: placehold,
62+
lineWrapping: true,
6263
})
6364
function updateDeclaredVariables() {
6465
declaredVariables = {} // Очистка переменных перед повторным анализом

src/sheets.js

+43
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,32 @@
1+
document
2+
.getElementById('file-input')
3+
.addEventListener('change', function (event) {
4+
const file = event.target.files[0]
5+
if (file) {
6+
const reader = new FileReader()
7+
reader.onload = function (e) {
8+
const content = e.target.result
9+
console.log('File content:', content)
10+
try {
11+
const importedData = JSON.parse(content)
12+
console.log('Imported data:', importedData)
13+
if (importedData.title && importedData.content) {
14+
// Пример: предполагаемый формат данных в NLX файле
15+
sheets.push(importedData) // Добавляем новый лист в массив sheets
16+
switchSheet(sheets.length - 1) // Переключаемся на новый лист
17+
renderSheets()
18+
} else {
19+
alert('Неверный формат файла NLX')
20+
}
21+
} catch (error) {
22+
console.error('Error parsing file:', error)
23+
alert('Ошибка при чтении файла')
24+
}
25+
}
26+
reader.readAsText(file)
27+
}
28+
})
29+
130
function addNewSheet() {
231
const currentTime = new Date()
332
const hours = currentTime.getHours().toString().padStart(2, '0')
@@ -68,3 +97,17 @@ document.addEventListener('DOMContentLoaded', function () {
6897
renderSheets()
6998
switchSheet(currentSheetIndex)
7099
})
100+
101+
function exportCurrentSheet() {
102+
const currentSheet = sheets[currentSheetIndex]
103+
const dataToExport = JSON.stringify(currentSheet) // Пример: экспортируем как JSON для простоты
104+
const blob = new Blob([dataToExport], { type: 'application/json' }) // Создаем Blob из строки JSON
105+
const url = URL.createObjectURL(blob)
106+
const a = document.createElement('a')
107+
a.href = url
108+
a.download = `${currentSheet.title}.nlx`
109+
document.body.appendChild(a)
110+
a.click()
111+
document.body.removeChild(a)
112+
URL.revokeObjectURL(url)
113+
}

src/translations.js

+2-7
Original file line numberDiff line numberDiff line change
@@ -84,18 +84,13 @@ const translations = {
8484
function updateLanguageTexts() {
8585
const lang = translations[currentLanguage]
8686
document.getElementById('new-sheet').textContent = lang.newSheet
87-
document.getElementById('input').placeholder = lang.enter
87+
placehold = lang.enter
88+
editor.setOption('placeholder', placehold) // Обновление placeholder в CodeMirror
8889
document.getElementById('settings-title').textContent = lang.settings
8990
document.getElementById('round-label').textContent = lang.round
90-
document.getElementById('color-label').textContent = lang.fontcolor
9191
document.getElementById('font-label').textContent = lang.fontsize
9292
document.getElementById('lang-label').textContent = lang.language
9393
document.getElementById('sheet-label').textContent = lang.sheetname
94-
95-
const colorSelector = document.getElementById('colorSelector')
96-
for (let option of colorSelector.options) {
97-
option.textContent = lang[option.value]
98-
}
9994
}
10095

10196
function changeLanguage() {

0 commit comments

Comments
 (0)