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

@itshixun/qckeditor-plugin-select-resource

v1.0.0

Published

CKEditor 5 plugin for selecting and inserting resource files

Readme

@itshixun/qckeditor-plugin-select-resource

CKEditor 5 插件:资料文件引用。在编辑器中插入资源文件链接(PDF、MP4 等),支持预览或下载。

安装

npm install @itshixun/qckeditor-plugin-select-resource
# 或
pnpm add @itshixun/qckeditor-plugin-select-resource

依赖 ckeditor5(peerDependencies,需自行安装)。

基本使用

1. 引入样式

import '@itshixun/qckeditor-plugin-select-resource/dist/index.css';

2. 注册插件

import { ClassicEditor } from 'ckeditor5';
import { SelectResource } from '@itshixun/qckeditor-plugin-select-resource';

const editor = await ClassicEditor.create(element, {
  plugins: [
    // ... 其他插件
    SelectResource,
  ],
  toolbar: [
    // ... 其他按钮
    'selectResource',  // 工具栏按钮名称
  ],
  selectResource: {
    resources: [
      {
        name: '示例文档.pdf',
        value: 'https://example.com/files/doc.pdf',
        filetype: 'pdf',
        attachmentId: 'att-001',
      },
      {
        name: '示例视频.mp4',
        value: 'https://example.com/files/video.mp4',
        filetype: 'mp4',
        src: 'https://example.com/files/video.mp4',
        attachmentId: 'att-002',
      },
    ],
    previewTypes: ['pdf', 'image'],
  },
});

2. Vue 中使用

<script setup lang="ts">
import { ClassicEditor } from 'ckeditor5';
import { SelectResource } from '@itshixun/qckeditor-plugin-select-resource';

const config = {
  editor: ClassicEditor,
  plugins: [/* ... */, SelectResource],
  toolbar: ['bold', 'italic', 'selectResource'],
  selectResource: {
    resources: [
      { name: '文件1.pdf', value: '/f1.pdf', filetype: 'pdf' },
      { name: '视频.mp4', value: '/v1.mp4', filetype: 'mp4', src: '/v1.mp4' },
    ],
    previewTypes: ['pdf'],
  },
};
</script>

<template>
  <ckeditor :editor="config.editor" :config="config" />
</template>

配置项

| 属性 | 类型 | 必填 | 说明 | |------|------|------|------| | resources | ResourceItem[] | 是 | 资源文件列表,用于弹窗选择 | | previewTypes | string[] | 否 | 可预览文件类型,在新窗口打开。默认空数组(全部下载) |

ResourceItem

| 属性 | 类型 | 必填 | 说明 | |------|------|------|------| | name | string | 是 | 显示名称 | | value | string | 是 | 文件 URL(对应 <a>href) | | filetype | string | 是 | 文件类型标识,如 pdfmp4image | | src | string | 否 | 视频源地址(仅 mp4 类型需要) | | attachmentId | string | 否 | 附件唯一标识 |

输出 HTML

插件根据 filetype 输出不同的 HTML:

非 MP4 文件(如 PDF、图片等)

<!-- 预览类型(previewTypes 包含该类型) -->
<a class="ck-select-resource ck-select-resource-pdf"
   href="https://example.com/files/doc.pdf"
   title="示例文档.pdf"
   data-filetype="pdf"
   attachmentid="att-001"
   target="_blank">
   示例文档.pdf
</a>

<!-- 非预览类型 -->
<a class="ck-select-resource ck-select-resource-doc"
   href="https://example.com/files/doc.doc"
   title="文档.doc"
   data-filetype="doc"
   attachmentid="att-002"
   download="download">
   文档.doc
</a>

MP4 文件

<iframe class="ck-select-resource ck-select-resource-iframe"
        title="示例视频.mp4"
        href="https://example.com/files/video.mp4"
        src="https://example.com/files/video.mp4"
        data-filetype="mp4">
</iframe>

数据兼容性

插件在 upcast(粘贴/加载 HTML)时兼容两种历史格式:

| 新版本 | 旧版本 | |--------|--------| | <a class="ck-select-resource"> | <a class="ckedit-file"> | | <iframe class="ck-select-resource ck-select-resource-iframe"> | <iframe class="ckedit-file ckedit-file-iframe"> |

旧版 HTML 会被自动转换为新版数据模型,保存时输出新版格式。

类型支持

导入插件后,EditorConfig 类型自动扩展,TypeScript 可直接识别 selectResource 配置:

const config: EditorConfig = {
  // 无类型错误,selectResource 已声明
  selectResource: { resources: [...] },
};

导出 API

import {
  SelectResource,        // 主插件(Editing + UI)
  SelectResourceEditing, // 编辑插件(Schema + Conversion + Command)
  SelectResourceUI,      // UI 插件(工具栏按钮 + 弹窗)
  SelectResourceCommand, // 命令
  ResourceFormView,      // 弹窗视图
  insertResource,        // 工具函数:插入资源元素
  isResourceAllowed,     // 工具函数:检查是否允许插入
  type ResourceItem,
  type SelectResourceConfig,
  type SelectResourceCommandOptions,
} from '@itshixun/qckeditor-plugin-select-resource';