chore: merge blocksuite source code (#9213)

This commit is contained in:
Mirone
2024-12-20 15:38:06 +08:00
committed by GitHub
parent 2c9ef916f4
commit 30200ff86d
2031 changed files with 238888 additions and 229 deletions

View File

@@ -0,0 +1,135 @@
import { RootBlockSchema } from '@blocksuite/affine-model';
import {
BlockHtmlAdapterExtension,
type BlockHtmlAdapterMatcher,
HastUtils,
} from '@blocksuite/affine-shared/adapters';
export const rootBlockHtmlAdapterMatcher: BlockHtmlAdapterMatcher = {
flavour: RootBlockSchema.model.flavour,
toMatch: o => HastUtils.isElement(o.node) && o.node.tagName === 'header',
fromMatch: o => o.node.flavour === RootBlockSchema.model.flavour,
toBlockSnapshot: {
enter: (o, context) => {
if (!HastUtils.isElement(o.node)) {
return;
}
const { walkerContext } = context;
if (o.node.tagName === 'header') {
walkerContext.skipAllChildren();
}
},
},
fromBlockSnapshot: {
enter: (_, context) => {
const { walkerContext } = context;
const htmlRootDocContext =
walkerContext.getGlobalContext('hast:html-root-doc');
const isRootDoc = htmlRootDocContext ?? true;
if (!isRootDoc) {
return;
}
walkerContext
.openNode(
{
type: 'element',
tagName: 'html',
properties: {},
children: [],
},
'children'
)
.openNode(
{
type: 'element',
tagName: 'head',
properties: {},
children: [],
},
'children'
)
.openNode(
{
type: 'element',
tagName: 'style',
properties: {},
children: [],
},
'children'
)
.openNode(
{
type: 'text',
value: `
input[type='checkbox'] {
display: none;
}
label:before {
background: rgb(30, 150, 235);
border-radius: 3px;
height: 16px;
width: 16px;
display: inline-block;
cursor: pointer;
}
input[type='checkbox'] + label:before {
content: '';
background: rgb(30, 150, 235);
color: #fff;
font-size: 16px;
line-height: 16px;
text-align: center;
}
input[type='checkbox']:checked + label:before {
content: '✓';
}
`.replace(/\s\s+/g, ''),
},
'children'
)
.closeNode()
.closeNode()
.closeNode()
.openNode(
{
type: 'element',
tagName: 'body',
properties: {},
children: [],
},
'children'
)
.openNode(
{
type: 'element',
tagName: 'div',
properties: {
style: 'width: 70vw; margin: 60px auto;',
},
children: [],
},
'children'
)
.openNode({
type: 'comment',
value: 'BlockSuiteDocTitlePlaceholder',
})
.closeNode();
},
leave: (_, context) => {
const { walkerContext } = context;
const htmlRootDocContext =
walkerContext.getGlobalContext('hast:html-root-doc');
const isRootDoc = htmlRootDocContext ?? true;
if (!isRootDoc) {
return;
}
walkerContext.closeNode().closeNode().closeNode();
},
},
};
export const RootBlockHtmlAdapterExtension = BlockHtmlAdapterExtension(
rootBlockHtmlAdapterMatcher
);

View File

@@ -0,0 +1,3 @@
export * from './html.js';
export * from './markdown.js';
export * from './notion-html.js';

View File

@@ -0,0 +1,36 @@
import { RootBlockSchema } from '@blocksuite/affine-model';
import {
BlockMarkdownAdapterExtension,
type BlockMarkdownAdapterMatcher,
} from '@blocksuite/affine-shared/adapters';
import type { DeltaInsert } from '@blocksuite/inline';
export const rootBlockMarkdownAdapterMatcher: BlockMarkdownAdapterMatcher = {
flavour: RootBlockSchema.model.flavour,
toMatch: () => false,
fromMatch: o => o.node.flavour === RootBlockSchema.model.flavour,
toBlockSnapshot: {},
fromBlockSnapshot: {
enter: (o, context) => {
const title = (o.node.props.title ?? { delta: [] }) as {
delta: DeltaInsert[];
};
const { walkerContext, deltaConverter } = context;
if (title.delta.length === 0) return;
walkerContext
.openNode(
{
type: 'heading',
depth: 1,
children: deltaConverter.deltaToAST(title.delta, 0),
},
'children'
)
.closeNode();
},
},
};
export const RootBlockMarkdownAdapterExtension = BlockMarkdownAdapterExtension(
rootBlockMarkdownAdapterMatcher
);

View File

@@ -0,0 +1,28 @@
import { RootBlockSchema } from '@blocksuite/affine-model';
import {
BlockNotionHtmlAdapterExtension,
type BlockNotionHtmlAdapterMatcher,
HastUtils,
} from '@blocksuite/affine-shared/adapters';
export const rootBlockNotionHtmlAdapterMatcher: BlockNotionHtmlAdapterMatcher =
{
flavour: RootBlockSchema.model.flavour,
toMatch: o => HastUtils.isElement(o.node) && o.node.tagName === 'header',
fromMatch: () => false,
toBlockSnapshot: {
enter: (o, context) => {
if (!HastUtils.isElement(o.node)) {
return;
}
const { walkerContext } = context;
if (o.node.tagName === 'header') {
walkerContext.skipAllChildren();
}
},
},
fromBlockSnapshot: {},
};
export const RootBlockNotionHtmlAdapterExtension =
BlockNotionHtmlAdapterExtension(rootBlockNotionHtmlAdapterMatcher);