# @nuwatop/code-canvas-runtime

Runtime utilities for **code-canvas** generated React applications. Re-exports [`@nuwatop/code-canvas-core`](https://www.npmjs.com/package/@nuwatop/code-canvas-core) and adds command watching, runtime rendering, and related helpers.

## Installation

Peer dependencies: `react`, `react-dom`, `antd`, `zustand`, etc. (see `package.json` → `peerDependencies`).

```bash
npm install @nuwatop/code-canvas-runtime
```

## Usage

Typical imports in generated app code (`Extend.ts` / pages):

```typescript
import {
  createWatchCommands,
  useAndStore,
  useItemStore,
} from "@nuwatop/code-canvas-runtime";

const watchCommandsWithContext = createWatchCommands(() => ({
  // command handlers keyed by action name
}));

export function init(store?: unknown) {
  if (store) {
    watchCommandsWithContext(store as never, "your-session-id");
  }
}
```

Other exports include `RuntimeRenderer`, `ComponentRegistry`, `initRuntime`, `UIUtils`, validation helpers, etc. — see `src/index.ts`.

## 发布到 npm（维护者）

在 **`runtime` 目录**下，先改好 `package.json` 里的 **`version`**（不能和已发布版本重复），登录 npm 官方源后执行：

```bash
npm publish --access public
```

- **`--access public`**：本包是 scoped 包（`@nuwatop/...`），公开到 npmjs 必须加这一项。
- **`prepublishOnly`** 已配置为自动 `npm run build`，一般无需先手动 `build`。

若本机默认 registry 是镜像（如 npmmirror，不能 `publish`），可：

```bash
npm publish --access public --registry https://registry.npmjs.org/
```

或在 `runtime/.npmrc` 中指定 `registry=https://registry.npmjs.org/`（含 token 时不要提交到 Git）。

## License

MIT
