-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 🎨 Add an editor for the styles loader
For simplicity I implemented it an endpoint for now. Closes #84
- Loading branch information
Showing
8 changed files
with
434 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/** | ||
* File: foldable.js | ||
* Project: comfy_mtb | ||
* Author: Mel Massadian | ||
* | ||
* Copyright (c) 2023 Mel Massadian | ||
* | ||
*/ | ||
|
||
function toggleFoldable(elementId, symbolId) { | ||
const content = document.getElementById(elementId) | ||
const symbol = document.getElementById(symbolId) | ||
if (content.style.display === 'none' || content.style.display === '') { | ||
content.style.display = 'flex' | ||
symbol.innerHTML = '▽' // Down arrow | ||
} else { | ||
content.style.display = 'none' | ||
symbol.innerHTML = '▷' // Right arrow | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/** | ||
* File: saveTableData.js | ||
* Project: comfy_mtb | ||
* Author: Mel Massadian | ||
* | ||
* Copyright (c) 2023 Mel Massadian | ||
* | ||
*/ | ||
|
||
function saveTableData(identifier) { | ||
const table = document.querySelector( | ||
`#style-editor table[data-id='${identifier}']` | ||
) | ||
|
||
let currentData = [] | ||
const rows = table.querySelectorAll('tr') | ||
const filename = table.getAttribute('data-id') | ||
|
||
rows.forEach((row, rowIndex) => { | ||
const rowData = [] | ||
const cells = | ||
rowIndex === 0 | ||
? row.querySelectorAll('th') | ||
: row.querySelectorAll('td input, td textarea') | ||
|
||
cells.forEach((cell) => { | ||
rowData.push(rowIndex === 0 ? cell.textContent : cell.value) | ||
}) | ||
|
||
currentData.push(rowData) | ||
}) | ||
|
||
let tablesData = {} | ||
tablesData[filename] = currentData | ||
|
||
console.debug('Sending styles to manage endpoint:', tablesData) | ||
fetch('/mtb/actions', { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify({ | ||
name: 'saveStyle', | ||
args: tablesData, | ||
}), | ||
}) | ||
.then((response) => response.json()) | ||
.then((data) => { | ||
console.debug('Success:', data) | ||
}) | ||
.catch((error) => { | ||
console.error('Error:', error) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/** | ||
* File: splitPane.js | ||
* Project: comfy_mtb | ||
* Author: Mel Massadian | ||
* | ||
* Copyright (c) 2023 Mel Massadian | ||
* | ||
*/ | ||
|
||
function initSplitPane(vertical) { | ||
let resizer = document.getElementById('resizer') | ||
let left = document.getElementById('leftPane') | ||
let right = document.getElementById('rightPane') | ||
resizer.addEventListener('mousedown', function (e) { | ||
document.addEventListener('mousemove', onMouseMove) | ||
document.addEventListener('mouseup', function () { | ||
document.removeEventListener('mousemove', onMouseMove) | ||
}) | ||
}) | ||
|
||
const onMouseMove = (e) => { | ||
if (vertical) { | ||
let leftWidth = e.clientX | ||
let rightWidth = window.innerWidth - e.clientX | ||
left.style.width = leftWidth + 'px' | ||
right.style.width = rightWidth + 'px' | ||
} else { | ||
let topHeight = e.clientY | ||
let bottomHeight = window.innerHeight - e.clientY | ||
left.style.height = topHeight + 'px' | ||
right.style.height = bottomHeight + 'px' | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/** | ||
* File: tabSwitch.js | ||
* Project: comfy_mtb | ||
* Author: Mel Massadian | ||
* | ||
* Copyright (c) 2023 Mel Massadian | ||
* | ||
*/ | ||
|
||
function openTab(evt, tabName) { | ||
var i, tabcontent, tablinks | ||
tabcontent = document.getElementsByClassName('tabcontent') | ||
for (i = 0; i < tabcontent.length; i++) { | ||
tabcontent[i].style.display = 'none' | ||
} | ||
tablinks = document.getElementsByClassName('tablinks') | ||
for (i = 0; i < tablinks.length; i++) { | ||
tablinks[i].className = tablinks[i].className.replace(' active', '') | ||
} | ||
document.getElementById(tabName).style.display = 'block' | ||
evt.currentTarget.className += ' active' | ||
} |
Oops, something went wrong.