Fix HTML Preview Tool critical bugs: PreviewFrame ref and click handler

- Fixed missing ref={previewFrameRef} on first PreviewFrame component (line 336)
  * This was causing 'PreviewFrame API not available' errors during save operations
  * Both fullscreen and normal mode PreviewFrame instances now have proper ref connection

- Fixed click handler attachment bug in setupInspectModeStyles function
  * Click handler was being skipped when styles were already injected
  * Now always attaches click handler when inspect mode is activated
  * Added proper cleanup to prevent duplicate event listeners

- Fixed variable scope issues in PreviewFrame.fresh.js
  * styleElement and cursorStyleElement now properly scoped for cleanup function
  * Added references to existing elements when styles already present

- Removed unused variables and fixed eslint warnings
  * Removed unused indentSize variable in BeautifierTool.js
  * Removed unused onSave and onDomUpdate props in PreviewFrame.fresh.js
  * Fixed unnecessary escape character in script tag

These fixes restore the Enhanced Option A DOM manipulation architecture:
- Inspector sidebar should now appear when clicking elements in inspect mode
- Save functionality should work without 'PreviewFrame ref not available' errors
- Live editing of element properties should work through PreviewFrame API
- Iframe refresh prevention during inspector operations maintained
This commit is contained in:
dwindown
2025-08-03 22:04:25 +07:00
parent 7afb83753c
commit e1bc8d193d
18 changed files with 5339 additions and 10 deletions

View File

@@ -144,6 +144,9 @@ const BeautifierTool = () => {
};
const beautifyHtml = (text) => {
// Declare formatted variable outside try/catch block
let formatted = '';
try {
// Clean input text first
let cleanText = text.trim();
@@ -154,14 +157,9 @@ const BeautifierTool = () => {
// Self-closing tags that don't need closing tags
const selfClosingTags = ['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'param', 'source', 'track', 'wbr'];
// Inline tags that should stay on same line
const inlineTags = ['a', 'abbr', 'acronym', 'b', 'bdo', 'big', 'br', 'button', 'cite', 'code', 'dfn', 'em', 'i', 'img', 'input', 'kbd', 'label', 'map', 'object', 'q', 'samp', 'script', 'select', 'small', 'span', 'strong', 'sub', 'sup', 'textarea', 'tt', 'var'];
let formatted = '';
let indent = 0;
const tab = ' ';
// Better HTML parsing
let formatted = ''; // Better HTML parsing
const tokens = cleanText.match(/<\/?[^>]+>|[^<]+/g) || [];
for (let i = 0; i < tokens.length; i++) {
@@ -203,7 +201,7 @@ const BeautifierTool = () => {
return formatted.trim();
} catch (err) {
// Fallback to simple formatting if advanced parsing fails
let formatted = '';
formatted = '';
let indent = 0;
const tab = ' ';