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

@meituan-nocode/nocode-design-mode-sandbox-script

v0.1.0

Published

NoCode Design Mode Sandbox Script

Readme

NoCode Design Mode Sandbox Script

这个包提供了一个沙箱脚本,用于在 iframe 中注入设计模式功能。

功能

  • 通过 Penpal 与父窗口通信
  • DOM 元素操作和查询
  • 样式管理
  • 拖拽功能
  • 文本编辑
  • 主题切换

构建

# 开发环境构建
pnpm run build:dev

# 测试环境构建
pnpm run build:test

# 预发布环境构建
pnpm run build:pre

# 生产环境构建
pnpm run build:prod

上传到 CDN

# 上传到开发环境
pnpm run upload:dev

# 上传到测试环境
pnpm run upload:test

# 上传到预发布环境
pnpm run upload:pre

# 上传到生产环境
pnpm run upload:prod

使用方式

在测试应用中使用

在 HTML 的 <head> 标签中引入脚本:

<head>
    <script src="../nocode-design-mode-sandbox-script/dist/sandbox-script.js"></script>
</head>

在生产环境中使用

从 CDN 引入:

<head>
    <!-- 开发环境 -->
    <script src="https://s3plus.meituan.net/nocode-external/artwork/dev/sandbox-script.js"></script>

    <!-- 测试环境 -->
    <script src="https://s3plus.meituan.net/nocode-external/artwork/test/sandbox-script.js"></script>

    <!-- 生产环境 -->
    <script src="https://s3plus.meituan.net/nocode-external/artwork/sandbox-script.js"></script>
</head>

架构说明

目录结构

nocode-design-mode-sandbox-script/
├── api/              # API 方法
│   ├── dom.ts       # DOM 处理
│   ├── elements/    # 元素操作
│   ├── events/      # 事件处理
│   ├── style/       # 样式管理
│   └── theme/       # 主题管理
├── constants/       # 常量定义
├── helpers/         # 辅助函数
├── types/          # TypeScript 类型定义
├── index.ts        # 入口文件
└── webpack.config.js

通信机制

脚本使用 Penpal 库与父窗口(Design Mode Designer)进行通信:

  1. 子窗口暴露的方法:在 api/index.ts 中的 preloadMethods 定义
  2. 父窗口方法调用:通过 penpalParent 对象调用父窗口方法

主要功能模块

  • DOM 处理:构建 Layer Tree,处理 DOM 变化
  • 元素操作:查询、插入、删除、移动元素
  • 样式管理:CSS 样式的读取和更新
  • 拖拽功能:元素拖拽和位置调整
  • 文本编辑:内联文本编辑
  • 主题管理:明暗主题切换

开发说明

依赖说明

  • penpal: 用于 iframe 跨窗口通信
  • lodash: 工具函数库
  • nanoid: 生成唯一 ID
  • css-tree: CSS 解析和操作

类型定义

所有类型定义在 types/index.ts 中,包括:

  • DomElement: DOM 元素信息
  • LayerNode: Layer Tree 节点
  • ActionElement: 操作元素
  • StyleChange: 样式变更
  • 等等

常量定义

constants/index.ts 中定义了:

  • EditorAttributes: 编辑器使用的 data 属性
  • DOM_IGNORE_TAGS: 需要忽略的 DOM 标签
  • INLINE_ONLY_CONTAINERS: 只能包含内联元素的容器

注意事项

  1. 脚本必须在页面加载前引入(在 <head> 中)
  2. 脚本会自动初始化并与父窗口建立连接
  3. 确保父窗口也使用了 Penpal 进行通信
  4. 上传到 CDN 后需要刷新 CDN 缓存