Better CSS for the JSON editor

This commit is contained in:
Magnus Åhall 2025-07-07 08:52:37 +02:00
parent 25bbc0c748
commit 4e834766ac
8 changed files with 271 additions and 9 deletions

BIN
datagraph

Binary file not shown.

106
static/css/json_editor.css Normal file
View file

@ -0,0 +1,106 @@
.je-indented-panel {
background-color: #f8f9fa;
border: 1px solid rgba(0, 0, 0, 0.125);
border-radius: var(--border-radius);
padding: 16px;
margin-left: 0px;
margin-top: 16px;
margin-bottom: 16px;
width: min-content;
}
.je-indented-panel .row {
margin-top: 16px;
}
.je-indented-panel .row:first-child {
margin-top: 0px;
}
.je-header {
color: var(--je-color);
font-weight: bold;
}
.je-object__controls > .je-modal {
width: 50%;
}
.je-object__controls > .je-modal .je-textarea {
font-family: "Roboto Mono", monospace;
font-size: 0.85em;
height: 500px;
}
.je-object__controls > .je-modal button {
margin: 8px 0px 8px 8px;
}
.form-control > label {
display: block;
color: var(--je-color);
margin-bottom: 4px;
}
[data-schematype="array"] button {
margin-right: 8px;
}
table {
margin-bottom: 8px;
}
table th {
text-align: left;
font-size: var(--textsize);
}
table td * {
white-space: nowrap;
}
input,
textarea {
color: #495057;
padding: 8px 8px;
background-color: #fff;
border-radius: var(--border-radius);
border: 1px solid #ced4da;
font-family: "Roboto", sans-serif;
font-optical-sizing: auto;
font-weight: 400;
font-style: normal;
font-size: var(--textsize);
}
textarea {
min-width: 400px;
}
.json-editor-btntype-delete {
border: none;
background-color: inherit;
cursor: pointer;
margin-top: 4px;
padding: 0px;
}
.json-editor-btntype-delete > span {
display: none;
}
.json-editor-btntype-delete::after {
display: block;
content: "";
width: 24px;
height: 24px;
}
.json-editor-btntype-delete::after {
background: url(/images/v0/node_modules/@mdi/svg/svg/trash-can.svg);
}
.json-editor-btntype-move {
border: none;
background-color: inherit;
cursor: pointer;
margin-top: 4px;
padding: 0px;
}
.json-editor-btntype-move > span {
display: none;
}
.json-editor-btntype-move::after {
display: block;
content: "";
width: 24px;
height: 24px;
}
.json-editor-btntype-move.moveup::after {
background: url(/images/v0/node_modules/@mdi/svg/svg/arrow-up-bold.svg);
}
.json-editor-btntype-move.movedown::after {
background: url(/images/v0/node_modules/@mdi/svg/svg/arrow-down-bold.svg);
}

View file

@ -1,9 +1,17 @@
:root {
--textsize: 12pt;
--je-color: #73a44d;
--border-radius: 5px;
}
html {
box-sizing: border-box;
font-family: sans-serif;
font-size: 14pt;
margin: 0px;
padding: 0px;
font-family: "Roboto", sans-serif;
font-optical-sizing: auto;
font-weight: 400;
font-style: normal;
font-size: var(--textsize);
}
body {
margin: 0px;

View file

@ -6,8 +6,9 @@ export class Editor {
render(data) {
const options = {
theme: 'spectre',
iconlib: 'spectre',
//theme: 'spectre',
//iconlib: 'spectre',
theme: 'barebones',
disable_collapse: true,
disable_properties: true,
schema: this.schema,
@ -22,7 +23,6 @@ export class Editor {
const div = document.createElement('div')
this.editor = new JSONEditor(div, options);
// this.editor.on('ready', ()=>{
// })
div.addEventListener('keydown', event=>this.keyHandler(event))

View file

@ -0,0 +1,128 @@
.je-indented-panel {
background-color: #f8f9fa;
border: 1px solid rgba(0,0,0,.125);
border-radius: var(--border-radius);
padding: 16px;
margin-left: 0px;
margin-top: 16px;
margin-bottom: 16px;
width: min-content;
.row {
margin-top: 16px;
&:first-child {
margin-top: 0px;
}
}
}
.je-header {
color: var(--je-color);
font-weight: bold;
}
.je-object__controls {
& > .je-modal {
width: 50%;
.je-textarea {
font-family: "Roboto Mono", monospace;
font-size: 0.85em;
height: 500px;
}
button {
margin: 8px 0px 8px 8px;
}
}
}
.form-control {
& > label {
display: block;
color: var(--je-color);
margin-bottom: 4px;
}
}
[data-schematype="array"] {
button {
margin-right: 8px;
}
}
table {
margin-bottom: 8px;
th {
text-align: left;
font-size: var(--textsize);
}
td {
* {
white-space: nowrap;
}
}
}
input, textarea {
color: #495057;
padding: 8px 8px;
background-color: #fff;
border-radius: var(--border-radius);
border: 1px solid #ced4da;
font-family: "Roboto", sans-serif;
font-optical-sizing: auto;
font-weight: 400;
font-style: normal;
font-size: var(--textsize);
}
textarea {
min-width: 400px;
}
.datagraph-button() {
border: none;
background-color: inherit;
cursor: pointer;
margin-top: 4px;
padding: 0px;
& > span {
display: none;
}
&::after {
display: block;
content: "";
width: 24px;
height: 24px;
}
}
// json-editor-btn-delete
// delete
.json-editor-btntype-delete {
.datagraph-button();
&::after {
background: url(/images/v0/node_modules/@mdi/svg/svg/trash-can.svg);
}
}
// json-editor-btn-movedown
// movedown
.json-editor-btntype-move {
.datagraph-button();
&.moveup::after {
background: url(/images/v0/node_modules/@mdi/svg/svg/arrow-up-bold.svg);
}
&.movedown::after {
background: url(/images/v0/node_modules/@mdi/svg/svg/arrow-down-bold.svg);
}
}

View file

@ -1,9 +1,20 @@
:root {
--textsize: 12pt;
--je-color: #73a44d;
--border-radius: 5px;
}
html {
box-sizing: border-box;
font-family: sans-serif;
font-size: 14pt;
margin: 0px;
padding: 0px;
font-family: "Roboto", sans-serif;
font-optical-sizing: auto;
font-weight: 400;
font-style: normal;
font-size: var(--textsize);
}
body {

View file

@ -3,6 +3,11 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Roboto+Mono:ital,wght@0,100..700;1,100..700&family=Roboto:ital,wght@0,100..900;1,100..900&display=swap" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="/css/{{ .VERSION }}/main.css">
<script type="text/javascript">
function showError(err) {

View file

@ -1,4 +1,6 @@
{{ define "page" }}
<link rel="stylesheet" type="text/css" href="/css/{{ .VERSION }}/json_editor.css">
<script type="importmap">
{
"imports": {
@ -8,8 +10,8 @@
}
</script>
<script src="/js/{{ .VERSION }}/lib/jsoneditor.js"></script>
<!--<script src="https://cdn.jsdelivr.net/npm/@json-editor/json-editor@latest/dist/jsoneditor.min.js"></script>-->
<!--script src="/js/{{ .VERSION }}/lib/jsoneditor.js"></script-->
<script src="https://cdn.jsdelivr.net/npm/@json-editor/json-editor@latest/dist/jsoneditor.min.js"></script>
<script type="module" defer>
import {App, TreeNode} from '/js/{{ .VERSION }}/app.mjs'
window._VERSION = '{{ .VERSION }}'
@ -50,8 +52,10 @@
<div class="page section" id="editor-type-schema"></div>
</div>
<!--
<link rel="stylesheet" href="/css/{{ .VERSION }}/spectre.min.css">
<link rel="stylesheet" href="/css/{{ .VERSION }}/spectre-exp.min.css">
<link rel="stylesheet" href="/css/{{ .VERSION }}/spectre-icons.min.css">
-->
{{ end }}