refactor editor

This commit is contained in:
Timi
2026-08-25 17:35:42 +08:00
parent bc375e1b2d
commit 13bd61326d
40 changed files with 4444 additions and 55 deletions
@@ -0,0 +1,95 @@
<template>
<t-button v-popup="'代码块'" variant="outline" :theme="active ? 'primary' : 'default'" @click="openDialog">
<t-icon name="code" />
</t-button>
<t-popup
v-model="visible"
placement="bottom"
destroy-on-close
>
<div class="form-popup">
<div class="popup-head">
<span class="title">插入代码块</span>
<t-button shape="square" size="small" variant="text" title="关闭" @click="visible = false">
<t-icon name="close" />
</t-button>
</div>
<t-input v-model="codeLanguage" placeholder="代码语言,可留空" />
<div class="popup-actions">
<t-button variant="outline" block @click="visible = false">取消</t-button>
<t-button theme="primary" block @click="onConfirm">插入</t-button>
</div>
</div>
</t-popup>
</template>
<script lang="ts" setup>
import type { TiptapEditorInstance } from "timi-web/editor";
defineOptions({
name: "TiptapCodeBlockButton"
});
const props = defineProps<{
editor?: TiptapEditorInstance;
active: boolean;
}>();
const visible = ref(false);
const codeLanguage = ref("");
function openDialog() {
if (!props.editor) {
return;
}
codeLanguage.value = "";
visible.value = true;
}
function onConfirm() {
if (!props.editor) {
return;
}
const language = codeLanguage.value.trim();
if (language) {
props.editor.chain().focus().setCodeBlock({ language }).run();
} else {
props.editor.chain().focus().setCodeBlock().run();
}
visible.value = false;
}
</script>
<style lang="less" scoped>
.form-popup {
width: 100%;
max-height: 85vh;
padding: 1rem 1rem calc(1rem + env(safe-area-inset-bottom));
box-sizing: border-box;
overflow-y: auto;
background: var(--td-bg-color-container);
.popup-head {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 1rem;
.title {
font-size: 1rem;
font-weight: 600;
color: var(--td-text-color-primary, #000);
}
}
.popup-actions {
gap: .75rem;
display: flex;
margin-top: 1rem;
:deep(.t-button) {
flex: 1;
}
}
}
</style>