@mova-ui/can-react
v0.1.0
Published
Can SDK is the complete local canvas used by the official Web and Desktop apps. The preview targets React 19 and modern desktop browsers. It has no account or cloud service.
Readme
@mova-ui/can-react
Can SDK is the complete local canvas used by the official Web and Desktop apps. The preview targets React 19 and modern desktop browsers. It has no account or cloud service.
Install the preview
The npm package name is @mova-ui/can-react (React 19 peer dependencies). Install version 0.1.0 with:
npm install @mova-ui/[email protected] react@^19 react-dom@^19To build and test local distribution archives, run npm run build:sdk and npm run test:sdk; install the three mova-ui-can-*-0.1.0.tgz files from release/sdk together.
import { CanCanvas } from "@mova-ui/can-react";
import "@mova-ui/can-react/style.css";
export function Board() {
return (
<div style={{ height: 720 }}>
<CanCanvas boardId="my-board" namespace="my-product" />
</div>
);
}The component includes editing, selection, movement, zoom, menus, history and browser local saving. Give its parent a definite height. namespace and boardId determine persistence identity; changing either opens different local data. Same-origin instances with the same identity share a single writer lease. A second instance opens read-only until it can take over.
Commands and events
Capture the instance with onReady or a component ref. Commands are the authoritative mutation interface; do not mutate the objects returned by getLibrary().
<CanCanvas
boardId="notes"
onReady={(canvas) => {
// Trigger this from your own UI, not on every mount:
// canvas.create('note', { title: 'Hello', content: 'Markdown text' });
}}
onChange={(library) => console.log("Content changed", library.items.length)}
onSaveStateChange={(state) => console.log(state.status)}
onError={(error) => console.error(error)}
/>Save states are pending, saving, saved and error. Only saved confirms storage committed. onChange does not confirm persistence. flush() waits for queued storage work. exportFile() opens the platform backup flow for the current board; exportFile({ scope: "workspace" }) includes every board. import() opens the platform import flow. export() returns the runtime workspace snapshot and exportBoard() returns the current board snapshot; neither embeds media bytes. Raw snapshot imports reject media references: use a portable .can archive when transferring assets.
In browsers, file-picker activation must happen directly in the user gesture. If import() is called while edits are still pending, the SDK saves those edits and reports that the import should be started again; invoke it again from a fresh click. This keeps the existing board safe and lets the browser open the picker without losing the user gesture.
Other methods include update, remove, undo, redo, getSelection, setSelection, getView, setView, and navigate. readOnly blocks content editing; theme accepts the library theme values. The SDK cleans its own subscriptions and default storage on unmount. A supplied storage adapter remains owned by the host. flushCanInstances() flushes every mounted instance, including open editors. Browser page exit requests a flush and prompts while edits are pending; Electron coordinates the flush before closing. Hosts that control navigation should await flush() before unmounting.
Custom cards
import type { CustomCardProps } from "@mova-ui/can-react";
function Counter({ item, update, readOnly }: CustomCardProps) {
const value = Number(item.data?.value ?? 0);
return (
<button
disabled={readOnly}
onClick={() => update({ data: { ...item.data, value: value + 1 } })}
>
Count: {value}
</button>
);
}
// <CanCanvas customCards={{ counter: Counter }} ... />
// canvas.create('custom', { customType: 'counter', data: { value: 0 } });Custom data must be JSON-serializable. The canvas owns geometry, selection, resize and history. Keep editor events scoped to the card so typing and pointer actions do not accidentally become canvas commands.
Composition and storage
CanProvider owns the same runtime used by CanCanvas. Place CanvasSurface and your controls inside it. useCan() returns the current controller and state after initialization; the provider delays its children until that runtime is ready. CanvasSurface inherits the provider’s theme, read-only mode, custom cards and selection callback. CanvasToolbar is an optional command toolbar. Built-in exports include Card, RichTextEditor, MindMapEditor, MediaFocus and metadata/dialog components; their typed props describe required content and callbacks.
storage accepts the CanAPI contract exported from @mova-ui/can-core. @mova-ui/can-storage-browser supplies createBrowserStorage. The desktop app supplies its restricted IPC adapter. capabilities supplies host operations. Node and Electron modules are absent from the browser SDK distribution.
Logical can-asset:// references are resolved by the adapter. Persist asset identifiers, never transient Blob URLs. Browser data stays local to its origin. Export a portable .can backup before changing origins or clearing browser data.
