Primeiros passos
No npmEditor
The whole drafting editor as one React component, with its stylesheet and its words in three languages.
The whole MellowCAD drafting editor as one React component, CadEditor: the drawing with the
chrome an AutoCAD user expects around it — the top bar, the tool palette, the palettes, the command
line, the status bar, the ViewCube — its menus and dialogs, and its words in English, Spanish and
Arabic. It is the editor of mellowcad.com/draw, built on
@mellowcad/engine and @mellowcad/react, and it
ships its own stylesheet.
npm install @mellowcad/editor @mellowcad/react @mellowcad/engineThe engine, @mellowcad/react and React 19 are peers: a page has one of each. The package is ESM
only and ships its TypeScript declarations.
Quick start
The whole of examples/editor-vite, a Vite app:
import { StrictMode } from "react"import { createRoot } from "react-dom/client"import { CadEditor } from "@mellowcad/editor"import "@mellowcad/editor/styles.css"import "./index.css"
createRoot(document.getElementById("root")!).render( <StrictMode> <CadEditor /> </StrictMode>)/* What the editor asks of the page around it: the two fonts it reads, and a body without margin, since the editor fills the window. Its stylesheet styles nothing outside its root. */:root { --font-sans: system-ui, sans-serif; --font-mono: ui-monospace, monospace; color-scheme: dark;}
body { margin: 0;}Type L and Enter, click twice, press Escape: that is AutoCAD's LINE. Reload the page and the
drawing is still there.
What it asks of the page
- Two fonts. Set
--font-sansand--font-monoon the page, or on any element around the editor. The editor declares neither. - The whole window. The editor is
100svhhigh and as wide as its parent. Give the body no margin and put nothing above or below it: your own controls go in the editor's slots. - The whole keyboard. It takes every key on the page wherever focus is, as AutoCAD does, so a command can be typed at any moment. A text field keeps what is typed in it, save the function keys and AutoCAD's Ctrl shortcuts.
- Nothing else. The stylesheet styles only the editor's root,
[data-mellowcad-editor], and what is inside it, never<html>or<body>. The editor setslanganddiron its own root and leaves the page's alone.
By default it keeps the drawing in this browser's localStorage and restores it on the next
visit. To keep it somewhere else, see Saving drawings.
Props
Every prop is optional.
- Languages:
engineLocalefor the commands, prompts and drawing,editorLocalefor the editor's own words, anddir="rtl"to mirror the chrome. See Languages. - The drawing:
store, where it is kept, andonEngine, which hands you the engine to save, open or run commands from your own code. See Saving drawings. - The chrome:
components, your own top bar, status bar or other piece, or none;mark, your product's glyph on the application menu;languages, the page in each language you offer, in that menu;layoutStorage, thelocalStoragekeys under which the palette panel and the status bar are remembered;help, where F1 opens help; andsheet, an id and aview-transition-namefor the drawing's cell. See Customizing.
engineLocale, store, onEngine and help go to the engine, so they are read once, when the
editor starts. To change one, mount a new editor: give it a new key.
Guides
| Guide | What it covers |
|---|---|
| Customizing | Replacing or removing the top bar, the status bar and the other pieces |
| Saving drawings | Your own store, and saving and opening drawings from your code |
| Languages | Spanish and Arabic, right to left, the language menu, your own words |
| Next.js | Server pages, catalogs loaded on the server, fonts and the layout script |
| API reference | Every export, with its signature and its documentation |
What each command does, with its prompts and options, is in the user's command reference.
Entry points
| Import | What |
|---|---|
@mellowcad/editor | CadEditor, its pieces and their types |
@mellowcad/editor/locales/<tag> | The editor's words in one language each: en, es, ar, pt-BR (exported as ptBR, in progress) |
@mellowcad/editor/styles.css | The stylesheet |
Versioning
The editor follows semantic versioning, as the engine does. What it promises is what the
API reference lists: every export and every type it reaches, the shape of its catalog
(EditorLocale), and what the stylesheet asks of a page — its root attribute, its cascade layers
and the two font variables. While the version is 0.x, a breaking change bumps the minor version.
Each release is in the changelog.
License
MIT (LICENSE): the code, not the MellowCAD name or logo.
AutoCAD is a registered trademark of Autodesk, Inc. MellowCAD is an independent project, not affiliated with or endorsed by Autodesk; AutoCAD is named only to describe what it is compatible with.