mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-09-22 03:33:06 +08:00
refactor(editor): unify directories naming (#11516)
**Directory Structure Changes** - Renamed multiple block-related directories by removing the "block-" prefix: - `block-attachment` → `attachment` - `block-bookmark` → `bookmark` - `block-callout` → `callout` - `block-code` → `code` - `block-data-view` → `data-view` - `block-database` → `database` - `block-divider` → `divider` - `block-edgeless-text` → `edgeless-text` - `block-embed` → `embed`
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
{
|
||||
"name": "@blocksuite/affine-block-divider",
|
||||
"description": "Divider block for BlockSuite.",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"build": "tsc"
|
||||
},
|
||||
"sideEffects": false,
|
||||
"keywords": [],
|
||||
"author": "toeverything",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@blocksuite/affine-components": "workspace:*",
|
||||
"@blocksuite/affine-model": "workspace:*",
|
||||
"@blocksuite/affine-shared": "workspace:*",
|
||||
"@blocksuite/global": "workspace:*",
|
||||
"@blocksuite/std": "workspace:*",
|
||||
"@blocksuite/store": "workspace:*",
|
||||
"@floating-ui/dom": "^1.6.13",
|
||||
"@lit/context": "^1.1.2",
|
||||
"@preact/signals-core": "^1.8.0",
|
||||
"@toeverything/theme": "^1.1.12",
|
||||
"@types/mdast": "^4.0.4",
|
||||
"lit": "^3.2.0",
|
||||
"minimatch": "^10.0.1",
|
||||
"rxjs": "^7.8.1",
|
||||
"zod": "^3.23.8"
|
||||
},
|
||||
"exports": {
|
||||
".": "./src/index.ts",
|
||||
"./effects": "./src/effects.ts"
|
||||
},
|
||||
"files": [
|
||||
"src",
|
||||
"dist",
|
||||
"!src/__tests__",
|
||||
"!dist/__tests__"
|
||||
],
|
||||
"version": "0.21.0"
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import type { ExtensionType } from '@blocksuite/store';
|
||||
|
||||
import { DividerBlockHtmlAdapterExtension } from './html.js';
|
||||
import { DividerBlockMarkdownAdapterExtension } from './markdown.js';
|
||||
import { DividerBlockNotionHtmlAdapterExtension } from './notion-html.js';
|
||||
import { DividerBlockPlainTextAdapterExtension } from './plain-text.js';
|
||||
|
||||
export const DividerBlockAdapterExtensions: ExtensionType[] = [
|
||||
DividerBlockHtmlAdapterExtension,
|
||||
DividerBlockMarkdownAdapterExtension,
|
||||
DividerBlockNotionHtmlAdapterExtension,
|
||||
DividerBlockPlainTextAdapterExtension,
|
||||
];
|
||||
@@ -0,0 +1,53 @@
|
||||
import { DividerBlockSchema } from '@blocksuite/affine-model';
|
||||
import {
|
||||
BlockHtmlAdapterExtension,
|
||||
type BlockHtmlAdapterMatcher,
|
||||
HastUtils,
|
||||
} from '@blocksuite/affine-shared/adapters';
|
||||
import { nanoid } from '@blocksuite/store';
|
||||
|
||||
export const dividerBlockHtmlAdapterMatcher: BlockHtmlAdapterMatcher = {
|
||||
flavour: DividerBlockSchema.model.flavour,
|
||||
toMatch: o => HastUtils.isElement(o.node) && o.node.tagName === 'hr',
|
||||
fromMatch: o => o.node.flavour === DividerBlockSchema.model.flavour,
|
||||
toBlockSnapshot: {
|
||||
enter: (o, context) => {
|
||||
if (!HastUtils.isElement(o.node)) {
|
||||
return;
|
||||
}
|
||||
const { walkerContext } = context;
|
||||
walkerContext
|
||||
.openNode(
|
||||
{
|
||||
type: 'block',
|
||||
id: nanoid(),
|
||||
flavour: 'affine:divider',
|
||||
props: {},
|
||||
children: [],
|
||||
},
|
||||
'children'
|
||||
)
|
||||
.closeNode();
|
||||
},
|
||||
},
|
||||
fromBlockSnapshot: {
|
||||
enter: (_, context) => {
|
||||
const { walkerContext } = context;
|
||||
walkerContext
|
||||
.openNode(
|
||||
{
|
||||
type: 'element',
|
||||
tagName: 'hr',
|
||||
properties: {},
|
||||
children: [],
|
||||
},
|
||||
'children'
|
||||
)
|
||||
.closeNode();
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export const DividerBlockHtmlAdapterExtension = BlockHtmlAdapterExtension(
|
||||
dividerBlockHtmlAdapterMatcher
|
||||
);
|
||||
@@ -0,0 +1,4 @@
|
||||
export * from './html.js';
|
||||
export * from './markdown.js';
|
||||
export * from './notion-html.js';
|
||||
export * from './plain-text.js';
|
||||
@@ -0,0 +1,50 @@
|
||||
import { DividerBlockSchema } from '@blocksuite/affine-model';
|
||||
import {
|
||||
BlockMarkdownAdapterExtension,
|
||||
type BlockMarkdownAdapterMatcher,
|
||||
type MarkdownAST,
|
||||
} from '@blocksuite/affine-shared/adapters';
|
||||
import { nanoid } from '@blocksuite/store';
|
||||
import type { ThematicBreak } from 'mdast';
|
||||
|
||||
const isDividerNode = (node: MarkdownAST): node is ThematicBreak =>
|
||||
node.type === 'thematicBreak';
|
||||
|
||||
export const dividerBlockMarkdownAdapterMatcher: BlockMarkdownAdapterMatcher = {
|
||||
flavour: DividerBlockSchema.model.flavour,
|
||||
toMatch: o => isDividerNode(o.node),
|
||||
fromMatch: o => o.node.flavour === DividerBlockSchema.model.flavour,
|
||||
toBlockSnapshot: {
|
||||
enter: (_, context) => {
|
||||
const { walkerContext } = context;
|
||||
walkerContext
|
||||
.openNode(
|
||||
{
|
||||
type: 'block',
|
||||
id: nanoid(),
|
||||
flavour: 'affine:divider',
|
||||
props: {},
|
||||
children: [],
|
||||
},
|
||||
'children'
|
||||
)
|
||||
.closeNode();
|
||||
},
|
||||
},
|
||||
fromBlockSnapshot: {
|
||||
enter: (_, context) => {
|
||||
const { walkerContext } = context;
|
||||
walkerContext
|
||||
.openNode(
|
||||
{
|
||||
type: 'thematicBreak',
|
||||
},
|
||||
'children'
|
||||
)
|
||||
.closeNode();
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export const DividerBlockMarkdownAdapterExtension =
|
||||
BlockMarkdownAdapterExtension(dividerBlockMarkdownAdapterMatcher);
|
||||
@@ -0,0 +1,38 @@
|
||||
import { DividerBlockSchema } from '@blocksuite/affine-model';
|
||||
import {
|
||||
BlockNotionHtmlAdapterExtension,
|
||||
type BlockNotionHtmlAdapterMatcher,
|
||||
HastUtils,
|
||||
} from '@blocksuite/affine-shared/adapters';
|
||||
import { nanoid } from '@blocksuite/store';
|
||||
|
||||
export const dividerBlockNotionHtmlAdapterMatcher: BlockNotionHtmlAdapterMatcher =
|
||||
{
|
||||
flavour: DividerBlockSchema.model.flavour,
|
||||
toMatch: o => HastUtils.isElement(o.node) && o.node.tagName === 'hr',
|
||||
fromMatch: () => false,
|
||||
toBlockSnapshot: {
|
||||
enter: (o, context) => {
|
||||
if (!HastUtils.isElement(o.node)) {
|
||||
return;
|
||||
}
|
||||
const { walkerContext } = context;
|
||||
walkerContext
|
||||
.openNode(
|
||||
{
|
||||
type: 'block',
|
||||
id: nanoid(),
|
||||
flavour: DividerBlockSchema.model.flavour,
|
||||
props: {},
|
||||
children: [],
|
||||
},
|
||||
'children'
|
||||
)
|
||||
.closeNode();
|
||||
},
|
||||
},
|
||||
fromBlockSnapshot: {},
|
||||
};
|
||||
|
||||
export const DividerBlockNotionHtmlAdapterExtension =
|
||||
BlockNotionHtmlAdapterExtension(dividerBlockNotionHtmlAdapterMatcher);
|
||||
@@ -0,0 +1,21 @@
|
||||
import { DividerBlockSchema } from '@blocksuite/affine-model';
|
||||
import {
|
||||
BlockPlainTextAdapterExtension,
|
||||
type BlockPlainTextAdapterMatcher,
|
||||
} from '@blocksuite/affine-shared/adapters';
|
||||
|
||||
export const dividerBlockPlainTextAdapterMatcher: BlockPlainTextAdapterMatcher =
|
||||
{
|
||||
flavour: DividerBlockSchema.model.flavour,
|
||||
toMatch: () => false,
|
||||
fromMatch: o => o.node.flavour === DividerBlockSchema.model.flavour,
|
||||
toBlockSnapshot: {},
|
||||
fromBlockSnapshot: {
|
||||
enter: (_, context) => {
|
||||
context.textBuffer.content += '---\n';
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export const DividerBlockPlainTextAdapterExtension =
|
||||
BlockPlainTextAdapterExtension(dividerBlockPlainTextAdapterMatcher);
|
||||
@@ -0,0 +1,50 @@
|
||||
import { CaptionedBlockComponent } from '@blocksuite/affine-components/caption';
|
||||
import type { DividerBlockModel } from '@blocksuite/affine-model';
|
||||
import { BLOCK_CHILDREN_CONTAINER_PADDING_LEFT } from '@blocksuite/affine-shared/consts';
|
||||
import { BlockSelection } from '@blocksuite/std';
|
||||
import { html } from 'lit';
|
||||
|
||||
import { dividerBlockStyles } from './styles.js';
|
||||
|
||||
export class DividerBlockComponent extends CaptionedBlockComponent<DividerBlockModel> {
|
||||
static override styles = dividerBlockStyles;
|
||||
|
||||
override connectedCallback() {
|
||||
super.connectedCallback();
|
||||
|
||||
this.contentEditable = 'false';
|
||||
|
||||
this.handleEvent('click', () => {
|
||||
this.host.selection.setGroup('note', [
|
||||
this.host.selection.create(BlockSelection, {
|
||||
blockId: this.blockId,
|
||||
}),
|
||||
]);
|
||||
});
|
||||
}
|
||||
|
||||
override renderBlock() {
|
||||
const children = html`<div
|
||||
class="affine-block-children-container"
|
||||
style="padding-left: ${BLOCK_CHILDREN_CONTAINER_PADDING_LEFT}px"
|
||||
>
|
||||
${this.renderChildren(this.model)}
|
||||
</div>`;
|
||||
|
||||
return html`
|
||||
<div class="affine-divider-block-container">
|
||||
<hr />
|
||||
|
||||
${children}
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
override accessor useZeroWidth = true;
|
||||
}
|
||||
|
||||
declare global {
|
||||
interface HTMLElementTagNameMap {
|
||||
'affine-divider': DividerBlockComponent;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import { BlockViewExtension } from '@blocksuite/std';
|
||||
import type { ExtensionType } from '@blocksuite/store';
|
||||
import { literal } from 'lit/static-html.js';
|
||||
|
||||
import { DividerBlockAdapterExtensions } from './adapters/extension.js';
|
||||
|
||||
export const DividerBlockSpec: ExtensionType[] = [
|
||||
BlockViewExtension('affine:divider', literal`affine-divider`),
|
||||
DividerBlockAdapterExtensions,
|
||||
].flat();
|
||||
@@ -0,0 +1,5 @@
|
||||
import { DividerBlockComponent } from './divider-block';
|
||||
|
||||
export function effects() {
|
||||
customElements.define('affine-divider', DividerBlockComponent);
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
export * from './adapters';
|
||||
export * from './divider-block';
|
||||
export * from './divider-spec';
|
||||
@@ -0,0 +1,19 @@
|
||||
import { css } from 'lit';
|
||||
|
||||
export const dividerBlockStyles = css`
|
||||
.affine-divider-block-container {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
height: 1px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
padding: 18px 8px;
|
||||
margin-top: var(--affine-paragraph-space);
|
||||
}
|
||||
.affine-divider-block-container hr {
|
||||
border: none;
|
||||
border-top: 1px solid var(--affine-divider-color);
|
||||
width: 100%;
|
||||
}
|
||||
`;
|
||||
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"extends": "../../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"rootDir": "./src",
|
||||
"outDir": "./dist",
|
||||
"tsBuildInfoFile": "./dist/tsconfig.tsbuildinfo"
|
||||
},
|
||||
"include": ["./src"],
|
||||
"references": [
|
||||
{ "path": "../../components" },
|
||||
{ "path": "../../model" },
|
||||
{ "path": "../../shared" },
|
||||
{ "path": "../../../framework/global" },
|
||||
{ "path": "../../../framework/std" },
|
||||
{ "path": "../../../framework/store" }
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user