1.1.18 • Published 3 months ago

gp-editorjs v1.1.18

Weekly downloads
-
License
MIT
Repository
-
Last release
3 months ago

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;
  }
} */
1.1.16

3 months ago

1.1.15

3 months ago

1.1.18

3 months ago

1.1.17

3 months ago

1.1.14

10 months ago

1.1.13

1 year ago

1.1.9

1 year ago

1.1.12

1 year ago

1.1.11

1 year ago

1.1.10

1 year ago

1.1.8

1 year ago

1.1.7

1 year ago

1.1.6

1 year ago

1.1.5

1 year ago

1.1.4

1 year ago

1.1.3

1 year ago

1.1.1

1 year ago

1.1.2

1 year ago

1.1.0

1 year ago

1.0.87

1 year ago

1.0.86

1 year ago

1.0.85

1 year ago

1.0.84

1 year ago

1.0.83

1 year ago

1.0.82

1 year ago

1.0.81

1 year ago

1.0.80

2 years ago

1.0.62

2 years ago

1.0.61

2 years ago

1.0.60

2 years ago

1.0.66

2 years ago

1.0.65

2 years ago

1.0.64

2 years ago

1.0.63

2 years ago

1.0.69

2 years ago

1.0.68

2 years ago

1.0.67

2 years ago

1.0.73

2 years ago

1.0.72

2 years ago

1.0.71

2 years ago

1.0.70

2 years ago

1.0.77

2 years ago

1.0.76

2 years ago

1.0.75

2 years ago

1.0.74

2 years ago

1.0.79

2 years ago

1.0.78

2 years ago

1.0.44

2 years ago

1.0.43

2 years ago

1.0.42

2 years ago

1.0.41

2 years ago

1.0.48

2 years ago

1.0.47

2 years ago

1.0.46

2 years ago

1.0.45

2 years ago

1.0.49

2 years ago

1.0.51

2 years ago

1.0.50

2 years ago

1.0.55

2 years ago

1.0.53

2 years ago

1.0.52

2 years ago

1.0.59

2 years ago

1.0.58

2 years ago

1.0.57

2 years ago

1.0.56

2 years ago

1.0.40

2 years ago

1.0.39

2 years ago

1.0.38

2 years ago

1.0.37

2 years ago

1.0.36

2 years ago

1.0.35

2 years ago

1.0.34

2 years ago

1.0.33

2 years ago

1.0.32

2 years ago

1.0.31

2 years ago

1.0.30

2 years ago

1.0.29

2 years ago

1.0.28

2 years ago

1.0.27

2 years ago

1.0.26

2 years ago

1.0.25

2 years ago

1.0.24

2 years ago

1.0.23

2 years ago

1.0.22

2 years ago

1.0.21

2 years ago

1.0.20

2 years ago

1.0.19

2 years ago

1.0.18

2 years ago

1.0.17

2 years ago

1.0.16

2 years ago

1.0.15

2 years ago

1.0.14

2 years ago

1.0.13

2 years ago

1.0.12

2 years ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

0.1.14

2 years ago

0.1.13

2 years ago

0.1.12

2 years ago

0.1.11

2 years ago

0.1.10

2 years ago

0.1.9

2 years ago

0.1.8

2 years ago

0.1.6

2 years ago

0.1.5

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.1

2 years ago

0.0.11

2 years ago

0.0.10

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago