mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-10 13:38:49 +08:00
16831e8c0e
Closes: BS-3215 Closes: BS-3218 Closes: BS-3217
105 lines
3.0 KiB
TypeScript
105 lines
3.0 KiB
TypeScript
import type { AffineTextAttributes } from '@blocksuite/affine-shared/types';
|
|
import {
|
|
type InlineRootElement,
|
|
InlineSpecExtension,
|
|
} from '@blocksuite/std/inline';
|
|
import type { ExtensionType } from '@blocksuite/store';
|
|
import { html } from 'lit';
|
|
import { z } from 'zod';
|
|
|
|
export type AffineInlineRootElement = InlineRootElement<AffineTextAttributes>;
|
|
|
|
export const BoldInlineSpecExtension =
|
|
InlineSpecExtension<AffineTextAttributes>({
|
|
name: 'bold',
|
|
schema: z.literal(true).optional().nullable().catch(undefined),
|
|
match: delta => {
|
|
return !!delta.attributes?.bold;
|
|
},
|
|
renderer: ({ delta }) => {
|
|
return html`<affine-text .delta=${delta}></affine-text>`;
|
|
},
|
|
});
|
|
|
|
export const ItalicInlineSpecExtension =
|
|
InlineSpecExtension<AffineTextAttributes>({
|
|
name: 'italic',
|
|
schema: z.literal(true).optional().nullable().catch(undefined),
|
|
match: delta => {
|
|
return !!delta.attributes?.italic;
|
|
},
|
|
renderer: ({ delta }) => {
|
|
return html`<affine-text .delta=${delta}></affine-text>`;
|
|
},
|
|
});
|
|
|
|
export const UnderlineInlineSpecExtension =
|
|
InlineSpecExtension<AffineTextAttributes>({
|
|
name: 'underline',
|
|
schema: z.literal(true).optional().nullable().catch(undefined),
|
|
match: delta => {
|
|
return !!delta.attributes?.underline;
|
|
},
|
|
renderer: ({ delta }) => {
|
|
return html`<affine-text .delta=${delta}></affine-text>`;
|
|
},
|
|
});
|
|
|
|
export const StrikeInlineSpecExtension =
|
|
InlineSpecExtension<AffineTextAttributes>({
|
|
name: 'strike',
|
|
schema: z.literal(true).optional().nullable().catch(undefined),
|
|
match: delta => {
|
|
return !!delta.attributes?.strike;
|
|
},
|
|
renderer: ({ delta }) => {
|
|
return html`<affine-text .delta=${delta}></affine-text>`;
|
|
},
|
|
});
|
|
|
|
export const CodeInlineSpecExtension =
|
|
InlineSpecExtension<AffineTextAttributes>({
|
|
name: 'code',
|
|
schema: z.literal(true).optional().nullable().catch(undefined),
|
|
match: delta => {
|
|
return !!delta.attributes?.code;
|
|
},
|
|
renderer: ({ delta }) => {
|
|
return html`<affine-text .delta=${delta}></affine-text>`;
|
|
},
|
|
});
|
|
|
|
export const BackgroundInlineSpecExtension =
|
|
InlineSpecExtension<AffineTextAttributes>({
|
|
name: 'background',
|
|
schema: z.string().optional().nullable().catch(undefined),
|
|
match: delta => {
|
|
return !!delta.attributes?.background;
|
|
},
|
|
renderer: ({ delta }) => {
|
|
return html`<affine-text .delta=${delta}></affine-text>`;
|
|
},
|
|
});
|
|
|
|
export const ColorInlineSpecExtension =
|
|
InlineSpecExtension<AffineTextAttributes>({
|
|
name: 'color',
|
|
schema: z.string().optional().nullable().catch(undefined),
|
|
match: delta => {
|
|
return !!delta.attributes?.color;
|
|
},
|
|
renderer: ({ delta }) => {
|
|
return html`<affine-text .delta=${delta}></affine-text>`;
|
|
},
|
|
});
|
|
|
|
export const InlineSpecExtensions: ExtensionType[] = [
|
|
BoldInlineSpecExtension,
|
|
ItalicInlineSpecExtension,
|
|
UnderlineInlineSpecExtension,
|
|
StrikeInlineSpecExtension,
|
|
CodeInlineSpecExtension,
|
|
BackgroundInlineSpecExtension,
|
|
ColorInlineSpecExtension,
|
|
];
|