Documentation
Everything you need to integrate and use the Custom Editor SDK in your projects.
๐ฆ Introduction
Custom Editor is a powerful, client-side image design editor SDK built with React and Konva. It provides a complete set of tools for creating and editing designs with text, images, shapes, and freehand drawing.
โก Installation
Install the package using your preferred package manager:
npm install @lokasketch/corepnpm add @lokasketch/coreyarn add @lokasketch/core@lokasketch/core- Main editor component
๐ Quick Start
Here's a minimal example to get the editor running:
import { CustomEditor } from "@lokasketch/core";
function App() {
return (
<CustomEditor
width={800}
height={600}
config={{
apiKey: "your-api-key",
}}
onDesignChange={(json) => {
console.log("Design changed:", json);
}}
/>
);
}
export default App;๐ API Configuration
The editor requires a config prop for API features like fonts, stock photos, and templates.
import type { EditorConfig } from "@lokasketch/core";
interface EditorConfig {
apiKey: string; // API key sent in x-api-key header
}<CustomEditor
config={{
apiKey: process.env.NEXT_PUBLIC_EDITOR_API_KEY,
}}
/>โ๏ธ React Integration
For standard React projects (Create React App, custom setups):
import { CustomEditor } from "@lokasketch/core";
import { useState, useCallback } from "react";
const config = {
apiKey: "your-api-key",
};
function App() {
const [design, setDesign] = useState(null);
const handleDesignChange = useCallback((json) => {
setDesign(json);
localStorage.setItem("my-design", JSON.stringify(json));
}, []);
const handleExport = useCallback((blob, format) => {
const url = URL.createObjectURL(blob);
const link = document.createElement("a");
link.href = url;
link.download = `design.${format}`;
link.click();
URL.revokeObjectURL(url);
}, []);
return (
<CustomEditor
width={800}
height={600}
config={config}
initialDesign={design}
onDesignChange={handleDesignChange}
onExport={handleExport}
/>
);
}โฒ Next.js App Router
For Next.js 13+ with App Router, use the ClientOnly wrapper or dynamic imports to handle SSR:
"use client";
import dynamic from "next/dynamic";
const CustomEditor = dynamic(
() => import("@lokasketch/core").then((mod) => mod.CustomEditor),
{ ssr: false, loading: () => <div>Loading...</div> }
);
const config = {
apiKey: process.env.NEXT_PUBLIC_EDITOR_API_KEY || "demo-key",
};
export default function EditorPage() {
return <CustomEditor width={800} height={600} config={config} />;
}๐ Next.js Pages Router
For Next.js with Pages Router, use dynamic imports:
import dynamic from "next/dynamic";
import { useState } from "react";
const CustomEditor = dynamic(
() => import("@lokasketch/core").then((mod) => mod.CustomEditor),
{ ssr: false, loading: () => <div>Loading editor...</div> }
);
const config = {
apiKey: process.env.NEXT_PUBLIC_EDITOR_API_KEY || "demo-key",
};
export default function EditorPage() {
const [design, setDesign] = useState(null);
return (
<div style={{ padding: 20 }}>
<h1>Design Editor</h1>
<CustomEditor
width={800}
height={600}
config={config}
initialDesign={design}
onDesignChange={setDesign}
/>
</div>
);
}โก Vite + React
Vite works out of the box with no special configuration:
# Create new Vite project
npm create vite@latest my-editor -- --template react-ts
cd my-editor
# Install Custom Editor
npm install @lokasketch/coreimport { CustomEditor } from "@lokasketch/core";
const config = {
apiKey: import.meta.env.VITE_EDITOR_API_KEY || "demo-key",
};
function App() {
return (
<div className="app">
<CustomEditor
width={1080}
height={1080}
config={config}
onDesignChange={(json) => console.log(json)}
/>
</div>
);
}
export default App;๐ API Reference
Main exports from @lokasketch/core:
| Export | Type | Description |
|---|---|---|
| CustomEditor | Component | Main editor component with full UI |
โ๏ธ CustomEditor Props
| Prop | Type | Required | Description |
|---|---|---|---|
| config | EditorConfig | โ Yes | API configuration (EditorConfig from @lokasketch/core) |
| width | number | No | Canvas width in pixels (default: 800) |
| height | number | No | Canvas height in pixels (default: 600) |
| initialDesign | EditorJSON | null | No | Initial design to load (EditorJSON from @lokasketch/core) |
| onDesignChange | (json) => void | No | Called when design changes |
| onExport | (blob, format) => void | No | Called when exporting |