KJDRAW / QUICKSTART
Quickstart
Install KJDraw, mount a complete editor in minutes and open one of the editable industry samples.
Install#
npm install @kanjieteam/kjdraw@next
The next tag follows the release-candidate channel. Pin an exact version when you need reproducible builds.
Mount a complete editor#
Give the container a height, then create the editor:
<div id="cad"></div>
<style>#cad { width: 100%; height: 720px; }</style>
import { createKJDrawEditor } from '@kanjieteam/kjdraw'
const editor = createKJDrawEditor('#cad', {
document: 'sample',
locale: 'en',
theme: 'dark',
onSelectionChange: ({ ids }) => console.log(ids),
})
await editor.ready
await editor.execute('CREATE', {
type: 'LINE',
payload: { start: [0, 0, 0], end: [100, 40, 0] },
})
editor.fit()
Use editor.open(file) for KJD or DXF input and editor.save() to download the current drawing. The Editor API lists every option, method and event.
Open an industry sample#
import { createKJDrawEditor, createKJDrawSDK } from '@kanjieteam/kjdraw'
import {
INDUSTRY_SAMPLES,
createIndustrySample,
} from '@kanjieteam/kjdraw/samples'
const sdk = createKJDrawSDK()
console.table(INDUSTRY_SAMPLES)
const drawing = await createIndustrySample(sdk, 'sample-architecture')
const editor = createKJDrawEditor('#cad', { sdk, document: drawing })
await editor.ready
The sample catalogue also includes a site plan, road profile and mechanical manufacturing drawing. Each result is a normal editable KJDocument, so the same file, command and plugin APIs apply.
Use multiple editors#
Pass the same sdk to share plugins and commands, and give each editor its own container with a height. Use editor.execute() to target a specific editor, or pass an explicit document when calling the SDK directly. See Commands and transactions for background editing examples.
Blank and sample drawings created by an editor are released after their last editor view closes. A drawing supplied through document remains owned by your application. Two views can display the same drawing; replacing it by reopening a file with the same ID is rejected while another view still uses it, so that view keeps its drawing and selection.
Continue to React or Vue for framework components, Files for KJD/KJP/DXF, or Commands for programmatic editing.