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 🙏

© 2024 – Pkg Stats / Ryan Hefner

gp-editorjs

v1.1.14

Published

自定义块编辑器说明。

Downloads

26

Readme

GP 模块编辑器

自定义块编辑器说明。

使用

https://www.npmjs.com/package/gp-editorjs

文档

https://editorjs.io/base-concepts/

插件

https://github.com/editor-js/awesome-editorjs

依赖

目前依赖阿里图标,在使用的项目中,添加阿里图标库的引入

https://www.iconfont.cn/manage/index?spm=a313x.manage_type_mylikes.i1.db775f1f3.3f3e3a81JXSoHU&manage_type=myprojects&projectId=3524467


//at.alicdn.com/t/c/font_3524467_318htfu2kxc.css

/*
引入阿里图标样式
*/
@import url("https://at.alicdn.com/t/c/font_3524467_318htfu2kxc.css");

使用说明

// 1. 安装
// yarn add gp-editorjs

// 2. 引入 - 支持 TS
// import GPEditorJS from 'gp-editorjs'; // 原引入方式
// import 'gp-editorjs/dist/style.css'; // 原引入方式

import GPEditorJS, { OutputData } from 'gp-editorjs'; // 对应 "./dist/gp-editorjs.es.js"
import 'gp-editorjs/style.css'; // 对应 "./dist/style.css"

// 此方案不可以,预览时也是引入上述样式即可
// 2.1 使用预览显示的样式(渲染为 html 结构的样式)
// 使用 index.css
// import 'gp-editorjs/index.css';

// 3. 绑定
const editorVal = ref({});
const editorRef = ref();

// 4. 使用

// 简单使用
<GPEditorJS v-model="editorVal" ref="editorRef" />

// 自定义上传方法
<GPEditorJS v-model="editorVal" ref="editorRef" 
:linkEndpoint="linkEndpoint"
:uploadByFile="uploadByFile"
:uploadByImage="uploadByImage"
:uploadByImageUrl="uploadByImageUrl" />

// 只开启指定模块的功能
<GPEditorJS :enabled-tools="['header', 'image', 'list', 'checklist', 'table']" placeholder="请输入内容"
      v-model="editorVal" ref="editorRef2" />

// 显示内容
<textarea style="width: 100%;" :value="JSON.stringify(editorVal || {})" />

/* 上传文件 - 可选的配置(覆盖默认逻辑) */
const uploadByFile = async (file) => {
  console.log('file', file);
  var fdata1 = new FormData();
  fdata1.append('BussCode', '6000');
  fdata1.append('UserType', 'gp');
  fdata1.append('Date', formatToDate(new Date()));
  fdata1.append('Guid', buildUUID());
  fdata1.append('File', file);
  fdata1.append('Type', file.type);
  const res = await uploadFile(fdata1);
  return {
    success: 1,
    file: {
      url: res.url,
      // any other image data you want to store, such as width, height, color, extension, etc

      // 如果是附件
      title: "Hero",
      name: res.fileName,
      size: 91,
      extension: "jpg"
    },
  };
}

/* 上传图片 - 可选的配置(覆盖默认逻辑) */
const uploadByImage = async (file) => {
  console.log('file', file);
  var fdata1 = new FormData();
  fdata1.append('BussCode', '6000');
  fdata1.append('UserType', 'gp');
  fdata1.append('Date', formatToDate(new Date()));
  fdata1.append('Guid', buildUUID());
  fdata1.append('File', file);
  fdata1.append('Type', file.type);
  const res = await uploadFile(fdata1);
  return {
    success: 1,
    file: {
      url: res.url,
      // any other image data you want to store, such as width, height, color, extension, etc
    },
  };
}

/* 粘贴图片 url - 可选的配置(覆盖默认逻辑) */ 
const uploadByImageUrl = async (url) => {
  return {
    success: 1,
    file: {
      url: url,
      // any other image data you want to store, such as width, height, color, extension, etc
    }
  }
}

/* 插入自定义块 */
const onInsert = async () => {
  if (editorRef.value) {
   // param1 块名称
   // param2 块内容
    editorRef.value.received('image', {
      file: {
        url: 'https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png'
      },
      caption: '测试',
      withBackground: true,
    });
  }
}

// 链接抓取地址 - 可选的配置(覆盖默认逻辑)
// https://github.com/editor-js/link
const api = process.env.VUE_APP_API_BASE_URL;
const linkEndpoint = api + '/api/test/link'
/*
接口返回示例
{
    success = 0,
    meta = new
    {
        title = ex.Message,
        site_name = "CodeX",
        description = "Club of web-development, design and marketing. We build team learning how to build full-valued projects on the world market.",
        image = new
        {
            url = "https://codex.so/public/app/img/meta_img.png"
        }
    }
}
*/

包发布

npm run push

// or
npm run build
npm version patch
npm login
npm publish

模板

Vue 3 + TypeScript + Vite

npm init vite@latest gp-editorjs --template vue-ts

参考


/* 机构组件样式覆盖示例 */

/* .gp-school-link {
  @apply border p-2 m-3 flex flex-row rounded hover:bg-blue-50 text-gray-500 items-center justify-center bg-gray-50;
  img {
    @apply mr-2 w-[64px] h-[64px] shadow p-0.5 flex-none;
  }
  p {
    @apply flex flex-col flex-auto m-0;
  }
  .gp-school-link__title {
    @apply text-gray-600 font-bold;
  }
  .gp-school-link__desc {
    @apply text-blue-600;
  }
  .gp-school-link__tag-item {
    @apply px-1.5 py-0.5 mr-2 bg-blue-100 text-blue-500 text-xs rounded;
  }
} */