fix table delete

This commit is contained in:
Timi
2026-08-28 16:38:20 +08:00
parent b12cc2c243
commit b013d3b557
2 changed files with 106 additions and 17 deletions
@@ -1,5 +1,36 @@
<template>
<t-button v-popup="'插入表格'" :variant="active ? 'base' : 'text'" :theme="active ? 'light' : 'default'" @click="openPopup">
<t-popover
v-if="active"
v-model="actionVisible"
class="popover"
placement="bottom"
theme="light"
:show-arrow="false"
>
<t-button variant="base" theme="light">
<t-icon name="table" />
</t-button>
<template #content>
<div class="actions">
<t-button
class="action"
size="extra-small"
variant="text"
block
@click="onContinueInsert"
>继续插入</t-button>
<t-button
class="action"
size="extra-small"
variant="text"
theme="danger"
block
@click="onDeleteTable"
>删除表格</t-button>
</div>
</template>
</t-popover>
<t-button v-else v-popup="'插入表格'" variant="text" @click="openPopup">
<t-icon name="table" />
</t-button>
<bottom-popup
@@ -44,6 +75,7 @@ const props = defineProps<{
}>();
const visible = ref(false);
const actionVisible = ref(false);
const hoverRow = ref(1);
const hoverCol = ref(1);
@@ -68,6 +100,16 @@ function openPopup() {
visible.value = true;
}
function onContinueInsert() {
actionVisible.value = false;
openPopup();
}
function onDeleteTable() {
actionVisible.value = false;
props.editor?.chain().focus().deleteTable().run();
}
function onReset() {
hoverRow.value = 1;
hoverCol.value = 1;
@@ -83,41 +125,59 @@ function onSelect(row: number, col: number) {
return;
}
props.editor.chain().focus().insertTable({ rows: row, cols: col, withHeaderRow: true }).run();
visible.value = false;
}
watch(() => props.active, (active) => {
if (!active) {
actionVisible.value = false;
}
});
</script>
<style lang="less" scoped>
.table-picker {
width: min(20rem, calc(100vw - 2rem));
padding: 1rem 1rem calc(1rem + env(safe-area-inset-bottom));
padding: 0 1rem calc(1rem + env(safe-area-inset-bottom));
display: flex;
box-sizing: border-box;
background: var(--td-bg-color-container, #fff);
justify-content: center;
flex-direction: column;
.tip {
height: 1.5rem;
color: var(--td-text-color-secondary, #666);
font-size: .75rem;
text-align: center;
line-height: 1.5rem;
}
.grid {
gap: .125rem;
gap: .5rem;
width: fit-content;
display: grid;
margin: 0 auto;
grid-template-columns: repeat(7, 1fr);
}
.cell {
width: 1.75rem;
height: 1.75rem;
padding: 0;
border: 1px solid var(--td-component-border, #dcdcdc);
background: var(--td-bg-color-container, #fff);
.cell {
width: 2rem;
height: 2rem;
border: 1px solid var(--td-component-border, #dcdcdc);
padding: 0;
background: var(--td-bg-color-container, #fff);
&.active {
border-color: var(--td-brand-color, #0052d9);
background: var(--td-brand-color-light, #e0edff);
&.active {
border-color: var(--td-brand-color, #0052d9);
background: var(--td-brand-color-light, #e0edff);
}
}
}
}
.actions {
padding: 0 1rem;
.action {
height: 2rem !important;
}
}
</style>