vue-shiki-monaco
Version:
一个封shiki和monaco-editor的Vue组件
98 lines (97 loc) • 3.39 kB
JavaScript
import { defineComponent, computed, createElementBlock, openBlock, normalizeClass, createElementVNode, toDisplayString, renderSlot } from "vue";
import { _ as _export_sfc } from "../../_plugin-vue_export-helper-1tPrXgE0.js";
import './index.css';const _hoisted_1 = { class: "default-toolbar" };
const _hoisted_2 = { class: "toolbar-left" };
const _hoisted_3 = { class: "file-info" };
const _hoisted_4 = { class: "file-name" };
const _hoisted_5 = { class: "file-language" };
const _hoisted_6 = { class: "toolbar-right" };
const _sfc_main = /* @__PURE__ */ defineComponent({
__name: "index",
props: {
currentLanguage: { default: "javascript" },
fileName: {},
showToolbar: { type: Boolean, default: true },
theme: { default: "vitesse-light" }
},
emits: ["copy", "format"],
setup(__props, { expose: __expose, emit: __emit }) {
const props = __props;
const emit = __emit;
const isDarkTheme = computed(() => {
return props.theme && props.theme.toLowerCase().includes("dark");
});
const themeClasses = computed(() => ({
"theme-light": !isDarkTheme.value,
"theme-dark": isDarkTheme.value
}));
const getFileName = () => {
const extensions = {
javascript: "main.js",
typescript: "main.ts",
python: "main.py",
html: "index.html",
css: "style.css",
json: "data.json"
};
return props.fileName || extensions[props.currentLanguage] || "untitled";
};
const handleCopy = () => {
emit("copy");
};
const handleFormat = () => {
emit("format");
};
__expose({
getFileName,
handleCopy,
handleFormat
});
return (_ctx, _cache) => {
return openBlock(), createElementBlock("div", {
class: normalizeClass(["editor-toolbar", themeClasses.value])
}, [
createElementVNode("div", _hoisted_1, [
createElementVNode("div", _hoisted_2, [
createElementVNode("div", _hoisted_3, [
createElementVNode("span", _hoisted_4, toDisplayString(getFileName()), 1),
createElementVNode("span", _hoisted_5, toDisplayString(_ctx.currentLanguage?.toUpperCase()), 1)
])
]),
createElementVNode("div", _hoisted_6, [
renderSlot(_ctx.$slots, "toolbar", {}, void 0, true),
createElementVNode("button", {
class: "toolbar-btn",
onClick: handleCopy,
title: "复制代码"
}, _cache[0] || (_cache[0] = [
createElementVNode("svg", {
width: "16",
height: "16",
viewBox: "0 0 24 24",
fill: "none",
stroke: "currentColor",
"stroke-width": "3"
}, [
createElementVNode("rect", {
x: "9",
y: "9",
width: "13",
height: "13",
rx: "2",
ry: "2"
}),
createElementVNode("path", { d: "M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1" })
], -1)
]))
])
])
], 2);
};
}
});
const MonacoHeader = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-402c9a54"]]);
export {
MonacoHeader as default
};
//# sourceMappingURL=index.js.map