* Fix/venus spanish (#423) fix: update venus spanish language Co-authored-by: DarkSky <25152247+darkskygit@users.noreply.github.com> * fix: can not convert url text to link after paste * fix: double link icon size error * feat(code): enhance markdown parse code * fix(code): add robust * fix: remove special menu * chore: clean code * fix: ime with command menu * fix(code): langs[lang] is not a function * fix: can't add image and delete more action button (#430) * feat: add zh_Hant for venus (#431) * fix: lang select in code block is insanity * GitHub Doc Updates (#421) * Update types-of-contributions.md * Update README.md Tidy up links section * fix: inline menu position (#433) Co-authored-by: DarkSky <25152247+darkskygit@users.noreply.github.com> Co-authored-by: QiShaoXuan <qishaoxuan777@gmail.com> Co-authored-by: tzhangchi <terry.zhangchi@outlook.com> Co-authored-by: lawvs <18554747+lawvs@users.noreply.github.com> Co-authored-by: DiamondThree <diamond.shx@gmail.com> Co-authored-by: CJSS <CJSS@users.noreply.github.com> Co-authored-by: Qi <474021214@qq.com>
156 lines
3.7 KiB
TypeScript
156 lines
3.7 KiB
TypeScript
import { Protocol } from '@toeverything/datasource/db-service';
|
|
import {
|
|
AsyncBlock,
|
|
BaseView,
|
|
BlockEditor,
|
|
CreateView,
|
|
HTML2BlockResult,
|
|
} from '@toeverything/framework/virgo';
|
|
import {
|
|
Block2HtmlProps,
|
|
commonBlock2HtmlContent,
|
|
commonHTML2block,
|
|
} from '../../utils/commonBlockClip';
|
|
import { TextView } from './TextView';
|
|
|
|
export class TextBlock extends BaseView {
|
|
type = Protocol.Block.Type.text;
|
|
|
|
View: (prop: CreateView) => JSX.Element = TextView;
|
|
|
|
override async onCreate(block: AsyncBlock): Promise<AsyncBlock> {
|
|
if (!block.getProperty('text')) {
|
|
await block.setProperty('text', {
|
|
value: [{ text: '' }],
|
|
});
|
|
}
|
|
return block;
|
|
}
|
|
|
|
override async html2block({
|
|
element,
|
|
editor,
|
|
}: {
|
|
element: Element;
|
|
editor: BlockEditor;
|
|
}): Promise<HTML2BlockResult> {
|
|
return commonHTML2block({
|
|
element,
|
|
editor,
|
|
type: this.type,
|
|
tagName: [
|
|
'DIV',
|
|
'P',
|
|
// 'PRE',
|
|
'B',
|
|
'A',
|
|
'EM',
|
|
'U',
|
|
// 'CODE',
|
|
'S',
|
|
'DEL',
|
|
],
|
|
});
|
|
}
|
|
}
|
|
|
|
export class Heading1Block extends BaseView {
|
|
type = Protocol.Block.Type.heading1;
|
|
|
|
View: (prop: CreateView) => JSX.Element = TextView;
|
|
|
|
override async onCreate(block: AsyncBlock): Promise<AsyncBlock> {
|
|
if (!block.getProperty('text')) {
|
|
await block.setProperty('text', {
|
|
value: [{ text: '' }],
|
|
});
|
|
}
|
|
return block;
|
|
}
|
|
override async html2block({
|
|
element,
|
|
editor,
|
|
}: {
|
|
element: Element;
|
|
editor: BlockEditor;
|
|
}): Promise<HTML2BlockResult> {
|
|
return commonHTML2block({
|
|
element,
|
|
editor,
|
|
type: this.type,
|
|
tagName: 'H1',
|
|
});
|
|
}
|
|
|
|
override async block2html(props: Block2HtmlProps) {
|
|
return `<h1>${await commonBlock2HtmlContent(props)}</h1>`;
|
|
}
|
|
}
|
|
|
|
export class Heading2Block extends BaseView {
|
|
type = Protocol.Block.Type.heading2;
|
|
|
|
View: (prop: CreateView) => JSX.Element = TextView;
|
|
|
|
override async onCreate(block: AsyncBlock): Promise<AsyncBlock> {
|
|
if (!block.getProperty('text')) {
|
|
await block.setProperty('text', {
|
|
value: [{ text: '' }],
|
|
});
|
|
}
|
|
return block;
|
|
}
|
|
override async html2block({
|
|
element,
|
|
editor,
|
|
}: {
|
|
element: Element;
|
|
editor: BlockEditor;
|
|
}): Promise<HTML2BlockResult> {
|
|
return commonHTML2block({
|
|
element,
|
|
editor,
|
|
type: this.type,
|
|
tagName: 'H2',
|
|
});
|
|
}
|
|
|
|
override async block2html(props: Block2HtmlProps) {
|
|
return `<h2>${await commonBlock2HtmlContent(props)}</h2>`;
|
|
}
|
|
}
|
|
|
|
export class Heading3Block extends BaseView {
|
|
type = Protocol.Block.Type.heading3;
|
|
|
|
View: (prop: CreateView) => JSX.Element = TextView;
|
|
|
|
override async onCreate(block: AsyncBlock): Promise<AsyncBlock> {
|
|
if (!block.getProperty('text')) {
|
|
await block.setProperty('text', {
|
|
value: [{ text: '' }],
|
|
});
|
|
}
|
|
return block;
|
|
}
|
|
|
|
override async html2block({
|
|
element,
|
|
editor,
|
|
}: {
|
|
element: Element;
|
|
editor: BlockEditor;
|
|
}): Promise<HTML2BlockResult> {
|
|
return commonHTML2block({
|
|
element,
|
|
editor,
|
|
type: this.type,
|
|
tagName: 'H3',
|
|
});
|
|
}
|
|
|
|
override async block2html(props: Block2HtmlProps) {
|
|
return `<h3>${await commonBlock2HtmlContent(props)}</h3>`;
|
|
}
|
|
}
|