1.1.6 • Published 1 year ago

custom-editor v1.1.6

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

custom-editor

浏览器支持

不支持 IE; Edge >= 79;

能力

依赖 highligh.js 支持多种语言和主题;支持可编辑。

自主定制元素

custom-editor 属于 自主定制元素(Autonomous custom elements) ; 支持跨库组件应用;

支持跨模块应用

支持 AMD CommonJS Browser

快速应用

下载 custom-editor npm i custom-editor -S

非 vue 应用

 <raw-custom-editor 
     id="custom-editor" 
     value="select * from 'table'" 
     resize="true" 
  >
 </raw-custom-editor>
/** js */
import style from '!!css-loader?exportType=string!highlight.js/styles/sunburst.css';
import initCustomEditor from 'custom-editor/vue'; 
import javascript from 'highlight.js/lib/languages/javascript';

// 可定义元素名称
initCustomEditor({name: 'raw-custom-editor'});
let customEditor = document.getElementById("custom-editor");
customEditor.appendStyle(style);
customEditor.setLanguage('javascript', javascript);

vue 中应用

import {vue2Plugin} from 'custom-editor/vue';
Vue.use(vue2Plugin, {name: 'vue-custom-editor'});

属性及方法

属性

value:展示内容,或编辑初始化内容

readonly:设置只读 or 编辑

resize:设置拖可调整大小的类型 'auto', 'none', 'horizontal', 'vertical', (默认为 'none' 不支持拖拽); 若设置resize 属性,但属性设置为空或其他值,会自动默认设置 'auto'

width: 设置容器宽度(默认值为100%)

height:设置容器高度(默认值为100%)

其中 resize,height, width 的设置其实只是快捷操作, 可以对给该自定义组件设置样式 如:

 <!- 行内样式-->
 <raw-custom-editor 
    style="width:50%; height: 50%; resize: horizontal"
  >
 </raw-custom-editor>

或内部样式

 <style>
    raw-custom-editor {
        width:50%; 
        height: 50%; 
        resize: horizontal;
    }
 </style>

方法

appendStyle(styleCode): 参数为 style 样式字符串,用于添加样式,可用来添加主题,使用方式如下:

import style from '!!css-loader?exportType=string!highlight.js/styles/sunburst.css';
customEditor.appendStyle(style);

appendLink(href):参数为 link 的 href, 用于添加样式,可用来添加主题;

removeCss():删除通过 appendStyle 和 appendLink 的样式;

setLanguage(language, languageFn): 设置 language,使用方式如下:

import javascript from 'highlight.js/lib/languages/javascript';
customEditor.setLanguage('javascript', javascript);

未来规划

增加 web worker 匹配无阻塞;更丰富的样式注入,如支持 styleSheets;

1.1.6

1 year ago

1.1.5

1 year ago

1.1.4

1 year ago

1.1.1

2 years ago

1.0.2

2 years ago

1.1.0

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

1.0.0-alpha.19

2 years ago

1.1.3

2 years ago

1.0.0-alpha.9

2 years ago

1.1.2

2 years ago

1.0.3

2 years ago

1.0.0-alpha.8

2 years ago

1.0.0-alpha.7

2 years ago

1.0.0-alpha.6

2 years ago

1.0.0-alpha.10

2 years ago

1.0.0-alpha.5

2 years ago

1.0.0-alpha.4

2 years ago

1.0.0-alpha.3

2 years ago

1.0.0-alpha.2

2 years ago

1.0.0-alpha.1

2 years ago

1.0.0-alpha.16

2 years ago

1.0.0-alpha.15

2 years ago

1.0.0-alpha.18

2 years ago

1.0.0-alpha.17

2 years ago

1.0.0-alpha.12

2 years ago

1.0.0-alpha.11

2 years ago

1.0.0-alpha.14

2 years ago

1.0.0-alpha.13

2 years ago

1.0.0-alpha.21

2 years ago

1.0.0-alpha.20

2 years ago

1.0.0-alpha.23

2 years ago

1.0.0-alpha.22

2 years ago

1.0.0-alpha.24

2 years ago

19.0.0

4 years ago