npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@hokkeung/astro-excalidraw-editable

v0.1.9

Published

Editable Excalidraw diagrams for Astro content, with a dev-only save endpoint.

Downloads

1,233

Readme

@hokkeung/astro-excalidraw-editable 中文文档

在 Astro / MDX 中嵌入 Excalidraw 图,并在开发环境里直接编辑、保存回 .excalidraw.json 文件。

适合什么场景

  • 在技术文章、知识库、组件文档中展示 Excalidraw 图。
  • 希望图表源码以 .excalidraw.json 文件保存在项目里。
  • 希望开发时能直接在页面上编辑图表,保存后自动写回本地文件。
  • 生产环境只需要干净的只读预览。

安装

pnpm add @hokkeung/astro-excalidraw-editable @excalidraw/excalidraw
pnpm astro add react

@excalidraw/excalidraw 需要安装在使用方项目中。这个包内部会直接使用它,但不会把它打包进来。

配置 Astro

// astro.config.ts
import react from '@astrojs/react'
import { excalidrawEditable } from '@hokkeung/astro-excalidraw-editable/integration'
import { defineConfig } from 'astro/config'

export default defineConfig({
  integrations: [
    react(),
    excalidrawEditable(),
  ],
})

默认配置:

excalidrawEditable({
  allowedDir: 'src/content/excalidraw',
  allowedSuffix: '.excalidraw.json',
  endpoint: '/__excalidraw_save',
})

保存接口只会写入 allowedDir 目录下,并且只接受 allowedSuffix 后缀的文件。

在 MDX 中使用

创建图表文件:

src/content/excalidraw/demo.excalidraw.json

在 MDX 页面中引入组件:

---
title: Editable Diagram
---

import Excalidraw from '@hokkeung/astro-excalidraw-editable'

<Excalidraw src="demo" height={520} />

src="demo" 会被解析到默认目录:

src/content/excalidraw/demo.excalidraw.json

子目录也可以直接写:

<Excalidraw src="architecture/frontend" />

上面会读取:

src/content/excalidraw/architecture/frontend.excalidraw.json

也可以使用相对路径:

<Excalidraw src="../content/excalidraw/demo.excalidraw.json" />

编辑和保存

开发环境中,组件会在右上角显示 编辑 按钮。点击后会打开全屏 Excalidraw 编辑器。

  • 使用 Cmd+SCtrl+S 保存。
  • 保存成功后,本地 .excalidraw.json 文件会被更新。
  • 如果有未保存修改,关闭编辑器前会提示确认。
  • 生产环境默认不会显示编辑入口。

常用属性

组件支持 @excalidraw/excalidraw 的 React props,并额外支持这些属性:

| Prop | 类型 | 默认值 | 说明 | | --- | --- | --- | --- | | class | string | - | 外层容器 class。 | | dataPath | string | - | 保存时使用的项目内 JSON 路径。 | | editable | boolean | import.meta.env.DEV | 是否显示编辑入口。 | | height | number \| string | '400px' | 图表高度,数字会按 px 处理。 | | saveEndpoint | string | '/__excalidraw_save' | 保存接口地址。 | | src | string | - | MDX 中的文件路径简写。 |

通常只需要传 srcheight

自定义组件名

如果你在 MDX 中把组件封装成别的名字,可以通过 componentNamessrc 转换继续生效:

excalidrawEditable({
  componentNames: ['Excalidraw', 'MyDiagram'],
})

之后可以这样写:

<MyDiagram src="demo" />

导出入口

  • @hokkeung/astro-excalidraw-editable: Astro 组件。
  • @hokkeung/astro-excalidraw-editable/integration: Astro integration。
  • @hokkeung/astro-excalidraw-editable/remark-plugin: MDX src 转换插件。
  • @hokkeung/astro-excalidraw-editable/react: 底层 React 组件。
  • @hokkeung/astro-excalidraw-editable/vite-plugin: 开发环境保存中间件。