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

ew-iframe-editor

v0.0.1

Published

Embed online code editors into any web page via iframe with initial code loading. Built-in ew-code-editor support, with adapter pattern for custom editor integration.

Readme

ew-iframe-editor

通用代码编辑器嵌入 SDK,通过适配器模式将在线代码编辑器(默认 ew-code-editor)嵌入网页并加载初始代码。支持通过 requestUrl 加载代码文件,或直接传入 html/css/js 代码内容。

在线演示:https://eveningwater.github.io/ew-iframe-editor/

安装

npm install ew-iframe-editor
# 或
pnpm add ew-iframe-editor
# 或
yarn add ew-iframe-editor

快速开始

默认使用 ew-code-editor,最简用法:

import { createEditor } from 'ew-iframe-editor';

const { iframe, destroy } = createEditor({
  requestUrl: './demo.html',
});

用法

通过 requestUrl 加载代码

import { createEditor, ewCodeEditorAdapter } from 'ew-iframe-editor';

createEditor({
  adapter: ewCodeEditorAdapter('https://ew-code-editor.eveningwater.com'),
  requestUrl: './demo.html',
});

直接传入代码内容

import { createEditor, ewCodeEditorAdapter } from 'ew-iframe-editor';

createEditor({
  adapter: ewCodeEditorAdapter(),
  code: {
    html: '<h1>Hello</h1>',
    css: 'h1 { color: red; }',
    js: 'console.log("hi");',
  },
});

指定挂载容器

createEditor({
  container: '#editor-container', // 或传入 HTMLElement
  requestUrl: './demo.html',
});

不传 container 时默认挂载到 document.body。

CDN 使用

<script src="https://unpkg.com/ew-iframe-editor/dist/index.global.js"></script>
<script>
  const { createEditor } = EwIframeEditor;
  createEditor({
    requestUrl: './demo.html',
  });
</script>

API

createEditor(options)

| 参数 | 类型 | 说明 | |---|---|---| | options.adapter | EditorAdapter | 编辑器适配器,默认 ew-code-editor | | options.requestUrl | string | 初始代码内容的请求地址(与 code 二选一) | | options.code | { html, css, js } | 直接传入代码内容(与 requestUrl 二选一,优先) | | options.iframeStyle | string | iframe 自定义 CSS | | options.container | HTMLElement \| string | 挂载容器,传入元素或选择器,默认 document.body | | options.parser | (content) => { html, css, js } | 自定义内容解析器 | | options.retryDelays | number[] | postMessage 重试延迟,默认 [0, 300, 800, 1500, 3000] | | options.onLoad | (iframe) => void | iframe 加载完成回调 | | options.onError | (error) => void | 加载失败回调 |

返回值:{ iframe: HTMLIFrameElement, destroy: () => void }

内置适配器

| 适配器 | 类型 | 说明 | |---|---|---| | ewCodeEditorAdapter(codeUrl?) | postMessage | ew-code-editor,默认地址 https://ew-code-editor.eveningwater.com |

自定义适配器

实现 EditorAdapter 接口即可支持任意编辑器:

import type { EditorAdapter, ParsedCode } from 'ew-iframe-editor';

class MyEditorAdapter implements EditorAdapter {
  name = 'my-editor';
  usesPostMessage = true; // 或 false(URL 参数型)

  getUrl(code: ParsedCode): string {
    return 'https://my-editor.com';
  }

  sendCode(iframe: HTMLIFrameElement, code: ParsedCode): void {
    iframe.contentWindow?.postMessage(code, '*');
  }
}

createEditor({
  adapter: new MyEditorAdapter(),
  requestUrl: './demo.html',
});

默认解析规则

如果不传入 parser,会从 requestUrl 返回的文本中提取以下标签内容:

<style>/* css 内容 */</style>
<html><!-- html 内容 --></html>
<script>// js 内容</script>

License

ISC