mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-22 00:37:05 +08:00
Compare commits
1 Commits
v0.26.3-be
...
flrande/fe
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e363ba5f4f |
13
blocksuite/affine/blocks/code/src/code-edgeless-block.ts
Normal file
13
blocksuite/affine/blocks/code/src/code-edgeless-block.ts
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
import { toGfxBlockComponent } from '@blocksuite/std';
|
||||||
|
|
||||||
|
import { CodeBlockComponent } from './code-block.js';
|
||||||
|
|
||||||
|
export class CodeEdgelessBlockComponent extends toGfxBlockComponent(
|
||||||
|
CodeBlockComponent
|
||||||
|
) {}
|
||||||
|
|
||||||
|
declare global {
|
||||||
|
interface HTMLElementTagNameMap {
|
||||||
|
'affine-edgeless-code': CodeEdgelessBlockComponent;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
import { CodeBlockComponent } from './code-block';
|
import { CodeBlockComponent } from './code-block';
|
||||||
|
import { CodeEdgelessBlockComponent } from './code-edgeless-block';
|
||||||
import {
|
import {
|
||||||
AFFINE_CODE_TOOLBAR_WIDGET,
|
AFFINE_CODE_TOOLBAR_WIDGET,
|
||||||
AffineCodeToolbarWidget,
|
AffineCodeToolbarWidget,
|
||||||
@@ -14,6 +15,7 @@ export function effects() {
|
|||||||
customElements.define(AFFINE_CODE_TOOLBAR_WIDGET, AffineCodeToolbarWidget);
|
customElements.define(AFFINE_CODE_TOOLBAR_WIDGET, AffineCodeToolbarWidget);
|
||||||
customElements.define('affine-code-unit', AffineCodeUnit);
|
customElements.define('affine-code-unit', AffineCodeUnit);
|
||||||
customElements.define('affine-code', CodeBlockComponent);
|
customElements.define('affine-code', CodeBlockComponent);
|
||||||
|
customElements.define('affine-edgeless-code', CodeEdgelessBlockComponent);
|
||||||
customElements.define('preview-button', PreviewButton);
|
customElements.define('preview-button', PreviewButton);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -41,7 +41,11 @@ export class CodeBlockViewExtension extends ViewExtensionProvider {
|
|||||||
context.register([
|
context.register([
|
||||||
FlavourExtension('affine:code'),
|
FlavourExtension('affine:code'),
|
||||||
CodeBlockHighlighter,
|
CodeBlockHighlighter,
|
||||||
BlockViewExtension('affine:code', literal`affine-code`),
|
BlockViewExtension('affine:code', model => {
|
||||||
|
return model.parent?.flavour === 'affine:surface'
|
||||||
|
? literal`affine-edgeless-code`
|
||||||
|
: literal`affine-code`;
|
||||||
|
}),
|
||||||
SlashMenuConfigExtension('affine:code', codeSlashMenuConfig),
|
SlashMenuConfigExtension('affine:code', codeSlashMenuConfig),
|
||||||
CodeKeymapExtension,
|
CodeKeymapExtension,
|
||||||
...getCodeClipboardExtensions(),
|
...getCodeClipboardExtensions(),
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ export const SurfaceBlockSchema = defineBlockSchema({
|
|||||||
'affine:attachment',
|
'affine:attachment',
|
||||||
'affine:embed-*',
|
'affine:embed-*',
|
||||||
'affine:edgeless-text',
|
'affine:edgeless-text',
|
||||||
|
'affine:code',
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
transformer: transformerConfigs =>
|
transformer: transformerConfigs =>
|
||||||
|
|||||||
@@ -1,3 +1,8 @@
|
|||||||
|
import {
|
||||||
|
type GfxCommonBlockProps,
|
||||||
|
GfxCompatible,
|
||||||
|
type GfxElementGeometry,
|
||||||
|
} from '@blocksuite/std/gfx';
|
||||||
import {
|
import {
|
||||||
BlockModel,
|
BlockModel,
|
||||||
BlockSchemaExtension,
|
BlockSchemaExtension,
|
||||||
@@ -14,7 +19,8 @@ type CodeBlockProps = {
|
|||||||
caption: string;
|
caption: string;
|
||||||
preview?: boolean;
|
preview?: boolean;
|
||||||
lineNumber?: boolean;
|
lineNumber?: boolean;
|
||||||
} & BlockMeta;
|
} & BlockMeta &
|
||||||
|
GfxCommonBlockProps;
|
||||||
|
|
||||||
export const CodeBlockSchema = defineBlockSchema({
|
export const CodeBlockSchema = defineBlockSchema({
|
||||||
flavour: 'affine:code',
|
flavour: 'affine:code',
|
||||||
@@ -30,6 +36,10 @@ export const CodeBlockSchema = defineBlockSchema({
|
|||||||
'meta:createdBy': undefined,
|
'meta:createdBy': undefined,
|
||||||
'meta:updatedAt': undefined,
|
'meta:updatedAt': undefined,
|
||||||
'meta:updatedBy': undefined,
|
'meta:updatedBy': undefined,
|
||||||
|
xywh: '[0,0,16,16]',
|
||||||
|
index: 'a0',
|
||||||
|
scale: 1,
|
||||||
|
rotate: 0,
|
||||||
}) as CodeBlockProps,
|
}) as CodeBlockProps,
|
||||||
metadata: {
|
metadata: {
|
||||||
version: 1,
|
version: 1,
|
||||||
@@ -39,6 +49,7 @@ export const CodeBlockSchema = defineBlockSchema({
|
|||||||
'affine:paragraph',
|
'affine:paragraph',
|
||||||
'affine:list',
|
'affine:list',
|
||||||
'affine:edgeless-text',
|
'affine:edgeless-text',
|
||||||
|
'affine:surface',
|
||||||
],
|
],
|
||||||
children: [],
|
children: [],
|
||||||
},
|
},
|
||||||
@@ -47,4 +58,6 @@ export const CodeBlockSchema = defineBlockSchema({
|
|||||||
|
|
||||||
export const CodeBlockSchemaExtension = BlockSchemaExtension(CodeBlockSchema);
|
export const CodeBlockSchemaExtension = BlockSchemaExtension(CodeBlockSchema);
|
||||||
|
|
||||||
export class CodeBlockModel extends BlockModel<CodeBlockProps> {}
|
export class CodeBlockModel
|
||||||
|
extends GfxCompatible<CodeBlockProps>(BlockModel)
|
||||||
|
implements GfxElementGeometry {}
|
||||||
|
|||||||
@@ -1087,7 +1087,8 @@ export class DragEventWatcher {
|
|||||||
} else if (
|
} else if (
|
||||||
block.flavour === 'affine:attachment' ||
|
block.flavour === 'affine:attachment' ||
|
||||||
block.flavour === 'affine:bookmark' ||
|
block.flavour === 'affine:bookmark' ||
|
||||||
block.flavour.startsWith('affine:embed-')
|
block.flavour.startsWith('affine:embed-') ||
|
||||||
|
block.flavour === 'affine:code'
|
||||||
) {
|
) {
|
||||||
const style = (block.props.style ?? 'vertical') as EmbedCardStyle;
|
const style = (block.props.style ?? 'vertical') as EmbedCardStyle;
|
||||||
block.props.style = style;
|
block.props.style = style;
|
||||||
@@ -1173,7 +1174,8 @@ export class DragEventWatcher {
|
|||||||
block.flavour === 'affine:image' ||
|
block.flavour === 'affine:image' ||
|
||||||
block.flavour === 'affine:attachment' ||
|
block.flavour === 'affine:attachment' ||
|
||||||
block.flavour === 'affine:bookmark' ||
|
block.flavour === 'affine:bookmark' ||
|
||||||
block.flavour.startsWith('affine:embed-')
|
block.flavour.startsWith('affine:embed-') ||
|
||||||
|
block.flavour === 'affine:code'
|
||||||
) {
|
) {
|
||||||
store.updateBlock(block.id, {
|
store.updateBlock(block.id, {
|
||||||
xywh: content[idx].props.xywh,
|
xywh: content[idx].props.xywh,
|
||||||
|
|||||||
Reference in New Issue
Block a user