123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 |
- <section class="container">
- <div class="editor no-print">
- <ul class="toolbar">
- <li><button type="button" data-command="bold">Fett</button></li>
- <li><button type="button" data-command="italic">Kursiv</button></li>
- <!-- <li><button type="button" data-command="link">Link</button></li>
- <li><button type="button" data-command="image">Bild</button></li> -->
- <li><button type="button" data-command="header1">Groß</button></li>
- <li><button type="button" data-command="header2">Bisschen Groß</button></li>
- <li><button type="button" data-command="unorderedList">Liste</button></li>
- <li><button type="button" data-command="orderedList">Aufzählung</button></li>
- <!-- <li><button type="button" data-command="code"></button></li> -->
- </ul>
- <textarea bind:value=text type=text></textarea>
- </div>
- <div id="jsonformatter" class="no-print">Unter <code>»s«</code> erreichbare Daten:</div>
- <div class="right-half">
- {#if schueler}
- {#each schueler as s (s.ID)}
- <Brief schueler={schueler}><span slot="kuerzel">{s.Lehrer}</span><span slot="anschrift">{s.Vorname} {s.Name}<br>{s.Strasse}<br>{s.PLZ} {s.OrtAbk}</span><svelte:component this={Component} s={s} /></Brief>
- {/each}
- {/if}
- </div>
- </section>
- <script>
- import svelte from 'svelte'
- import TextareaEditor from 'textarea-editor'
- import marked from 'marked'
- import JSONFormatter from 'json-formatter-js'
- export default {
- oncreate () {
- const {schueler} = this.get()
- const formatter = new JSONFormatter(schueler[0])
- document.querySelector('#jsonformatter').appendChild(formatter.render())
- const textarea = document.querySelector('textarea')
- const toolbar = document.querySelector('.toolbar')
- const editor = new TextareaEditor(textarea)
- toolbar.addEventListener('mousedown', e => e.preventDefault());
- toolbar.addEventListener('click', e => {
- const command = e.target.getAttribute('data-command');
- if (!command) return;
- let url;
- if (/image|link/.test(command) && !editor.hasFormat(command)) {
- url = prompt('URL:');
- }
- editor.toggle(command, url);
- })
- textarea.addEventListener('keydown', (e) => {
- const key = e.which;
- const cmd = e.metaKey || e.ctrlKey;
- if (!cmd) return;
- switch (key) {
- case 66:
- editor.toggle('bold');
- break;
- case 73:
- editor.toggle('italic');
- break;
- default: return;
- }
- e.preventDefault();
- })
- },
- data () {return {
- text: 'Hallo {s.Vorname}'
- }},
- computed: {
- Component: ({text}) => { console.log(text) ;return svelte.create(marked(text, { sanitize: false }))}
- },
- components: {Brief: './_brief.html'}
- }
- </script>
- <style>
- @import 'daten/main.css';
- /* Pattern styles */
- .container {
- display: grid;
- grid-template-columns: 1fr 2fr;
- grid-template-rows: 2fr 1fr;
- grid-gap: 10px;
- height: 90vh;
- margin-top: 10px;
- }
- .right-half {
- grid-column: 2;
- grid-row-start: 1;
- grid-row-end: 3;
- }
- Brief {
- overflow: auto;
- }
- .editor {
- grid-column: 1;
- grid-row: 1;
- /* position: sticky; */
- height: 90%;
- margin-left: 10px;
- }
- #jsonformatter {
- grid-column: 1;
- grid-row-start: 2;
- grid-row-end: 3;
- font-size: 10pt;
- margin-left: 10px;
- overflow: auto;
- }
- textarea {
- width: 100%;
- height: 100%;
- padding: 20px;
- border-color: #ccc;
- resize: none;
- font-size: 1.6em;
- }
- textarea:focus {
- outline: none;
- border-color: #3498db;
- }
- .toolbar {
- background: #ddd;
- list-style: none;
- margin: 0;
- padding: 0;
- overflow: hidden;
- width: 100%;
- }
- .toolbar button {
- float: left;
- font-weight: bold;
- background: #ddd;
- color: #333;
- border: none;
- padding: 15px;
- }
- .toolbar button:hover {
- background: #ccc;
- }
- </style>
|