> ## Documentation Index
> Fetch the complete documentation index at: https://superdoc-caio-pizzol-docs-ai-core-preset.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# DropCursor extension

export const SourceCodeLink = ({extension, path}) => {
  const githubPath = path || `packages/super-editor/src/editors/v1/extensions/${extension.toLowerCase()}`;
  const githubUrl = `https://github.com/superdoc-dev/superdoc/tree/main/${githubPath}`;
  return <div>
      <p>
        <a href={githubUrl} target="_blank" rel="noopener noreferrer">
          View on GitHub →
        </a>
      </p>
    </div>;
};

export const SuperDocEditor = ({html = '<p>Start editing...</p>', height = '400px', maxHeight = '400px', onReady = null, showExport = true, customButtons = null}) => {
  const [ready, setReady] = useState(false);
  const editorRef = useRef(null);
  const containerIdRef = useRef(`editor-${Math.random().toString(36).substr(2, 9)}`);
  const DEV_DIST_URL = 'http://localhost:9094/dist';
  const UNPKG_DIST_URL = 'https://unpkg.com/superdoc@latest/dist';
  const getBaseUrl = async () => {
    const isDev = typeof window !== 'undefined' && window.location.hostname === 'localhost';
    if (isDev) {
      try {
        const res = await fetch(`${DEV_DIST_URL}/superdoc.min.js`, {
          method: 'HEAD'
        });
        if (res.ok) {
          console.info('[SuperDoc Docs] Using local build from', DEV_DIST_URL);
          return DEV_DIST_URL;
        }
        console.warn('[SuperDoc Docs] Local dev server returned', res.status, '- falling back to unpkg');
      } catch (err) {
        console.warn('[SuperDoc Docs] Local dev server not reachable: falling back to unpkg.', 'Run `pnpm dev:docs` from the repo root to use your local build.', err.message);
      }
    }
    return UNPKG_DIST_URL;
  };
  const ensureStyle = baseUrl => {
    const styleHref = `${baseUrl}/style.css`;
    if (document.querySelector(`link[href="${styleHref}"]`)) return;
    const link = document.createElement('link');
    link.rel = 'stylesheet';
    link.href = styleHref;
    document.head.appendChild(link);
  };
  const loadSuperDoc = baseUrl => {
    if (window.SuperDoc) return Promise.resolve();
    const scriptSrc = `${baseUrl}/superdoc.min.js`;
    const existingScript = document.querySelector(`script[src="${scriptSrc}"]`);
    if (existingScript) {
      if (window.SuperDoc) return Promise.resolve();
      return new Promise((resolve, reject) => {
        existingScript.addEventListener('load', resolve, {
          once: true
        });
        existingScript.addEventListener('error', reject, {
          once: true
        });
      });
    }
    return new Promise((resolve, reject) => {
      const script = document.createElement('script');
      script.src = scriptSrc;
      script.onload = resolve;
      script.onerror = reject;
      document.body.appendChild(script);
    });
  };
  const initEditor = () => {
    setTimeout(() => {
      if (!window.SuperDoc) return;
      if (!document.getElementById(containerIdRef.current)) return;
      if (editorRef.current) return;
      editorRef.current = new window.SuperDoc({
        selector: `#${containerIdRef.current}`,
        html,
        rulers: true,
        contained: true,
        onReady: () => {
          setReady(true);
          if (onReady) onReady(editorRef.current);
        }
      });
    }, 100);
  };
  useEffect(() => {
    let cancelled = false;
    const boot = async () => {
      try {
        const baseUrl = await getBaseUrl();
        ensureStyle(baseUrl);
        await loadSuperDoc(baseUrl);
        if (!cancelled) initEditor();
      } catch (error) {
        console.error('Failed to boot SuperDoc:', error);
      }
    };
    boot();
    return () => {
      cancelled = true;
      editorRef.current?.destroy?.();
      editorRef.current = null;
    };
  }, []);
  const exportDocx = () => {
    if (editorRef.current?.export) {
      editorRef.current.export();
    }
  };
  return <div className="border rounded-lg bg-white overflow-hidden">
      {ready && (showExport || customButtons) && <div className="px-3 py-2 bg-gray-50 border-b">
          {customButtons && <div className="space-y-1 mb-2">
              {customButtons.map((row, rowIndex) => <div key={rowIndex} className="flex gap-1">
                  {row.map((btn, i) => <button key={i} onClick={() => btn.onClick(editorRef.current)} className={btn.className || 'flex-1 px-2 py-1 bg-gray-100 text-gray-700 text-xs rounded hover:bg-gray-200'}>
                      {btn.label}
                    </button>)}
                </div>)}
            </div>}
          {showExport && <div className="text-right">
              <button onClick={exportDocx} className="px-3 py-1 bg-blue-500 text-white text-xs rounded hover:bg-blue-600">
                Export DOCX
              </button>
            </div>}
        </div>}
      <div id={containerIdRef.current} style={{
    height,
    maxHeight,
    paddingLeft: '5px'
  }} />
      <style jsx>{`
        #${containerIdRef.current} .superdoc__layers {
          max-width: 660px !important;
        }
        #${containerIdRef.current} .super-editor {
          max-width: 100% !important;
          width: 100% !important;
          color: #000;
        }
        #${containerIdRef.current} .editor-element {
          width: 100% !important;
          min-width: unset !important;
          transform: none !important;
        }
        #${containerIdRef.current} .editor-element {
          h1,
          h2,
          h3,
          h4,
          h5,
          strong {
            color: #000;
          }
        }
      `}</style>
    </div>;
};

Visual indicator showing where dragged content will be inserted.

The drop cursor appears as a vertical line when dragging content over the editor.

<div
  style={{
padding: '20px',
background: '#f3f4f6',
borderRadius: '8px',
marginBottom: '16px',
border: '2px dashed rgb(156, 163, 175)',
textAlign: 'center'
}}
>
  <img
    src="https://mintcdn.com/superdoc-caio-pizzol-docs-ai-core-preset/WYJm0Ixs2VTjtqSu/public/images/extensions/dropcursor.svg?fit=max&auto=format&n=WYJm0Ixs2VTjtqSu&q=85&s=90e216fd76751580f517657d1445ac8c"
    alt="Draggable demo image"
    style={{
  cursor: 'grab',
  borderRadius: '8px',
  margin: '0 auto'
}}
    draggable="true"
    width="100"
    height="100"
    data-path="public/images/extensions/dropcursor.svg"
  />

  <p style={{ marginTop: '12px', color: '#6b7280', fontSize: '14px' }}>
    👆 Drag this image into the editor below to see the drop cursor
  </p>
</div>

<SuperDocEditor html={`<p>As you drag the image above over different positions in this text, you'll see a vertical line (the drop cursor) indicating where the image would be inserted.</p><p>The drop cursor helps you position content precisely between words, at the start of paragraphs, or between paragraphs.</p><p>Try dragging the image to different positions to see how the cursor moves!</p>`} height="250px" />

## Use case

* **Visual Feedback** - Shows exactly where content will drop
* **Precision Placement** - Position images and files accurately
* **Better UX** - Clear indicator prevents placement mistakes
* **Professional Feel** - Matches modern editor behavior

## Options

Configure the extension behavior:

<ParamField path="color" type="string" default="currentColor">
  CSS color for the drop cursor indicator
</ParamField>

<ParamField path="width" type="number" default="2">
  Width of the drop cursor line in pixels
</ParamField>

<ParamField path="class" type="string">
  Optional CSS class to apply to the drop cursor element
</ParamField>

**Example:**

```javascript theme={null}
// Customize drop cursor appearance
const ConfiguredDropCursor = DropCursor.configure({
  color: '#3b82f6',
  width: 3,
  class: 'custom-drop-cursor'
});

// Use in SuperDoc
new SuperDoc({
  selector: '#editor',
  document: 'document.docx',
  editorExtensions: [ConfiguredDropCursor]
});
```

## Source code

<SourceCodeLink path="packages/super-editor/src/editors/v1/extensions/dropcursor/dropcursor.js" />
