mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-14 21:27:20 +00:00
feat(editor): simple table block (#9740)
close: BS-2122, BS-2125, BS-2124, BS-2420, PD-2073, BS-2126, BS-2469, BS-2470, BS-2478, BS-2471
This commit is contained in:
@@ -15,6 +15,8 @@ export function setupFormatBarAIEntry(formatBar: AffineFormatBarWidget) {
|
||||
{
|
||||
type: 'custom' as const,
|
||||
render(formatBar: AffineFormatBarWidget): TemplateResult | null {
|
||||
const richText = getRichText();
|
||||
if (richText?.dataset.disableAskAi !== undefined) return null;
|
||||
return html`
|
||||
<ask-ai-toolbar-button
|
||||
.host=${formatBar.host}
|
||||
@@ -28,3 +30,15 @@ export function setupFormatBarAIEntry(formatBar: AffineFormatBarWidget) {
|
||||
0
|
||||
);
|
||||
}
|
||||
const getRichText = () => {
|
||||
const selection = getSelection();
|
||||
if (!selection) return null;
|
||||
if (selection.rangeCount === 0) return null;
|
||||
const range = selection.getRangeAt(0);
|
||||
const commonAncestorContainer =
|
||||
range.commonAncestorContainer instanceof Element
|
||||
? range.commonAncestorContainer
|
||||
: range.commonAncestorContainer.parentElement;
|
||||
if (!commonAncestorContainer) return null;
|
||||
return commonAncestorContainer.closest('rich-text');
|
||||
};
|
||||
|
||||
@@ -22,6 +22,7 @@ import {
|
||||
ParagraphBlockSpec,
|
||||
RefNodeSlotsExtension,
|
||||
RichTextExtensions,
|
||||
TableBlockSpec,
|
||||
} from '@blocksuite/affine/blocks';
|
||||
import type { ExtensionType } from '@blocksuite/affine/store';
|
||||
|
||||
@@ -32,6 +33,7 @@ const CommonBlockSpecs: ExtensionType[] = [
|
||||
LatexBlockSpec,
|
||||
ListBlockSpec,
|
||||
DatabaseBlockSpec,
|
||||
TableBlockSpec,
|
||||
DataViewBlockSpec,
|
||||
DividerBlockSpec,
|
||||
EmbedExtensions,
|
||||
|
||||
Reference in New Issue
Block a user