design.tmpl 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. {{showFile "templates/design/sections/head.tmpl"}}
  2. <body class="bg-zinc-950 text-zinc-200 h-screen overflow-hidden flex">
  3. {{/* DELETE CONFIRMATION MODAL */}}
  4. <div id="delete-modal" class="fixed inset-0 z-50 flex items-center justify-center hidden">
  5. {{/* Backdrop */}}
  6. <div class="absolute inset-0 bg-black/60 backdrop-blur-sm" onclick="hideDeleteModal()"></div>
  7. {{/* Modal box */}}
  8. <div class="relative z-10 bg-zinc-900 border border-zinc-700 rounded-lg shadow-2xl w-80 p-5 flex flex-col gap-4">
  9. <div class="flex items-start gap-3">
  10. {{/* Warning icon */}}
  11. <div class="shrink-0 text-red-400 mt-0.5">
  12. <svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24"
  13. fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
  14. <path d="M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"/>
  15. <line x1="12" y1="9" x2="12" y2="13"/>
  16. <line x1="12" y1="17" x2="12.01" y2="17"/>
  17. </svg>
  18. </div>
  19. <div>
  20. <p class="text-sm font-medium text-zinc-100">Confirm Delete</p>
  21. <p id="delete-modal-message" class="text-xs text-zinc-400 mt-1"></p>
  22. </div>
  23. </div>
  24. <div class="flex justify-end gap-2">
  25. <button onclick="hideDeleteModal()"
  26. class="px-3 py-1.5 text-xs rounded border border-zinc-700 text-zinc-400 hover:text-zinc-100 hover:bg-zinc-800 transition-colors">
  27. Cancel
  28. </button>
  29. <button id="delete-modal-confirm"
  30. class="px-3 py-1.5 text-xs rounded bg-red-500/20 border border-red-500/50 text-red-400 hover:bg-red-500/30 hover:text-red-300 transition-colors">
  31. Delete
  32. </button>
  33. </div>
  34. </div>
  35. </div>
  36. {{showFile "templates/design/sections/nav_small.tmpl"}}
  37. {{template "nav_big.tmpl" .Folders}}
  38. <main class="flex-1 flex flex-col relative bg-zinc-900/20 overflow-auto">
  39. {{showFile "templates/design/sections/nav_header.tmpl"}}
  40. <div class="flex-1 flex">
  41. <section class="flex-1 overflow-y-auto custom-scrollbar p-12">
  42. {{if .Notepath}}
  43. {{/* NOTE ACTION BAR */}}
  44. <div class="w-full mb-4 flex items-center justify-between gap-4 border border-zinc-700 bg-zinc-900/40 px-4 py-3">
  45. <div class="min-w-0">
  46. <p class="text-xs uppercase tracking-widest text-zinc-500">Opened Note</p>
  47. <p class="text-sm text-zinc-200 truncate">{{.Notepath}}</p>
  48. </div>
  49. <div class="flex items-center gap-2 shrink-0">
  50. <form id="save-note-form" method="POST" action="/api/update_note">
  51. <input type="hidden" name="path" value="{{.Notepath}}">
  52. <textarea id="hidden-note-content" name="notita" class="hidden"></textarea>
  53. <button type="submit"
  54. class="inline-flex items-center gap-2 px-4 py-2 text-sm font-medium rounded border border-emerald-500/40 bg-emerald-500/10 text-emerald-400 hover:bg-emerald-500/20 hover:text-emerald-300 transition-colors">
  55. <svg xmlns="http://www.w3.org/2000/svg" width="15" height="15" viewBox="0 0 24 24"
  56. fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
  57. <path d="M19 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11l5 5v11a2 2 0 0 1-2 2z"/>
  58. <polyline points="17 21 17 13 7 13 7 21"/>
  59. <polyline points="7 3 7 8 15 8"/>
  60. </svg>
  61. Save Note
  62. </button>
  63. </form>
  64. </div>
  65. </div>
  66. {{/* Editor + Preview */}}
  67. <div class="w-full grid grid-cols-2 gap-0 border border-zinc-700">
  68. <div class="h-[85vh] bg-[#446454]">
  69. <textarea
  70. id="editor"
  71. placeholder="Start typing..."
  72. class="p-6 w-full h-full bg-transparent text-zinc-100 text-[14px] focus:outline-none resize-none custom-scrollbar"
  73. >{{.Continut}}</textarea>
  74. </div>
  75. <div id="preview" class="border-r border-zinc-700 h-[85vh] bg-[#454644] p-2 text-zinc-100 overflow-y-auto font-sans prose prose-invert prose-zinc max-w-none
  76. /* --- Code Blocks (Pre) --- */
  77. [&_pre]:bg-zinc-900/80 [&_pre]:p-4 [&_pre]:rounded-lg [&_pre]:border [&_pre]:border-zinc-700
  78. [&_pre]:my-6 [&_pre]:overflow-x-auto [&_pre]:shadow-inner
  79. /* --- Inline Code (<code>) --- */
  80. [&_code]:font-mono [&_code]:text-indigo-300 [&_code]:bg-zinc-800/50
  81. [&_code]:px-1.5 [&_code]:py-0.5 [&_code]:rounded [&_code]:text-[0.9em]
  82. /* Evităm background-ul dublu când codul este în interiorul unui <pre> */
  83. [&_pre_code]:bg-transparent [&_pre_code]:p-0 [&_pre_code]:text-zinc-200 [&_pre_code]:text-[0.85em]
  84. /* --- Stiluri Blockquote --- */
  85. [&_blockquote]:border-l-4 [&_blockquote]:border-indigo-500 [&_blockquote]:bg-zinc-800/30
  86. [&_blockquote]:py-2 [&_blockquote]:px-5 [&_blockquote]:my-4 [&_blockquote]:italic [&_blockquote]:text-zinc-300
  87. /* --- Stiluri Bold & Italic --- */
  88. [&_strong]:text-white [&_strong]:font-bold
  89. [&_em]:text-indigo-200 [&_em]:italic
  90. /* --- Stiluri pentru Tabele --- */
  91. [&_table]:w-full [&_table]:my-6 [&_table]:border-collapse [&_table]:border [&_table]:border-zinc-600
  92. [&_thead]:bg-zinc-800/50
  93. [&_th]:border [&_th]:border-zinc-600 [&_th]:p-3 [&_th]:text-left [&_th]:text-indigo-300 [&_th]:uppercase [&_th]:text-[11px]
  94. [&_td]:border [&_td]:border-zinc-600 [&_td]:p-3 [&_td]:text-sm
  95. [&_tr:nth-child(even)]:bg-zinc-700/30
  96. /* --- Stiluri pentru Liste & Headings --- */
  97. [&_ul]:list-disc [&_ul]:ml-6 [&_ol]:list-decimal [&_ol]:ml-6
  98. [&_h1]:text-3xl [&_h1]:font-bold [&_h1]:border-b [&_h1]:border-zinc-600 [&_h1]:pb-2 [&_h1]:mb-4
  99. [&_h2]:text-xl [&_h2]:font-semibold [&_h2]:text-indigo-400 [&_h2]:mt-6 custom-scrollbar">
  100. Your preview will appear here...
  101. </div>
  102. </div>
  103. {{else}}
  104. {{/* EMPTY STATE */}}
  105. <div class="flex-1 flex flex-col items-center justify-center gap-4 text-center h-[85vh]">
  106. <svg xmlns="http://www.w3.org/2000/svg" width="48" height="48" viewBox="0 0 24 24"
  107. fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round"
  108. class="text-zinc-700">
  109. <path d="M14.5 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7.5L14.5 2z"/>
  110. <polyline points="14 2 14 8 20 8"/>
  111. </svg>
  112. <p class="text-zinc-600 text-sm">No note open</p>
  113. <p class="text-zinc-700 text-xs">Select a file from the navigator or create a new one</p>
  114. </div>
  115. {{end}}
  116. </section>
  117. </div>
  118. </main>
  119. <script>
  120. const editor = document.getElementById('editor');
  121. const preview = document.getElementById('preview');
  122. const saveForm = document.getElementById('save-note-form');
  123. const hiddenNoteContent = document.getElementById('hidden-note-content');
  124. if (editor && preview){
  125. // Debounce helper
  126. function debounce(func, delay) {
  127. let timeout;
  128. return function(...args) {
  129. clearTimeout(timeout);
  130. timeout = setTimeout(() => func.apply(this, args), delay);
  131. };
  132. }
  133. // The API Call
  134. const updatePreview = async () => {
  135. const content = editor.value;
  136. try {
  137. const response = await fetch('/live_preview/', {
  138. method: 'POST',
  139. headers: { 'Content-Type': 'application/json' },
  140. body: JSON.stringify({ markdown: content })
  141. });
  142. if (response.ok) {
  143. const htmlResult = await response.text();
  144. preview.innerHTML = htmlResult;
  145. preview.querySelectorAll('pre code').forEach((codeBlock) => {
  146. const pre = codeBlock.parentElement;
  147. const langClass = Array.from(codeBlock.classList).find(c => c.startsWith('language-'));
  148. if (langClass) {
  149. pre.setAttribute('data-language', langClass.replace('language-', ''));
  150. }
  151. hljs.highlightElement(codeBlock);
  152. });
  153. console.log("Remote Preview & Highlighting Updated!");
  154. }
  155. } catch (error) {
  156. console.error("Error:", error);
  157. }
  158. };
  159. // Listen for input
  160. editor.addEventListener('input', debounce(updatePreview, 100));
  161. // sync editor content into hidden form field before save
  162. if (saveForm && hiddenNoteContent) {
  163. saveForm.addEventListener('submit', function () {
  164. hiddenNoteContent.value = editor.value;
  165. });
  166. }
  167. // initial preview
  168. if (editor.value.trim() !== '') {
  169. updatePreview();
  170. }
  171. }
  172. </script>
  173. </body>
  174. </html>