Brief schreiben.html 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <section class="container">
  2. <div class="editor no-print">
  3. <ul class="toolbar">
  4. <li><button type="button" data-command="bold">Fett</button></li>
  5. <li><button type="button" data-command="italic">Kursiv</button></li>
  6. <!-- <li><button type="button" data-command="link">Link</button></li>
  7. <li><button type="button" data-command="image">Bild</button></li> -->
  8. <li><button type="button" data-command="header1">Groß</button></li>
  9. <li><button type="button" data-command="header2">Bisschen Groß</button></li>
  10. <li><button type="button" data-command="unorderedList">Liste</button></li>
  11. <li><button type="button" data-command="orderedList">Aufzählung</button></li>
  12. <!-- <li><button type="button" data-command="code"></button></li> -->
  13. </ul>
  14. <textarea bind:value=text type=text></textarea>
  15. </div>
  16. <div id="jsonformatter" class="no-print">Unter <code>»s«</code> erreichbare Daten:</div>
  17. <div class="right-half">
  18. {#if schueler}
  19. {#each schueler as s (s.ID)}
  20. <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>
  21. {/each}
  22. {/if}
  23. </div>
  24. </section>
  25. <script>
  26. import svelte from 'svelte'
  27. import TextareaEditor from 'textarea-editor'
  28. import marked from 'marked'
  29. import JSONFormatter from 'json-formatter-js'
  30. export default {
  31. oncreate () {
  32. const {schueler} = this.get()
  33. const formatter = new JSONFormatter(schueler[0])
  34. document.querySelector('#jsonformatter').appendChild(formatter.render())
  35. const textarea = document.querySelector('textarea')
  36. const toolbar = document.querySelector('.toolbar')
  37. const editor = new TextareaEditor(textarea)
  38. toolbar.addEventListener('mousedown', e => e.preventDefault());
  39. toolbar.addEventListener('click', e => {
  40. const command = e.target.getAttribute('data-command');
  41. if (!command) return;
  42. let url;
  43. if (/image|link/.test(command) && !editor.hasFormat(command)) {
  44. url = prompt('URL:');
  45. }
  46. editor.toggle(command, url);
  47. })
  48. textarea.addEventListener('keydown', (e) => {
  49. const key = e.which;
  50. const cmd = e.metaKey || e.ctrlKey;
  51. if (!cmd) return;
  52. switch (key) {
  53. case 66:
  54. editor.toggle('bold');
  55. break;
  56. case 73:
  57. editor.toggle('italic');
  58. break;
  59. default: return;
  60. }
  61. e.preventDefault();
  62. })
  63. },
  64. data () {return {
  65. text: 'Hallo {s.Vorname}'
  66. }},
  67. computed: {
  68. Component: ({text}) => { console.log(text) ;return svelte.create(marked(text, { sanitize: false }))}
  69. },
  70. components: {Brief: './_brief.html'}
  71. }
  72. </script>
  73. <style>
  74. @import 'daten/main.css';
  75. /* Pattern styles */
  76. .container {
  77. display: grid;
  78. grid-template-columns: 1fr 2fr;
  79. grid-template-rows: 2fr 1fr;
  80. grid-gap: 10px;
  81. height: 90vh;
  82. margin-top: 10px;
  83. }
  84. .right-half {
  85. grid-column: 2;
  86. grid-row-start: 1;
  87. grid-row-end: 3;
  88. }
  89. Brief {
  90. overflow: auto;
  91. }
  92. .editor {
  93. grid-column: 1;
  94. grid-row: 1;
  95. /* position: sticky; */
  96. height: 90%;
  97. margin-left: 10px;
  98. }
  99. #jsonformatter {
  100. grid-column: 1;
  101. grid-row-start: 2;
  102. grid-row-end: 3;
  103. font-size: 10pt;
  104. margin-left: 10px;
  105. overflow: auto;
  106. }
  107. textarea {
  108. width: 100%;
  109. height: 100%;
  110. padding: 20px;
  111. border-color: #ccc;
  112. resize: none;
  113. font-size: 1.6em;
  114. }
  115. textarea:focus {
  116. outline: none;
  117. border-color: #3498db;
  118. }
  119. .toolbar {
  120. background: #ddd;
  121. list-style: none;
  122. margin: 0;
  123. padding: 0;
  124. overflow: hidden;
  125. width: 100%;
  126. }
  127. .toolbar button {
  128. float: left;
  129. font-weight: bold;
  130. background: #ddd;
  131. color: #333;
  132. border: none;
  133. padding: 15px;
  134. }
  135. .toolbar button:hover {
  136. background: #ccc;
  137. }
  138. </style>