A visual HTML editor built with React that supports editing DOM elements and iframe content with hover highlighting and click-to-edit functionality.
- 
Core Editor Library ( lib/)- HTMLEditor: Core editor with hover highlighting and focus selection
- StyleManager: Manages font, margin, padding, background, color, and border styles
- EventManager: Handles events for both regular DOM and iframe elements
 
- 
React Hooks ( hooks/)- useDirectMode: Edit DOM elements via React ref or iframe content directly
- useInjectMode: Inject editor into iframe for editing internal elements
 
- 
Components ( components/)- Tooltip: Contextual toolbar with editing options
- Text elements: Font size, background color, text color, bold, italic, underline, delete
- Block elements: Background color, border radius, border, margin, delete
- Image elements: Reserved API design
 
 
- Tooltip: Contextual toolbar with editing options
- 
Test Pages ( pages/)- react-dom.tsx: React ref DOM editing example
- iframe.tsx: Iframe content editing example
 
npm installnpm run devThe app will open at http://localhost:3000
Navigate to the home page to see React ref-based editing. Hover over elements to highlight them, click to select and edit.
Navigate to /iframe to see iframe injection-based editing. The editor is injected into the iframe allowing you to edit elements inside.
doc-editor/
├── src/
│   ├── lib/              # Core editor library
│   │   ├── index.ts      # HTMLEditor class
│   │   ├── types.d.ts    # TypeScript definitions
│   │   └── core/
│   │       ├── eventManager/
│   │       └── styleManager/
│   ├── hooks/            # React hooks
│   │   ├── useDirectMode.ts
│   │   └── useInjectMode.ts
│   ├── components/       # React components
│   │   └── tooltip.tsx
│   ├── pages/            # Test pages
│   │   ├── react-dom.tsx
│   │   └── iframe.tsx
│   ├── styles/           # Global styles
│   │   └── global.css
│   └── index.tsx         # App entry point
├── index.html
├── package.json
├── tsconfig.json
└── vite.config.ts
npm run buildThe editor provides a comprehensive style configuration API to customize hover, focus, and badge styles.
import HTMLEditor from './lib/index';
const editor = new HTMLEditor({
  container: '#editor',
  styleConfig: {
    hover: {
      outline: '2px dashed #4dabf7',
      cursor: 'pointer'
    },
    selected: {
      outline: '2px solid #228be6'
    },
    badge: {
      enabled: true,
      position: 'top-left',
      background: '#228be6',
      color: 'white'
    }
  }
});import { useDirectMode } from './hooks/useDirectMode';
const { editor, selectedElement, position } = useDirectMode(containerRef, {
  styleConfig: {
    badge: {
      position: 'top-right',
      background: '#ff6b6b'
    }
  }
});For detailed style configuration options, see STYLE_API.md.
- React 18
- TypeScript
- Vite
- React Router