diff --git a/src/main.js b/src/main.js index f1e7350c2641fedc9c05105854f6dcc13661ec3a..7ba079c4094dca44e663c8c05d2435bfc9741127 100644 --- a/src/main.js +++ b/src/main.js @@ -4,9 +4,10 @@ import Vtip from "vtip"; import "vtip/lib/index.min.css"; import { initStyle, setzIndex, isNotEmpty } from "@/assets/js/utils"; import "@/assets/style/global.less"; +import "@/assets/style/code/lightfair.less"; Vue.use(Vtip.directive); -function initMdEditor(obj) { +const initMdEditor = function (obj) { const _this = this; this.value = { text: "", @@ -110,7 +111,7 @@ function initMdEditor(obj) { onSubmit(val); }, upload({ val, type, callback }) { - onUpload(val, type, function(res) { + onUpload(val, type, function (res) { callback({ url: res, file: val @@ -119,13 +120,13 @@ function initMdEditor(obj) { }, renderLinks({ links, callback }) { if (!renderLinks) return callback(links); - renderLinks(links, function(res) { + renderLinks(links, function (res) { callback(res); }); }, queryUserList({ keyWord, callback }) { if (!queryUserList) return callback(false); // 返回false则不触发@弹窗 - queryUserList(keyWord, function(res) { + queryUserList(keyWord, function (res) { const list = res; if (!keyWord) return callback(list); callback( @@ -144,18 +145,18 @@ function initMdEditor(obj) { }) }).$mount(el); - this.getVideoList = function(callback) { + this.getVideoList = function (callback) { return this.vEl.$children[0].getVideoList(callback); }; - this.getValue = function(callback) { + this.getValue = function (callback) { if (callback) { callback(this.value); } return this.value; }; - this.setValue = function(val) { + this.setValue = function (val) { props.value = (val || "") + ""; this.vEl.$forceUpdate(); if (!props.setPreview) return; @@ -167,27 +168,27 @@ function initMdEditor(obj) { }); }; - this.focus = function() { + this.focus = function () { props.focus = true; this.vEl.$forceUpdate(); }; - this.blur = function() { + this.blur = function () { props.focus = false; this.vEl.$forceUpdate(); }; - this.disable = function() { + this.disable = function () { props.disabled = true; this.vEl.$forceUpdate(); }; - this.enable = function() { + this.enable = function () { props.disabled = false; this.vEl.$forceUpdate(); }; - this.registerTools = function(option) { + this.registerTools = function (option) { props.registerTools = []; if (Array.isArray(option)) { props.registerTools.push(...option); @@ -197,7 +198,7 @@ function initMdEditor(obj) { this.vEl.$forceUpdate(); }; - this.toggleTab = function(setPreview) { + this.toggleTab = function (setPreview) { if (setPreview !== "edit" && setPreview !== "preview") { props.setPreview = !props.setPreview; } else { @@ -207,7 +208,7 @@ function initMdEditor(obj) { this.vEl.$forceUpdate(); }; - this.toggleFullScreen = function(setFullScreen) { + this.toggleFullScreen = function (setFullScreen) { if (setFullScreen === undefined) { props.setFullScreen = !props.setFullScreen; } else { @@ -215,6 +216,8 @@ function initMdEditor(obj) { } this.vEl.$forceUpdate(); }; -} +}; window.MdEditor = initMdEditor; + +export default initMdEditor; diff --git a/webpack.config.js b/webpack.config.js index c22b5f83d156386feb6d7ea43035deff2593af82..e8ee15a986a6a3b572d057abd0a488c440d72294 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -2,14 +2,20 @@ const path = require("path"); const VueLoaderPlugin = require("vue-loader/lib/plugin"); module.exports = { entry: path.resolve(__dirname, "./src/main.js"), + experiments: { + outputModule: true + }, output: { filename: "markdown-editor.js", - path: path.resolve(__dirname, "public") + path: path.resolve(__dirname, "public"), + library: { + type: "module" + } }, devServer: { contentBase: path.resolve(__dirname, "public"), host: "0.0.0.0", - port: '80', + port: "80", // port: 443, // https: true, open: true