UNPKG

fei-editor

Version:

基于vue的代码编辑器插件

3 lines (2 loc) • 3.75 kB
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("vue");function t(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e)for(const a in e)if("default"!==a){const o=Object.getOwnPropertyDescriptor(e,a);Object.defineProperty(t,a,o.get?o:{enumerable:!0,get:()=>e[a]})}return t.default=e,Object.freeze(t)}const a=t(require("brace")),o=e.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(t,{expose:o,emit:l}){const n=t,s=l,u=e.ref(null),i=e.ref(null),r=e.ref(""),c=e.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=>{i.value?.getSession().setMode("ace/mode/"+e)},p=e=>{s("focus",e)},v=e=>{s("blur",e)};return e.watch(()=>n.modelValue,e=>{if(r.value!==e&&i.value){const t=e||"";i.value.getSession().setValue(t,t.length),r.value=t}}),e.watch(()=>n.theme,e=>{i.value&&i.value.setTheme("ace/theme/"+e)}),e.watch(()=>n.lang,e=>{i.value&&i.value.getSession().setMode("ace/mode/"+e)}),e.watch(()=>n.options,e=>{i.value&&e&&i.value.setOptions(e)}),e.watch(()=>n.fontSize,e=>{i.value&&i.value.setFontSize(e)}),e.watch(()=>n.readonly,e=>{i.value&&i.value.setReadOnly(e)}),e.watch(()=>n.height,()=>{e.nextTick(()=>{i.value?.resize()})}),e.watch(()=>n.width,()=>{e.nextTick(()=>{i.value?.resize()})}),e.onBeforeUnmount(()=>{i.value&&(i.value.destroy(),i.value=null)}),e.onMounted(()=>{const e=u.value;if(!e)return;const t=a.edit(e);i.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:()=>i.value?.getValue()||"",setValue:(e,t)=>{if(!i.value)return;const a=e||"";i.value.setValue(a,void 0===t?a.length:t),r.value=a},setTheme:e=>{i.value?.setTheme("ace/theme/"+e)},setLang:f,setMode:f,setReadOnly:e=>i.value?.setReadOnly(e),setFontSize:e=>i.value?.setFontSize(e),resize:()=>i.value?.resize(),destroy:()=>{i.value?.destroy(),i.value=null},focus:()=>{i.value?.focus()},blur:()=>{i.value?.blur()},getEditor:()=>i.value}),(t,a)=>(e.openBlock(),e.createElementBlock("div",{ref_key:"editorRef",ref:u,class:"fei-editor",style:e.normalizeStyle(c.value)},null,4))}});function l(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 n=(e,t,a,o="primary",n="20px",s="#999")=>{console.log(`%c${e.toUpperCase()} %cV${t} ${a}`,`color: ${l(o)};font-weight: 500;font-size: ${n};font-family: Source Sans Pro,Helvetica Neue,Arial,sans-serif;`,`color: ${s};`)},s="fei-editor",u="0.0.3",i="https://ymf930.gitee.io/fei-editor/",r={version:u,install:function(e,t={}){return e.component(o.name||"FeiEditor",o),t.disabledDoc||n(s,u,i,"#722ed1"),e}};exports.Editor=o,exports.default=r; //# sourceMappingURL=fei-editor.cjs.js.map