UNPKG

fei-editor

Version:

基于vue的代码编辑器插件

3 lines (2 loc) • 3.99 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("vue"),require("brace")):"function"==typeof define&&define.amd?define(["exports","vue","brace"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).FeiEditor={},e.Vue,e.ace)}(this,function(e,t,o){"use strict";function a(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e)for(const o in e)if("default"!==o){const a=Object.getOwnPropertyDescriptor(e,o);Object.defineProperty(t,o,a.get?a:{enumerable:!0,get:()=>e[o]})}return t.default=e,Object.freeze(t)}const l=a(o),n=t.defineComponent({name:"FeiEditor",__name:"index",props:{modelValue:{},lang:{default:"json"},theme:{default:"chrome"},height:{default:"350"},width:{default:"100%"},fontSize:{default:12},options:{},readonly:{type:Boolean,default:!1},wrap:{type:Boolean,default:!1},snippets:{type:Boolean,default:!0},styles:{}},emits:["blur","focus","init","update:modelValue","change"],setup(e,{expose:o,emit:a}){const n=e,s=a,i=t.ref(null),u=t.ref(null),r=t.ref(""),c=t.computed(()=>({width:n.width?d(n.width):"100%",height:n.height?d(n.height):"100%",border:"1px solid #e8e8e8",...n.styles})),d=e=>/^\d*$/.test(e)?`${e}px`:e,f=e=>{u.value?.getSession().setMode("ace/mode/"+e)},p=e=>{s("focus",e)},v=e=>{s("blur",e)};return t.watch(()=>n.modelValue,e=>{if(r.value!==e&&u.value){const t=e||"";u.value.getSession().setValue(t,t.length),r.value=t}}),t.watch(()=>n.theme,e=>{u.value&&u.value.setTheme("ace/theme/"+e)}),t.watch(()=>n.lang,e=>{u.value&&u.value.getSession().setMode("ace/mode/"+e)}),t.watch(()=>n.options,e=>{u.value&&e&&u.value.setOptions(e)}),t.watch(()=>n.fontSize,e=>{u.value&&u.value.setFontSize(e)}),t.watch(()=>n.readonly,e=>{u.value&&u.value.setReadOnly(e)}),t.watch(()=>n.height,()=>{t.nextTick(()=>{u.value?.resize()})}),t.watch(()=>n.width,()=>{t.nextTick(()=>{u.value?.resize()})}),t.onBeforeUnmount(()=>{u.value&&(u.value.destroy(),u.value=null)}),t.onMounted(()=>{const e=i.value;if(!e)return;const t=l.edit(e);u.value=t,t.getSession().setMode("ace/mode/"+n.lang),t.setTheme("ace/theme/"+n.theme),t.$blockScrolling=1/0,t.setFontSize(n.fontSize),t.setReadOnly(n.readonly),t.getSession().setUseWrapMode(n.wrap),t.setShowPrintMargin(!1),t.getSession().setTabSize(2),t.setOptions({enableBasicAutocompletion:n.snippets,enableSnippets:n.snippets,enableLiveAutocompletion:n.snippets}),s("init",t),n.modelValue&&t.setValue(n.modelValue,-1),r.value=n.modelValue||"",t.on("change",function(){const e=t.getValue();s("update:modelValue",e),s("change",e),r.value=e}),t.on("focus",p),t.on("blur",v),n.options&&t.setOptions(n.options)}),o({getValue:()=>u.value?.getValue()||"",setValue:(e,t)=>{if(!u.value)return;const o=e||"";u.value.setValue(o,void 0===t?o.length:t),r.value=o},setTheme:e=>{u.value?.setTheme("ace/theme/"+e)},setLang:f,setMode:f,setReadOnly:e=>u.value?.setReadOnly(e),setFontSize:e=>u.value?.setFontSize(e),resize:()=>u.value?.resize(),destroy:()=>{u.value?.destroy(),u.value=null},focus:()=>{u.value?.focus()},blur:()=>{u.value?.blur()},getEditor:()=>u.value}),(e,o)=>(t.openBlock(),t.createElementBlock("div",{ref_key:"editorRef",ref:i,class:"fei-editor",style:t.normalizeStyle(c.value)},null,4))}});function s(e="default"){let t="";switch(e){case"primary":t="#1089ff";break;case"success":t="#52c41a";break;case"warning":t="#fa8c16";break;case"danger":t="#f5222d";break;case"default":t="#35495E";break;default:t=e}return t}const i=(e,t,o,a="primary",l="20px",n="#999")=>{console.log(`%c${e.toUpperCase()} %cV${t} ${o}`,`color: ${s(a)};font-weight: 500;font-size: ${l};font-family: Source Sans Pro,Helvetica Neue,Arial,sans-serif;`,`color: ${n};`)},u="fei-editor",r="0.0.3",c="https://ymf930.gitee.io/fei-editor/",d={version:r,install:function(e,t={}){return e.component(n.name||"FeiEditor",n),t.disabledDoc||i(u,r,c,"#722ed1"),e}};e.Editor=n,e.default=d,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}); //# sourceMappingURL=fei-editor.umd.js.map