mirror of
https://github.com/misode/misode.github.io.git
synced 2026-04-23 07:10:41 +00:00
Add source controls with copy and download
This commit is contained in:
@@ -3,14 +3,14 @@
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Document</title>
|
||||
<title>Minecraft Generators</title>
|
||||
<link rel="stylesheet" href="./styles/global.css">
|
||||
<link rel="stylesheet" href="./styles/nodes.css">
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="header">
|
||||
<select id="model-selector" class="dropdown">
|
||||
<select id="model-selector" class="btn">
|
||||
<option value="loot-table">Loot Table</option>
|
||||
<option value="predicate">Predicate</option>
|
||||
<option value="advancement">Advancement</option>
|
||||
@@ -21,9 +21,24 @@
|
||||
<div class="tree" id="tree-view"></div>
|
||||
<div class="source" id="source-view">
|
||||
<div class="source-controls">
|
||||
<button class="btn">Copy</button>
|
||||
<button class="btn" id="source-controls-toggle"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path d="M8 9a1.5 1.5 0 100-3 1.5 1.5 0 000 3zM1.5 9a1.5 1.5 0 100-3 1.5 1.5 0 000 3zm13 0a1.5 1.5 0 100-3 1.5 1.5 0 000 3z"></path></svg></button>
|
||||
<button class="btn" id="source-controls-copy">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M5.75 1a.75.75 0 00-.75.75v3c0 .414.336.75.75.75h4.5a.75.75 0 00.75-.75v-3a.75.75 0 00-.75-.75h-4.5zm.75 3V2.5h3V4h-3zm-2.874-.467a.75.75 0 00-.752-1.298A1.75 1.75 0 002 3.75v9.5c0 .966.784 1.75 1.75 1.75h8.5A1.75 1.75 0 0014 13.25v-9.5a1.75 1.75 0 00-.874-1.515.75.75 0 10-.752 1.298.25.25 0 01.126.217v9.5a.25.25 0 01-.25.25h-8.5a.25.25 0 01-.25-.25v-9.5a.25.25 0 01.126-.217z"></path></svg>
|
||||
<span>Copy</span>
|
||||
</button>
|
||||
</div>
|
||||
<textarea spellcheck="false" autocorrect="off" autocapitalize="off"></textarea>
|
||||
<div class="source-controls-more" id="source-controls-menu">
|
||||
<button class="btn" id="source-controls-download">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.47 10.78a.75.75 0 001.06 0l3.75-3.75a.75.75 0 00-1.06-1.06L8.75 8.44V1.75a.75.75 0 00-1.5 0v6.69L4.78 5.97a.75.75 0 00-1.06 1.06l3.75 3.75zM3.75 13a.75.75 0 000 1.5h8.5a.75.75 0 000-1.5h-8.5z"></path></svg>
|
||||
<span>Download</span>
|
||||
<a id="source-controls-download-anchor" style="display:none;"></a>
|
||||
</button>
|
||||
<button class="btn" id="source-controls-share">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg>
|
||||
<span>Share</span>
|
||||
</button>
|
||||
</div>
|
||||
<textarea id="source-view-output" spellcheck="false" autocorrect="off" autocapitalize="off"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -30,8 +30,8 @@
|
||||
|
||||
.source textarea {
|
||||
width: 100%;
|
||||
height: calc(100vh - 56px - 30px - 13px);
|
||||
padding: 0.4rem;
|
||||
height: calc(100vh - 56px);
|
||||
padding: 1.3rem 0.4rem;
|
||||
border: none;
|
||||
white-space: pre;
|
||||
overflow-wrap: normal;
|
||||
@@ -48,9 +48,31 @@
|
||||
}
|
||||
|
||||
.source-controls {
|
||||
padding: 0.4rem;
|
||||
display: flex;
|
||||
flex-direction: row-reverse;
|
||||
position: absolute;
|
||||
right: 17px;
|
||||
top: 56px;
|
||||
padding: 5px;
|
||||
}
|
||||
|
||||
.source-controls .btn:not(:first-child) {
|
||||
margin-right: 5px;
|
||||
}
|
||||
|
||||
.source-controls-more {
|
||||
display: flex;
|
||||
visibility: hidden;
|
||||
flex-direction: column;
|
||||
position: absolute;
|
||||
right: 17px;
|
||||
top: 91px;
|
||||
padding: 5px;
|
||||
}
|
||||
|
||||
.source-controls .btn,
|
||||
.source-controls-more .btn {
|
||||
background: #1f2020a6;
|
||||
}
|
||||
|
||||
.gutter.gutter-horizontal {
|
||||
@@ -59,34 +81,28 @@
|
||||
cursor: ew-resize;
|
||||
}
|
||||
|
||||
|
||||
.btn {
|
||||
display: inline;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
border: none;
|
||||
color: #ffffff;
|
||||
background: #5c615f;
|
||||
padding: 7px 20px;
|
||||
fill: #ffffff;
|
||||
background-color: #1f2020a6;
|
||||
padding: 7px 11px;
|
||||
cursor: pointer;
|
||||
outline: none;
|
||||
transition: background-color 0.2s;
|
||||
}
|
||||
|
||||
.btn.check {
|
||||
fill: #97fa55;
|
||||
color: #97fa55;
|
||||
}
|
||||
|
||||
.btn svg:not(:last-child) {
|
||||
margin-right: 5px;
|
||||
}
|
||||
|
||||
.btn:hover {
|
||||
background: #787c7b;
|
||||
}
|
||||
|
||||
.dropdown {
|
||||
display: inline;
|
||||
border: none;
|
||||
color: #ffffff;
|
||||
background: #5c615f;
|
||||
padding: 7px 7px;
|
||||
cursor: pointer;
|
||||
outline: none;
|
||||
font-size: 1rem;
|
||||
transition: background-color 0.2s;
|
||||
}
|
||||
|
||||
.dropdown:hover {
|
||||
background: #787c7b;
|
||||
background-color: #5d5f5fa6;
|
||||
}
|
||||
|
||||
@@ -23,8 +23,9 @@ const models: {
|
||||
|
||||
let model = models["loot-table"]
|
||||
|
||||
let treeViewEl = document.getElementById('tree-view')!
|
||||
let sourceviewEl = document.getElementById('source-view')!
|
||||
const treeViewEl = document.getElementById('tree-view')!
|
||||
const sourceviewEl = document.getElementById('source-view')!
|
||||
const sourceviewOut = document.getElementById('source-view-output')!
|
||||
Split([treeViewEl, sourceviewEl], {
|
||||
sizes: [66, 34]
|
||||
})
|
||||
@@ -45,6 +46,42 @@ modelSelector.addEventListener('change', evt => {
|
||||
model.invalidate()
|
||||
})
|
||||
|
||||
const sourceControlsToggle = document.getElementById('source-controls-toggle')!
|
||||
const sourceControlsMenu = document.getElementById('source-controls-menu')!
|
||||
sourceControlsToggle.addEventListener('click', evt => {
|
||||
sourceControlsMenu.style.visibility = 'visible'
|
||||
|
||||
document.body.addEventListener('click', evt => {
|
||||
sourceControlsMenu.style.visibility = 'hidden'
|
||||
}, { capture: true, once: true })
|
||||
})
|
||||
|
||||
const sourceControlsCopy = document.getElementById('source-controls-copy')!
|
||||
const sourceControlsDownload = document.getElementById('source-controls-download')!
|
||||
const sourceControlsShare = document.getElementById('source-controls-share')!
|
||||
|
||||
const addChecked = (el: HTMLElement) => {
|
||||
el.classList.add('check')
|
||||
setTimeout(() => {
|
||||
el.classList.remove('check')
|
||||
}, 2000)
|
||||
}
|
||||
|
||||
sourceControlsCopy.addEventListener('click', evt => {
|
||||
(sourceviewOut as HTMLTextAreaElement).select()
|
||||
document.execCommand('copy');
|
||||
addChecked(sourceControlsCopy)
|
||||
})
|
||||
|
||||
sourceControlsDownload.addEventListener('click', evt => {
|
||||
const fileContents = encodeURIComponent(JSON.stringify(model.data, null, 2) + "\n")
|
||||
const dataString = "data:text/json;charset=utf-8," + fileContents
|
||||
const downloadAnchor = document.getElementById('source-controls-download-anchor')!
|
||||
downloadAnchor.setAttribute("href", dataString)
|
||||
downloadAnchor.setAttribute("download", "data.json")
|
||||
downloadAnchor.click()
|
||||
})
|
||||
|
||||
setTimeout(() => {
|
||||
window.scroll(0, 0)
|
||||
}, 1000)
|
||||
|
||||
Reference in New Issue
Block a user