Aichatbot12321 commited on
Commit
cb97ec5
·
verified ·
1 Parent(s): 27da15f

Update runhtml.html

Browse files
Files changed (1) hide show
  1. runhtml.html +79 -25
runhtml.html CHANGED
@@ -133,7 +133,7 @@ svg{width:20px; height:20px; display:block;}
133
  .rh-tmpl-chip{flex-shrink:0; padding:10px 16px; border-radius:12px; background:var(--rh-surface); border:1px solid var(--rh-border); font-size:12.5px; font-weight:700; white-space:nowrap; transition:.2s;}
134
  .rh-tmpl-chip:hover{border-color:var(--rh-primary); color:var(--rh-primary); transform:translateY(-2px);}
135
 
136
- /* ===== TOP BAR (create/history) ===== */
137
  .rh-topbar{display:flex; align-items:center; gap:10px; padding:14px 16px; background:var(--rh-surface); border-bottom:1px solid var(--rh-border); flex-shrink:0; box-shadow:0 4px 14px rgba(0,0,0,.04); z-index:20;}
138
  .rh-filename{flex:1; min-width:0; background:transparent; border:none; font-size:15px; font-weight:800; color:var(--rh-text); padding:6px 8px; border-radius:8px; outline:none;}
139
  .rh-filename:focus{background:var(--rh-input);}
@@ -165,6 +165,25 @@ svg{width:20px; height:20px; display:block;}
165
  .CodeMirror{height:100% !important; font-family:'JetBrains Mono', monospace !important; font-size:13px; line-height:1.6;}
166
  .rh-plain-fallback{width:100%; height:100%; background:var(--rh-code-bg); color:#e2e8f0; border:none; outline:none; resize:none; padding:14px; font-family:'JetBrains Mono',monospace; font-size:13px; line-height:1.6;}
167
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
168
  /* ===== PREVIEW ===== */
169
  .rh-preview-pane{flex:1; min-height:0; display:none; flex-direction:column; background:var(--rh-bg);}
170
  .rh-preview-pane.active{display:flex;}
@@ -320,14 +339,13 @@ textarea.rh-input{resize:vertical; min-height:90px; line-height:1.5;}
320
  .rh-confirm-actions{display:flex; gap:10px; margin-top:18px;}
321
  .rh-confirm-actions .rh-btn{flex:1;}
322
 
323
- /* Search dialog (CodeMirror) restyle */
324
- .CodeMirror-dialog{background:var(--rh-surface) !important; color:var(--rh-text) !important; padding:8px 12px !important;}
325
- .CodeMirror-dialog input{background:var(--rh-input); color:var(--rh-text); border:1px solid var(--rh-border); border-radius:8px; padding:5px 8px;}
326
-
327
  @media (min-width:760px){
328
  .rh-sheet{max-width:640px;}
329
  .rh-overlay:not(.center) .rh-sheet{margin-bottom:20px; border-radius:22px;}
330
  }
 
 
 
331
  </style>
332
  </head>
333
  <body>
@@ -399,6 +417,8 @@ textarea.rh-input{resize:vertical; min-height:90px; line-height:1.5;}
399
 
400
  <!-- CODE TAB -->
401
  <div class="rh-toolrow" id="codeToolbar">
 
 
402
  <button class="rh-icon-btn" id="btnGenerate" title="Generate with AI"></button>
403
  <div class="rh-divider"></div>
404
  <button class="rh-icon-btn" id="btnUndo" title="Undo"></button>
@@ -424,6 +444,7 @@ textarea.rh-input{resize:vertical; min-height:90px; line-height:1.5;}
424
  <span id="autosaveTxt">—</span>
425
  </div>
426
  <div class="rh-editor-wrap" id="tabpane-code">
 
427
  <textarea id="codeArea" spellcheck="false"></textarea>
428
  </div>
429
 
@@ -621,12 +642,6 @@ textarea.rh-input{resize:vertical; min-height:90px; line-height:1.5;}
621
  <div id="toastStack"></div>
622
  </div>
623
 
624
- <style>
625
- .menu-row{display:flex; align-items:center; gap:12px; width:100%; padding:13px 10px; border-radius:12px; font-size:14px; font-weight:700; text-align:left; transition:.15s;}
626
- .menu-row:hover{background:var(--rh-input);}
627
- .menu-row svg{width:18px;height:18px; color:var(--rh-primary);}
628
- </style>
629
-
630
  <script>
631
  'use strict';
632
  /* =========================================================================
@@ -680,7 +695,9 @@ const ICONS = {
680
  list: svg('<line x1="9" y1="6" x2="20" y2="6"/><line x1="9" y1="12" x2="20" y2="12"/><line x1="9" y1="18" x2="20" y2="18"/><circle cx="4.5" cy="6" r="1"/><circle cx="4.5" cy="12" r="1"/><circle cx="4.5" cy="18" r="1"/>'),
681
  timer: svg('<circle cx="12" cy="13" r="8"/><line x1="12" y1="9" x2="12" y2="13"/><line x1="9" y1="3" x2="15" y2="3"/>'),
682
  layers: svg('<polygon points="12 2 22 8.5 12 15 2 8.5 12 2"/><polyline points="2 15.5 12 22 22 15.5"/>'),
683
- empty: svg('<path d="M21 8v10a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h5"/><path d="M16 2l6 6M22 2l-6 6"/>')
 
 
684
  };
685
  function setIc(id, key, cls){ const el = document.getElementById(id); if(el) el.innerHTML = ICONS[key] || ''; if(cls) el.classList.add(cls); }
686
 
@@ -914,7 +931,16 @@ function goView(name){
914
  state.view = name;
915
  if(name === 'home') renderHome();
916
  if(name === 'history') renderHistory();
917
- if(name === 'create'){ setTimeout(()=>{ if(cm) cm.refresh(); fitDeviceFrame(); }, 50); }
 
 
 
 
 
 
 
 
 
918
  }
919
 
920
  /* ---------- Sheets / modals ---------- */
@@ -928,13 +954,12 @@ document.querySelectorAll('.rh-overlay').forEach(ov=>{
928
  function initEditor(){
929
  const ta = document.getElementById('codeArea');
930
  if(window.CodeMirror){
931
- // Clear value before initializing to prevent double rendering/locking blocks
932
- ta.value = "";
933
  cm = CodeMirror.fromTextArea(ta, {
934
  mode:'htmlmixed', theme:'dracula', lineNumbers:true, lineWrapping:true,
935
  matchBrackets:true, autoCloseBrackets:true, autoCloseTags:true,
936
  tabSize:2, indentUnit:2, styleActiveLine:true,
937
- readOnly: false, // Explicitly forces the editor area to be writable
938
  extraKeys:{
939
  'Ctrl-S': ()=>{ handleSaveClick(); },
940
  'Cmd-S': ()=>{ handleSaveClick(); },
@@ -947,8 +972,7 @@ function initEditor(){
947
  }
948
  });
949
  cm.setValue(TEMPLATES.blank.code);
950
- // Clear history immediately so backspace/delete keys register correctly from ground zero
951
- cm.clearHistory();
952
  cm.on('change', onEditorChange);
953
  cm.on('cursorActivity', updateUndoRedoButtons);
954
  } else {
@@ -1071,9 +1095,6 @@ function appendConsoleLine(level, text){
1071
  line.appendChild(tag); line.appendChild(msg);
1072
  body.appendChild(line);
1073
  body.scrollTop = body.scrollHeight;
1074
- if(!document.getElementById('consoleDrawer').classList.contains('open') && level === 'error'){
1075
- // subtle nudge — badge dot could go here; keep silent to avoid noise
1076
- }
1077
  }
1078
  function clearConsole(){
1079
  document.getElementById('consoleBody').innerHTML = '<div class="rh-console-empty">No output yet — hit Run to see logs &amp; errors here.</div>';
@@ -1175,7 +1196,8 @@ function switchTab(tab){
1175
  document.getElementById('tabpane-code').style.display = tab==='code' ? 'block' : 'none';
1176
  document.getElementById('tabpane-preview').classList.toggle('active', tab==='preview');
1177
  if(tab==='preview') setTimeout(fitDeviceFrame, 30);
1178
- if(tab==='code' && cm) setTimeout(()=> cm.refresh(), 30);
 
1179
  }
1180
 
1181
  /* ---------- Beautify ---------- */
@@ -1198,14 +1220,30 @@ async function callAI(userPrompt, systemPrompt, isCode){
1198
  headers:{ 'Content-Type':'application/json' },
1199
  body: JSON.stringify({ userPrompt, systemPrompt: systemPrompt||'', isCode: !!isCode, providerOverride:'auto' })
1200
  });
1201
- if(!res.ok){ let msg = 'AI request failed'; try{ const j = await res.json(); msg = j.error || msg; }catch(e){} throw new Error(msg); }
 
 
 
 
1202
  const data = await res.json();
1203
- return data.text || '';
 
 
1204
  }
 
1205
  function extractCode(text){
1206
  if(!text) return '';
1207
- const fence = text.match(/```(?:html|HTML)?\s*([\s\S]*?)```/);
 
 
1208
  if(fence) return fence[1].trim();
 
 
 
 
 
 
 
1209
  return text.trim();
1210
  }
1211
 
@@ -1599,6 +1637,11 @@ function wireIcons(){
1599
  setIc('btnBackHome','back'); setIc('btnBackHome2','back'); setIc('btnMoreMenu','more');
1600
  setIc('tabCode','file'); document.getElementById('tabCode').innerHTML = ICONS.file + '<span>Code</span>';
1601
  setIc('tabPreview','smartphone'); document.getElementById('tabPreview').innerHTML = ICONS.smartphone + '<span>Preview</span>';
 
 
 
 
 
1602
  setIc('btnGenerate','sparkles'); setIc('btnUndo','undo'); setIc('btnRedo','redo');
1603
  setIc('btnFind','search'); setIc('btnBeautify','wand'); setIc('btnTemplates','layout');
1604
  setIc('btnImport','fileImport'); setIc('btnCopyCode','copy'); setIc('btnClearCode','trash');
@@ -1659,6 +1702,17 @@ function wireEvents(){
1659
  document.getElementById('tabCode').onclick = ()=> switchTab('code');
1660
  document.getElementById('tabPreview').onclick = ()=> switchTab('preview');
1661
 
 
 
 
 
 
 
 
 
 
 
 
1662
  document.getElementById('btnGenerate').onclick = openGenerateModal;
1663
  document.getElementById('closeGenerate').onclick = ()=> closeSheet('ovGenerate');
1664
  document.getElementById('btnDoGenerate').onclick = doGenerate;
 
133
  .rh-tmpl-chip{flex-shrink:0; padding:10px 16px; border-radius:12px; background:var(--rh-surface); border:1px solid var(--rh-border); font-size:12.5px; font-weight:700; white-space:nowrap; transition:.2s;}
134
  .rh-tmpl-chip:hover{border-color:var(--rh-primary); color:var(--rh-primary); transform:translateY(-2px);}
135
 
136
+ /* ===== TOP BAR ===== */
137
  .rh-topbar{display:flex; align-items:center; gap:10px; padding:14px 16px; background:var(--rh-surface); border-bottom:1px solid var(--rh-border); flex-shrink:0; box-shadow:0 4px 14px rgba(0,0,0,.04); z-index:20;}
138
  .rh-filename{flex:1; min-width:0; background:transparent; border:none; font-size:15px; font-weight:800; color:var(--rh-text); padding:6px 8px; border-radius:8px; outline:none;}
139
  .rh-filename:focus{background:var(--rh-input);}
 
165
  .CodeMirror{height:100% !important; font-family:'JetBrains Mono', monospace !important; font-size:13px; line-height:1.6;}
166
  .rh-plain-fallback{width:100%; height:100%; background:var(--rh-code-bg); color:#e2e8f0; border:none; outline:none; resize:none; padding:14px; font-family:'JetBrains Mono',monospace; font-size:13px; line-height:1.6;}
167
 
168
+ /* FULLSCREEN MODE CSS */
169
+ .rh-editor-wrap.fs-mode {
170
+ position: fixed; inset: 0; z-index: 100000; background: var(--rh-code-bg); height: 100dvh !important;
171
+ }
172
+ .floating-fs-close { display: none; position: absolute; top: 14px; right: 14px; z-index: 100001; background: rgba(239,68,68,0.15); color: var(--rh-danger); border: 1px solid var(--rh-danger); }
173
+ .rh-editor-wrap.fs-mode .floating-fs-close { display: flex; }
174
+ .floating-fs-close:hover { background: var(--rh-danger); color: #fff; }
175
+
176
+ /* SEARCH DIALOG FIX (THE "X" BUTTON) */
177
+ .CodeMirror-dialog { background:var(--rh-surface) !important; color:var(--rh-text) !important; padding:10px 14px !important; position: relative; padding-right: 50px !important; }
178
+ .CodeMirror-dialog input { background:var(--rh-input); color:var(--rh-text); border:1px solid var(--rh-border); border-radius:8px; padding:6px 10px; width: calc(100% - 60px); }
179
+ .CodeMirror-search-close {
180
+ position: absolute !important; right: 10px !important; top: 50% !important; transform: translateY(-50%) !important;
181
+ background: rgba(239,68,68,0.15) !important; color: var(--rh-danger) !important; border: 1px solid rgba(239,68,68,0.3) !important; border-radius: 8px !important;
182
+ width: 32px !important; height: 32px !important; font-size: 16px !important; cursor: pointer !important; display: flex !important; align-items: center !important; justify-content: center !important;
183
+ opacity: 1 !important;
184
+ }
185
+ .CodeMirror-search-close:hover { background: var(--rh-danger) !important; color: #fff !important; }
186
+
187
  /* ===== PREVIEW ===== */
188
  .rh-preview-pane{flex:1; min-height:0; display:none; flex-direction:column; background:var(--rh-bg);}
189
  .rh-preview-pane.active{display:flex;}
 
339
  .rh-confirm-actions{display:flex; gap:10px; margin-top:18px;}
340
  .rh-confirm-actions .rh-btn{flex:1;}
341
 
 
 
 
 
342
  @media (min-width:760px){
343
  .rh-sheet{max-width:640px;}
344
  .rh-overlay:not(.center) .rh-sheet{margin-bottom:20px; border-radius:22px;}
345
  }
346
+ .menu-row{display:flex; align-items:center; gap:12px; width:100%; padding:13px 10px; border-radius:12px; font-size:14px; font-weight:700; text-align:left; transition:.15s;}
347
+ .menu-row:hover{background:var(--rh-input);}
348
+ .menu-row svg{width:18px;height:18px; color:var(--rh-primary);}
349
  </style>
350
  </head>
351
  <body>
 
417
 
418
  <!-- CODE TAB -->
419
  <div class="rh-toolrow" id="codeToolbar">
420
+ <button class="rh-icon-btn" id="btnFullscreen" title="Full Screen Editor"></button>
421
+ <div class="rh-divider"></div>
422
  <button class="rh-icon-btn" id="btnGenerate" title="Generate with AI"></button>
423
  <div class="rh-divider"></div>
424
  <button class="rh-icon-btn" id="btnUndo" title="Undo"></button>
 
444
  <span id="autosaveTxt">—</span>
445
  </div>
446
  <div class="rh-editor-wrap" id="tabpane-code">
447
+ <button class="rh-icon-btn floating-fs-close" id="btnCloseFs" title="Close Fullscreen"></button>
448
  <textarea id="codeArea" spellcheck="false"></textarea>
449
  </div>
450
 
 
642
  <div id="toastStack"></div>
643
  </div>
644
 
 
 
 
 
 
 
645
  <script>
646
  'use strict';
647
  /* =========================================================================
 
695
  list: svg('<line x1="9" y1="6" x2="20" y2="6"/><line x1="9" y1="12" x2="20" y2="12"/><line x1="9" y1="18" x2="20" y2="18"/><circle cx="4.5" cy="6" r="1"/><circle cx="4.5" cy="12" r="1"/><circle cx="4.5" cy="18" r="1"/>'),
696
  timer: svg('<circle cx="12" cy="13" r="8"/><line x1="12" y1="9" x2="12" y2="13"/><line x1="9" y1="3" x2="15" y2="3"/>'),
697
  layers: svg('<polygon points="12 2 22 8.5 12 15 2 8.5 12 2"/><polyline points="2 15.5 12 22 22 15.5"/>'),
698
+ empty: svg('<path d="M21 8v10a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h5"/><path d="M16 2l6 6M22 2l-6 6"/>'),
699
+ fullscreen: svg('<path d="M8 3H5a2 2 0 0 0-2 2v3m18 0V5a2 2 0 0 0-2-2h-3m0 18h3a2 2 0 0 0 2-2v-3M3 16v3a2 2 0 0 0 2 2h3"/>'),
700
+ minimize: svg('<path d="M8 3v3h-3m14 -3v3h3m-14 14v-3h-3m14 3v-3h3"/>')
701
  };
702
  function setIc(id, key, cls){ const el = document.getElementById(id); if(el) el.innerHTML = ICONS[key] || ''; if(cls) el.classList.add(cls); }
703
 
 
931
  state.view = name;
932
  if(name === 'home') renderHome();
933
  if(name === 'history') renderHistory();
934
+ if(name === 'create'){
935
+ // THIS FIXES THE EDITOR NOT TYPING BUG (forces proper initialization on next frame)
936
+ requestAnimationFrame(() => {
937
+ if(cm) {
938
+ cm.refresh();
939
+ cm.focus();
940
+ }
941
+ fitDeviceFrame();
942
+ });
943
+ }
944
  }
945
 
946
  /* ---------- Sheets / modals ---------- */
 
954
  function initEditor(){
955
  const ta = document.getElementById('codeArea');
956
  if(window.CodeMirror){
957
+ ta.value = ""; // Clear out hidden values that break history
 
958
  cm = CodeMirror.fromTextArea(ta, {
959
  mode:'htmlmixed', theme:'dracula', lineNumbers:true, lineWrapping:true,
960
  matchBrackets:true, autoCloseBrackets:true, autoCloseTags:true,
961
  tabSize:2, indentUnit:2, styleActiveLine:true,
962
+ readOnly: false, // EXPLICITLY MAKE IT WRITABLE
963
  extraKeys:{
964
  'Ctrl-S': ()=>{ handleSaveClick(); },
965
  'Cmd-S': ()=>{ handleSaveClick(); },
 
972
  }
973
  });
974
  cm.setValue(TEMPLATES.blank.code);
975
+ cm.clearHistory(); // Force a clean history slate
 
976
  cm.on('change', onEditorChange);
977
  cm.on('cursorActivity', updateUndoRedoButtons);
978
  } else {
 
1095
  line.appendChild(tag); line.appendChild(msg);
1096
  body.appendChild(line);
1097
  body.scrollTop = body.scrollHeight;
 
 
 
1098
  }
1099
  function clearConsole(){
1100
  document.getElementById('consoleBody').innerHTML = '<div class="rh-console-empty">No output yet — hit Run to see logs &amp; errors here.</div>';
 
1196
  document.getElementById('tabpane-code').style.display = tab==='code' ? 'block' : 'none';
1197
  document.getElementById('tabpane-preview').classList.toggle('active', tab==='preview');
1198
  if(tab==='preview') setTimeout(fitDeviceFrame, 30);
1199
+ // Explicit refresh check here too
1200
+ if(tab==='code' && cm) requestAnimationFrame(()=> cm.refresh());
1201
  }
1202
 
1203
  /* ---------- Beautify ---------- */
 
1220
  headers:{ 'Content-Type':'application/json' },
1221
  body: JSON.stringify({ userPrompt, systemPrompt: systemPrompt||'', isCode: !!isCode, providerOverride:'auto' })
1222
  });
1223
+ if(!res.ok){
1224
+ let msg = 'AI request failed';
1225
+ try { const j = await res.json(); msg = j.error || msg; } catch(e){}
1226
+ throw new Error(msg);
1227
+ }
1228
  const data = await res.json();
1229
+
1230
+ // Checks multiple fields just in case your server.js formats the response differently for code
1231
+ return data.text || data.code || data.reply || data.response || (typeof data === 'string' ? data : JSON.stringify(data));
1232
  }
1233
+
1234
  function extractCode(text){
1235
  if(!text) return '';
1236
+
1237
+ // 1. Catch standard markdown fences, even if it says ```xml or something dumb
1238
+ const fence = text.match(/```[a-zA-Z]*\s*([\s\S]*?)```/);
1239
  if(fence) return fence[1].trim();
1240
+
1241
+ // 2. If the AI ignored fences entirely but gave raw HTML, strictly slice it out
1242
+ const htmlStart = text.match(/<!DOCTYPE html>|<html/i);
1243
+ if(htmlStart) {
1244
+ return text.substring(htmlStart.index).trim();
1245
+ }
1246
+
1247
  return text.trim();
1248
  }
1249
 
 
1637
  setIc('btnBackHome','back'); setIc('btnBackHome2','back'); setIc('btnMoreMenu','more');
1638
  setIc('tabCode','file'); document.getElementById('tabCode').innerHTML = ICONS.file + '<span>Code</span>';
1639
  setIc('tabPreview','smartphone'); document.getElementById('tabPreview').innerHTML = ICONS.smartphone + '<span>Preview</span>';
1640
+
1641
+ // FULLSCREEN TOGGLE
1642
+ setIc('btnFullscreen', 'fullscreen');
1643
+ setIc('btnCloseFs', 'close');
1644
+
1645
  setIc('btnGenerate','sparkles'); setIc('btnUndo','undo'); setIc('btnRedo','redo');
1646
  setIc('btnFind','search'); setIc('btnBeautify','wand'); setIc('btnTemplates','layout');
1647
  setIc('btnImport','fileImport'); setIc('btnCopyCode','copy'); setIc('btnClearCode','trash');
 
1702
  document.getElementById('tabCode').onclick = ()=> switchTab('code');
1703
  document.getElementById('tabPreview').onclick = ()=> switchTab('preview');
1704
 
1705
+ // FULL SCREEN TOGGLE LOGIC
1706
+ const toggleFs = () => {
1707
+ const wrap = document.getElementById('tabpane-code');
1708
+ wrap.classList.toggle('fs-mode');
1709
+ const isFs = wrap.classList.contains('fs-mode');
1710
+ setIc('btnFullscreen', isFs ? 'minimize' : 'fullscreen');
1711
+ if(cm) cm.refresh();
1712
+ };
1713
+ document.getElementById('btnFullscreen').onclick = toggleFs;
1714
+ document.getElementById('btnCloseFs').onclick = toggleFs;
1715
+
1716
  document.getElementById('btnGenerate').onclick = openGenerateModal;
1717
  document.getElementById('closeGenerate').onclick = ()=> closeSheet('ovGenerate');
1718
  document.getElementById('btnDoGenerate').onclick = doGenerate;