mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-04 16:44:56 +00:00
Compare commits
19 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f64d62d869 | ||
|
|
1c6c2194c4 | ||
|
|
e3d681306c | ||
|
|
43adb85e7d | ||
|
|
e8aabed3fa | ||
|
|
b51de2ac4c | ||
|
|
597b631918 | ||
|
|
353eaf7fbe | ||
|
|
83915c2e90 | ||
|
|
8732801f06 | ||
|
|
9dc1b5e25b | ||
|
|
1e34ec8487 | ||
|
|
0f03c3fc5e | ||
|
|
7aba836dbe | ||
|
|
09427e846e | ||
|
|
adf14d11d5 | ||
|
|
7c41775c7f | ||
|
|
9c119e6505 | ||
|
|
887732179e |
45
blocksuite/affine/block-data-view/package.json
Normal file
45
blocksuite/affine/block-data-view/package.json
Normal file
@@ -0,0 +1,45 @@
|
||||
{
|
||||
"name": "@blocksuite/affine-block-data-view",
|
||||
"description": "Data view block for BlockSuite.",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"test:unit": "nx vite:test --run --passWithNoTests",
|
||||
"test:unit:coverage": "nx vite:test --run --coverage",
|
||||
"test:e2e": "playwright test"
|
||||
},
|
||||
"sideEffects": false,
|
||||
"keywords": [],
|
||||
"author": "toeverything",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@blocksuite/affine-block-database": "workspace:*",
|
||||
"@blocksuite/affine-components": "workspace:*",
|
||||
"@blocksuite/affine-model": "workspace:*",
|
||||
"@blocksuite/affine-shared": "workspace:*",
|
||||
"@blocksuite/block-std": "workspace:*",
|
||||
"@blocksuite/data-view": "workspace:*",
|
||||
"@blocksuite/global": "workspace:*",
|
||||
"@blocksuite/inline": "workspace:*",
|
||||
"@blocksuite/store": "workspace:*",
|
||||
"@floating-ui/dom": "^1.6.10",
|
||||
"@lit/context": "^1.1.2",
|
||||
"@preact/signals-core": "^1.8.0",
|
||||
"@toeverything/theme": "^1.1.3",
|
||||
"@types/mdast": "^4.0.4",
|
||||
"lit": "^3.2.0",
|
||||
"minimatch": "^10.0.1",
|
||||
"zod": "^3.23.8"
|
||||
},
|
||||
"exports": {
|
||||
".": "./src/index.ts",
|
||||
"./effects": "./src/effects.ts"
|
||||
},
|
||||
"files": [
|
||||
"src",
|
||||
"dist",
|
||||
"!src/__tests__",
|
||||
"!dist/__tests__"
|
||||
],
|
||||
"version": "0.19.0"
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
import { BlockRenderer, NoteRenderer } from '@blocksuite/affine-block-database';
|
||||
import type { NoteBlockComponent } from '@blocksuite/affine-block-note';
|
||||
import { CaptionedBlockComponent } from '@blocksuite/affine-components/caption';
|
||||
import {
|
||||
menu,
|
||||
@@ -13,12 +12,17 @@ import {
|
||||
} from '@blocksuite/affine-components/icons';
|
||||
import { PeekViewProvider } from '@blocksuite/affine-components/peek';
|
||||
import { toast } from '@blocksuite/affine-components/toast';
|
||||
import { NOTE_SELECTOR } from '@blocksuite/affine-shared/consts';
|
||||
import {
|
||||
DocModeProvider,
|
||||
NotificationProvider,
|
||||
type TelemetryEventMap,
|
||||
TelemetryProvider,
|
||||
} from '@blocksuite/affine-shared/services';
|
||||
import { RANGE_SYNC_EXCLUDE_ATTR } from '@blocksuite/block-std';
|
||||
import {
|
||||
type BlockComponent,
|
||||
RANGE_SYNC_EXCLUDE_ATTR,
|
||||
} from '@blocksuite/block-std';
|
||||
import {
|
||||
createRecordDetail,
|
||||
createUniComponentFromWebComponent,
|
||||
@@ -40,10 +44,6 @@ import { computed, signal } from '@preact/signals-core';
|
||||
import { css, nothing, unsafeCSS } from 'lit';
|
||||
import { html } from 'lit/static-html.js';
|
||||
|
||||
import {
|
||||
EdgelessRootBlockComponent,
|
||||
type RootService,
|
||||
} from '../root-block/index.js';
|
||||
import { BlockQueryDataSource } from './data-source.js';
|
||||
import type { DataViewBlockModel } from './data-view-model.js';
|
||||
|
||||
@@ -153,10 +153,6 @@ export class DataViewBlockComponent extends CaptionedBlockComponent<DataViewBloc
|
||||
};
|
||||
};
|
||||
|
||||
getRootService = () => {
|
||||
return this.std.getService<RootService>('affine:page');
|
||||
};
|
||||
|
||||
headerWidget: DataViewWidget = defineUniComponent(
|
||||
(props: DataViewWidgetProps) => {
|
||||
return html`
|
||||
@@ -230,9 +226,8 @@ export class DataViewBlockComponent extends CaptionedBlockComponent<DataViewBloc
|
||||
}
|
||||
|
||||
override get topContenteditableElement() {
|
||||
if (this.rootComponent instanceof EdgelessRootBlockComponent) {
|
||||
const note = this.closest<NoteBlockComponent>('affine-note');
|
||||
return note;
|
||||
if (this.std.get(DocModeProvider).getEditorMode() === 'edgeless') {
|
||||
return this.closest<BlockComponent>(NOTE_SELECTOR);
|
||||
}
|
||||
return this.rootComponent;
|
||||
}
|
||||
14
blocksuite/affine/block-data-view/src/effects.ts
Normal file
14
blocksuite/affine/block-data-view/src/effects.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { DataViewBlockComponent } from './data-view-block';
|
||||
import type { DataViewBlockModel } from './data-view-model';
|
||||
|
||||
export function effects() {
|
||||
customElements.define('affine-data-view', DataViewBlockComponent);
|
||||
}
|
||||
|
||||
declare global {
|
||||
namespace BlockSuite {
|
||||
interface BlockModels {
|
||||
'affine:data-view': DataViewBlockModel;
|
||||
}
|
||||
}
|
||||
}
|
||||
3
blocksuite/affine/block-data-view/src/index.ts
Normal file
3
blocksuite/affine/block-data-view/src/index.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export * from './data-view-block.js';
|
||||
export * from './data-view-model.js';
|
||||
export * from './data-view-spec.js';
|
||||
29
blocksuite/affine/block-data-view/tsconfig.json
Normal file
29
blocksuite/affine/block-data-view/tsconfig.json
Normal file
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"extends": "../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"rootDir": "./src/",
|
||||
"outDir": "./dist/",
|
||||
"noEmit": false
|
||||
},
|
||||
"include": ["./src"],
|
||||
"references": [
|
||||
{
|
||||
"path": "../../framework"
|
||||
},
|
||||
{
|
||||
"path": "../model"
|
||||
},
|
||||
{
|
||||
"path": "../components"
|
||||
},
|
||||
{
|
||||
"path": "../shared"
|
||||
},
|
||||
{
|
||||
"path": "../data-view"
|
||||
},
|
||||
{
|
||||
"path": "../block-database"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
import type { ExtensionType } from '@blocksuite/block-std';
|
||||
|
||||
import { EmbedSyncedDocBlockHtmlAdapterExtension } from './html.js';
|
||||
import { EmbedSyncedDocBlockMarkdownAdapterExtension } from './markdown.js';
|
||||
import { EmbedSyncedDocMarkdownAdapterExtension } from './markdown.js';
|
||||
import { EmbedSyncedDocBlockPlainTextAdapterExtension } from './plain-text.js';
|
||||
|
||||
export const EmbedSyncedDocBlockAdapterExtensions: ExtensionType[] = [
|
||||
EmbedSyncedDocBlockHtmlAdapterExtension,
|
||||
EmbedSyncedDocBlockMarkdownAdapterExtension,
|
||||
EmbedSyncedDocMarkdownAdapterExtension,
|
||||
EmbedSyncedDocBlockPlainTextAdapterExtension,
|
||||
];
|
||||
|
||||
@@ -60,5 +60,5 @@ export const embedSyncedDocBlockMarkdownAdapterMatcher: BlockMarkdownAdapterMatc
|
||||
},
|
||||
};
|
||||
|
||||
export const EmbedSyncedDocBlockMarkdownAdapterExtension =
|
||||
export const EmbedSyncedDocMarkdownAdapterExtension =
|
||||
BlockMarkdownAdapterExtension(embedSyncedDocBlockMarkdownAdapterMatcher);
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
"exports": {
|
||||
".": "./src/index.ts",
|
||||
"./ai-item": "./src/ai-item/index.ts",
|
||||
"./color-picker": "./src/color-picker/index.ts",
|
||||
"./icons": "./src/icons/index.ts",
|
||||
"./peek": "./src/peek/index.ts",
|
||||
"./portal": "./src/portal/index.ts",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { EditorMenuButton } from '@blocksuite/affine-components/toolbar';
|
||||
import type { ColorScheme, Palette } from '@blocksuite/affine-model';
|
||||
import { resolveColor } from '@blocksuite/affine-model';
|
||||
import type { ColorEvent } from '@blocksuite/affine-shared/utils';
|
||||
import { WithDisposable } from '@blocksuite/global/utils';
|
||||
import { html, LitElement } from 'lit';
|
||||
import { property, query, state } from 'lit/decorators.js';
|
||||
@@ -8,7 +8,7 @@ import { choose } from 'lit/directives/choose.js';
|
||||
import { ifDefined } from 'lit/directives/if-defined.js';
|
||||
import { styleMap } from 'lit/directives/style-map.js';
|
||||
|
||||
import type { ColorEvent } from '../panel/color-panel.js';
|
||||
import type { EditorMenuButton } from '../toolbar/menu-button.js';
|
||||
import type { ModeType, PickColorEvent, PickColorType } from './types.js';
|
||||
import { keepColor, preprocessColor, rgbaToHex8 } from './utils.js';
|
||||
|
||||
20
blocksuite/affine/components/src/color-picker/index.ts
Normal file
20
blocksuite/affine/components/src/color-picker/index.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { EdgelessColorPickerButton } from './button.js';
|
||||
import { EdgelessColorPicker } from './color-picker.js';
|
||||
import { EdgelessColorCustomButton } from './custom-button.js';
|
||||
|
||||
export * from './button.js';
|
||||
export * from './color-picker.js';
|
||||
export * from './types.js';
|
||||
export * from './utils.js';
|
||||
|
||||
export function effects() {
|
||||
customElements.define('edgeless-color-picker', EdgelessColorPicker);
|
||||
customElements.define(
|
||||
'edgeless-color-picker-button',
|
||||
EdgelessColorPickerButton
|
||||
);
|
||||
customElements.define(
|
||||
'edgeless-color-custom-button',
|
||||
EdgelessColorCustomButton
|
||||
);
|
||||
}
|
||||
@@ -26,7 +26,7 @@ const styles = css`
|
||||
background: var(--affine-tooltip);
|
||||
|
||||
overflow-wrap: anywhere;
|
||||
white-space: pre-wrap;
|
||||
white-space: normal;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
import type { FromSnapshotPayload, SnapshotNode } from '@blocksuite/store';
|
||||
import type {
|
||||
BlockSnapshotLeaf,
|
||||
FromSnapshotPayload,
|
||||
SnapshotNode,
|
||||
ToSnapshotPayload,
|
||||
} from '@blocksuite/store';
|
||||
import { BaseBlockTransformer } from '@blocksuite/store';
|
||||
|
||||
import type { AttachmentBlockProps } from './attachment-model.js';
|
||||
@@ -14,4 +19,16 @@ export class AttachmentBlockTransformer extends BaseBlockTransformer<AttachmentB
|
||||
|
||||
return snapshotRet;
|
||||
}
|
||||
|
||||
override toSnapshot(
|
||||
snapshot: ToSnapshotPayload<AttachmentBlockProps>
|
||||
): BlockSnapshotLeaf {
|
||||
const snapshotRet = super.toSnapshot(snapshot);
|
||||
const sourceId = snapshot.model.sourceId;
|
||||
if (sourceId) {
|
||||
const pathBlobIdMap = snapshot.assets.getPathBlobIdMap();
|
||||
pathBlobIdMap.set(snapshot.model.id, sourceId);
|
||||
}
|
||||
return snapshotRet;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
import type { FromSnapshotPayload, SnapshotNode } from '@blocksuite/store';
|
||||
import type {
|
||||
BlockSnapshotLeaf,
|
||||
FromSnapshotPayload,
|
||||
SnapshotNode,
|
||||
ToSnapshotPayload,
|
||||
} from '@blocksuite/store';
|
||||
import { BaseBlockTransformer } from '@blocksuite/store';
|
||||
|
||||
import type { ImageBlockProps } from './image-model.js';
|
||||
@@ -14,4 +19,16 @@ export class ImageBlockTransformer extends BaseBlockTransformer<ImageBlockProps>
|
||||
|
||||
return snapshotRet;
|
||||
}
|
||||
|
||||
override toSnapshot(
|
||||
snapshot: ToSnapshotPayload<ImageBlockProps>
|
||||
): BlockSnapshotLeaf {
|
||||
const snapshotRet = super.toSnapshot(snapshot);
|
||||
const sourceId = snapshot.model.sourceId;
|
||||
if (sourceId) {
|
||||
const pathBlobIdMap = snapshot.assets.getPathBlobIdMap();
|
||||
pathBlobIdMap.set(snapshot.model.id, sourceId);
|
||||
}
|
||||
return snapshotRet;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,9 +28,21 @@
|
||||
"lit": "^3.2.0",
|
||||
"lodash.clonedeep": "^4.5.0",
|
||||
"lodash.mergewith": "^4.6.2",
|
||||
"mdast-util-gfm-autolink-literal": "^2.0.1",
|
||||
"mdast-util-gfm-strikethrough": "^2.0.0",
|
||||
"mdast-util-gfm-table": "^2.0.0",
|
||||
"mdast-util-gfm-task-list-item": "^2.0.0",
|
||||
"micromark-extension-gfm-autolink-literal": "^2.1.0",
|
||||
"micromark-extension-gfm-strikethrough": "^2.1.0",
|
||||
"micromark-extension-gfm-table": "^2.1.0",
|
||||
"micromark-extension-gfm-task-list-item": "^2.1.0",
|
||||
"micromark-util-combine-extensions": "^2.0.0",
|
||||
"minimatch": "^10.0.1",
|
||||
"rehype-parse": "^9.0.0",
|
||||
"rehype-stringify": "^10.0.0",
|
||||
"remark-math": "^6.0.0",
|
||||
"remark-parse": "^11.0.0",
|
||||
"remark-stringify": "^11.0.0",
|
||||
"unified": "^11.0.5",
|
||||
"zod": "^3.23.8"
|
||||
},
|
||||
|
||||
@@ -20,11 +20,16 @@ export {
|
||||
BlockMarkdownAdapterExtension,
|
||||
type BlockMarkdownAdapterMatcher,
|
||||
BlockMarkdownAdapterMatcherIdentifier,
|
||||
InlineDeltaToMarkdownAdapterExtension,
|
||||
type InlineDeltaToMarkdownAdapterMatcher,
|
||||
InlineDeltaToMarkdownAdapterMatcherIdentifier,
|
||||
isMarkdownAST,
|
||||
type Markdown,
|
||||
MarkdownAdapter,
|
||||
MarkdownAdapterFactoryExtension,
|
||||
MarkdownAdapterFactoryIdentifier,
|
||||
type MarkdownAST,
|
||||
MarkdownASTToDeltaExtension,
|
||||
type MarkdownASTToDeltaMatcher,
|
||||
MarkdownASTToDeltaMatcherIdentifier,
|
||||
MarkdownDeltaConverter,
|
||||
|
||||
@@ -52,7 +52,7 @@ function gfmToMarkdown() {
|
||||
}
|
||||
|
||||
export function remarkGfm(this: Processor) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
||||
// oxlint-disable-next-line typescript/no-this-alias
|
||||
const self = this;
|
||||
const data = self.data();
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
export * from './block-adapter.js';
|
||||
export * from './delta-converter.js';
|
||||
export * from './markdown.js';
|
||||
export * from './type.js';
|
||||
|
||||
@@ -1,14 +1,6 @@
|
||||
import { DefaultTheme, NoteDisplayMode } from '@blocksuite/affine-model';
|
||||
import {
|
||||
type AdapterContext,
|
||||
AdapterFactoryIdentifier,
|
||||
type BlockMarkdownAdapterMatcher,
|
||||
BlockMarkdownAdapterMatcherIdentifier,
|
||||
type Markdown,
|
||||
type MarkdownAST,
|
||||
MarkdownDeltaConverter,
|
||||
} from '@blocksuite/affine-shared/adapters';
|
||||
import type { ExtensionType } from '@blocksuite/block-std';
|
||||
import type { ServiceProvider } from '@blocksuite/global/di';
|
||||
import {
|
||||
type AssetsManager,
|
||||
ASTWalker,
|
||||
@@ -34,10 +26,18 @@ import remarkParse from 'remark-parse';
|
||||
import remarkStringify from 'remark-stringify';
|
||||
import { unified } from 'unified';
|
||||
|
||||
import { defaultBlockMarkdownAdapterMatchers } from './block-matcher.js';
|
||||
import { inlineDeltaToMarkdownAdapterMatchers } from './delta-converter/inline-delta.js';
|
||||
import { markdownInlineToDeltaMatchers } from './delta-converter/markdown-inline.js';
|
||||
import { remarkGfm } from './gfm.js';
|
||||
import { type AdapterContext, AdapterFactoryIdentifier } from '../types';
|
||||
import {
|
||||
type BlockMarkdownAdapterMatcher,
|
||||
BlockMarkdownAdapterMatcherIdentifier,
|
||||
} from './block-adapter';
|
||||
import {
|
||||
InlineDeltaToMarkdownAdapterMatcherIdentifier,
|
||||
MarkdownASTToDeltaMatcherIdentifier,
|
||||
MarkdownDeltaConverter,
|
||||
} from './delta-converter';
|
||||
import { remarkGfm } from './gfm';
|
||||
import type { Markdown, MarkdownAST } from './type';
|
||||
|
||||
type MarkdownToSliceSnapshotPayload = {
|
||||
file: Markdown;
|
||||
@@ -164,11 +164,20 @@ export class MarkdownAdapter extends BaseAdapter<Markdown> {
|
||||
|
||||
deltaConverter: MarkdownDeltaConverter;
|
||||
|
||||
constructor(
|
||||
job: Job,
|
||||
readonly blockMatchers: BlockMarkdownAdapterMatcher[] = defaultBlockMarkdownAdapterMatchers
|
||||
) {
|
||||
readonly blockMatchers: BlockMarkdownAdapterMatcher[];
|
||||
|
||||
constructor(job: Job, provider: ServiceProvider) {
|
||||
super(job);
|
||||
const blockMatchers = Array.from(
|
||||
provider.getAll(BlockMarkdownAdapterMatcherIdentifier).values()
|
||||
);
|
||||
const inlineDeltaToMarkdownAdapterMatchers = Array.from(
|
||||
provider.getAll(InlineDeltaToMarkdownAdapterMatcherIdentifier).values()
|
||||
);
|
||||
const markdownInlineToDeltaMatchers = Array.from(
|
||||
provider.getAll(MarkdownASTToDeltaMatcherIdentifier).values()
|
||||
);
|
||||
this.blockMatchers = blockMatchers;
|
||||
this.deltaConverter = new MarkdownDeltaConverter(
|
||||
job.adapterConfigs,
|
||||
inlineDeltaToMarkdownAdapterMatchers,
|
||||
@@ -440,13 +449,7 @@ export const MarkdownAdapterFactoryIdentifier =
|
||||
export const MarkdownAdapterFactoryExtension: ExtensionType = {
|
||||
setup: di => {
|
||||
di.addImpl(MarkdownAdapterFactoryIdentifier, provider => ({
|
||||
get: (job: Job) =>
|
||||
new MarkdownAdapter(
|
||||
job,
|
||||
Array.from(
|
||||
provider.getAll(BlockMarkdownAdapterMatcherIdentifier).values()
|
||||
)
|
||||
),
|
||||
get: (job: Job) => new MarkdownAdapter(job, provider),
|
||||
}));
|
||||
},
|
||||
};
|
||||
@@ -1,3 +1,4 @@
|
||||
import type { Palette } from '@blocksuite/affine-model';
|
||||
import { IS_IOS, IS_MAC } from '@blocksuite/global/env';
|
||||
|
||||
export function isTouchPadPinchEvent(e: WheelEvent) {
|
||||
@@ -347,3 +348,19 @@ export const createKeydownObserver = ({
|
||||
// Fix composition input
|
||||
target.addEventListener('compositionend', () => onInput?.(true), { signal });
|
||||
};
|
||||
|
||||
export class ColorEvent extends Event {
|
||||
detail: Palette;
|
||||
|
||||
constructor(
|
||||
type: string,
|
||||
{
|
||||
detail,
|
||||
composed,
|
||||
bubbles,
|
||||
}: { detail: Palette; composed: boolean; bubbles: boolean }
|
||||
) {
|
||||
super(type, { bubbles, composed });
|
||||
this.detail = detail;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
"@blocksuite/affine-block-attachment": "workspace:*",
|
||||
"@blocksuite/affine-block-bookmark": "workspace:*",
|
||||
"@blocksuite/affine-block-code": "workspace:*",
|
||||
"@blocksuite/affine-block-data-view": "workspace:*",
|
||||
"@blocksuite/affine-block-database": "workspace:*",
|
||||
"@blocksuite/affine-block-divider": "workspace:*",
|
||||
"@blocksuite/affine-block-edgeless-text": "workspace:*",
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import { DefaultTheme, NoteDisplayMode } from '@blocksuite/affine-model';
|
||||
import { MarkdownAdapter } from '@blocksuite/affine-shared/adapters';
|
||||
import { Container } from '@blocksuite/global/di';
|
||||
import type {
|
||||
BlockSnapshot,
|
||||
DocSnapshot,
|
||||
@@ -8,11 +10,24 @@ import type {
|
||||
import { AssetsManager, MemoryBlobCRUD } from '@blocksuite/store';
|
||||
import { describe, expect, test } from 'vitest';
|
||||
|
||||
import { MarkdownAdapter } from '../../_common/adapters/markdown/index.js';
|
||||
import { inlineDeltaToMarkdownAdapterMatchers } from '../../_common/adapters/markdown/delta-converter/inline-delta.js';
|
||||
import { markdownInlineToDeltaMatchers } from '../../_common/adapters/markdown/delta-converter/markdown-inline.js';
|
||||
import { defaultBlockMarkdownAdapterMatchers } from '../../_common/adapters/markdown/index.js';
|
||||
import { nanoidReplacement } from '../../_common/test-utils/test-utils.js';
|
||||
import { embedSyncedDocMiddleware } from '../../_common/transformers/middlewares.js';
|
||||
import { createJob } from '../utils/create-job.js';
|
||||
|
||||
const container = new Container();
|
||||
[
|
||||
...markdownInlineToDeltaMatchers,
|
||||
...defaultBlockMarkdownAdapterMatchers,
|
||||
...inlineDeltaToMarkdownAdapterMatchers,
|
||||
].forEach(ext => {
|
||||
ext.setup(container);
|
||||
});
|
||||
|
||||
const provider = container.provider();
|
||||
|
||||
describe('snapshot to markdown', () => {
|
||||
test('code', async () => {
|
||||
const blockSnapshot: BlockSnapshot = {
|
||||
@@ -71,7 +86,7 @@ describe('snapshot to markdown', () => {
|
||||
|
||||
const markdown = '```python\nimport this\n```\n';
|
||||
|
||||
const mdAdapter = new MarkdownAdapter(createJob());
|
||||
const mdAdapter = new MarkdownAdapter(createJob(), provider);
|
||||
const target = await mdAdapter.fromBlockSnapshot({
|
||||
snapshot: blockSnapshot,
|
||||
});
|
||||
@@ -270,7 +285,7 @@ describe('snapshot to markdown', () => {
|
||||
hhh
|
||||
`;
|
||||
|
||||
const mdAdapter = new MarkdownAdapter(createJob());
|
||||
const mdAdapter = new MarkdownAdapter(createJob(), provider);
|
||||
const target = await mdAdapter.fromBlockSnapshot({
|
||||
snapshot: blockSnapshot,
|
||||
});
|
||||
@@ -418,7 +433,7 @@ hhh
|
||||
* eee
|
||||
`;
|
||||
|
||||
const mdAdapter = new MarkdownAdapter(createJob());
|
||||
const mdAdapter = new MarkdownAdapter(createJob(), provider);
|
||||
const target = await mdAdapter.fromBlockSnapshot({
|
||||
snapshot: blockSnapshot,
|
||||
});
|
||||
@@ -567,7 +582,7 @@ hhh
|
||||
* [ ] eee
|
||||
`;
|
||||
|
||||
const mdAdapter = new MarkdownAdapter(createJob());
|
||||
const mdAdapter = new MarkdownAdapter(createJob(), provider);
|
||||
const target = await mdAdapter.fromBlockSnapshot({
|
||||
snapshot: blockSnapshot,
|
||||
});
|
||||
@@ -710,7 +725,7 @@ hhh
|
||||
2. ddd
|
||||
`;
|
||||
|
||||
const mdAdapter = new MarkdownAdapter(createJob());
|
||||
const mdAdapter = new MarkdownAdapter(createJob(), provider);
|
||||
const target = await mdAdapter.fromBlockSnapshot({
|
||||
snapshot: blockSnapshot,
|
||||
});
|
||||
@@ -874,7 +889,7 @@ hhh
|
||||
2. eee
|
||||
`;
|
||||
|
||||
const mdAdapter = new MarkdownAdapter(createJob());
|
||||
const mdAdapter = new MarkdownAdapter(createJob(), provider);
|
||||
const target = await mdAdapter.fromBlockSnapshot({
|
||||
snapshot: blockSnapshot,
|
||||
});
|
||||
@@ -946,7 +961,7 @@ hhh
|
||||
};
|
||||
const markdown = 'aaa `bbb` ccc\n';
|
||||
|
||||
const mdAdapter = new MarkdownAdapter(createJob());
|
||||
const mdAdapter = new MarkdownAdapter(createJob(), provider);
|
||||
const target = await mdAdapter.fromBlockSnapshot({
|
||||
snapshot: blockSnapshot,
|
||||
});
|
||||
@@ -1018,7 +1033,7 @@ hhh
|
||||
};
|
||||
const markdown = 'inline $E=mc^2$ latex\n';
|
||||
|
||||
const mdAdapter = new MarkdownAdapter(createJob());
|
||||
const mdAdapter = new MarkdownAdapter(createJob(), provider);
|
||||
const target = await mdAdapter.fromBlockSnapshot({
|
||||
snapshot: blockSnapshot,
|
||||
});
|
||||
@@ -1074,7 +1089,7 @@ hhh
|
||||
|
||||
const markdown = '$$\nE=mc^2\n$$\n';
|
||||
|
||||
const mdAdapter = new MarkdownAdapter(createJob());
|
||||
const mdAdapter = new MarkdownAdapter(createJob(), provider);
|
||||
const target = await mdAdapter.fromBlockSnapshot({
|
||||
snapshot: blockSnapshot,
|
||||
});
|
||||
@@ -1146,7 +1161,7 @@ hhh
|
||||
};
|
||||
const markdown = 'aaa [bbb](https://affine.pro/) ccc\n';
|
||||
|
||||
const mdAdapter = new MarkdownAdapter(createJob());
|
||||
const mdAdapter = new MarkdownAdapter(createJob(), provider);
|
||||
const target = await mdAdapter.fromBlockSnapshot({
|
||||
snapshot: blockSnapshot,
|
||||
});
|
||||
@@ -1215,7 +1230,7 @@ hhh
|
||||
};
|
||||
const markdown = 'aaa https://affine.pro/ \n';
|
||||
|
||||
const mdAdapter = new MarkdownAdapter(createJob());
|
||||
const mdAdapter = new MarkdownAdapter(createJob(), provider);
|
||||
const target = await mdAdapter.fromBlockSnapshot({
|
||||
snapshot: blockSnapshot,
|
||||
});
|
||||
@@ -1288,7 +1303,7 @@ hhh
|
||||
|
||||
const markdown = 'aaa**bbb**ccc\n';
|
||||
|
||||
const mdAdapter = new MarkdownAdapter(createJob());
|
||||
const mdAdapter = new MarkdownAdapter(createJob(), provider);
|
||||
const target = await mdAdapter.fromBlockSnapshot({
|
||||
snapshot: blockSnapshot,
|
||||
});
|
||||
@@ -1361,7 +1376,7 @@ hhh
|
||||
|
||||
const markdown = 'aaa*bbb*ccc\n';
|
||||
|
||||
const mdAdapter = new MarkdownAdapter(createJob());
|
||||
const mdAdapter = new MarkdownAdapter(createJob(), provider);
|
||||
const target = await mdAdapter.fromBlockSnapshot({
|
||||
snapshot: blockSnapshot,
|
||||
});
|
||||
@@ -1437,7 +1452,7 @@ hhh
|
||||
const markdown =
|
||||
'\n\n';
|
||||
|
||||
const mdAdapter = new MarkdownAdapter(createJob());
|
||||
const mdAdapter = new MarkdownAdapter(createJob(), provider);
|
||||
const blobCRUD = new MemoryBlobCRUD();
|
||||
await blobCRUD.set(
|
||||
'YXXTjRmLlNyiOUnHb8nAIvUP6V7PAXhwW9F5_tc2LGs=',
|
||||
@@ -1670,7 +1685,7 @@ hhh
|
||||
| Task 1 | TODO | 2023-12-15 | 1 | 65 | test1,test2 | [test2](https://google.com) | https://google.com | true |
|
||||
| Task 2 | In Progress | 2023-12-20 | | | | test1 | | |
|
||||
`;
|
||||
const mdAdapter = new MarkdownAdapter(createJob());
|
||||
const mdAdapter = new MarkdownAdapter(createJob(), provider);
|
||||
const target = await mdAdapter.fromBlockSnapshot({
|
||||
snapshot: blockSnapshot,
|
||||
});
|
||||
@@ -1920,7 +1935,7 @@ hhh
|
||||
adapterConfigs.set('title:deadbeef', 'test');
|
||||
adapterConfigs.set('docLinkBaseUrl', 'https://example.com');
|
||||
};
|
||||
const mdAdapter = new MarkdownAdapter(createJob([middleware]));
|
||||
const mdAdapter = new MarkdownAdapter(createJob([middleware]), provider);
|
||||
const target = await mdAdapter.fromBlockSnapshot({
|
||||
snapshot: blockSnapshot,
|
||||
});
|
||||
@@ -2327,7 +2342,7 @@ World!
|
||||
await job.snapshotToDoc(syncedDocSnapshot);
|
||||
await job.snapshotToDoc(docSnapShot);
|
||||
|
||||
const mdAdapter = new MarkdownAdapter(job);
|
||||
const mdAdapter = new MarkdownAdapter(job, provider);
|
||||
const target = await mdAdapter.fromDocSnapshot({
|
||||
snapshot: docSnapShot,
|
||||
});
|
||||
@@ -2371,7 +2386,7 @@ describe('markdown to snapshot', () => {
|
||||
],
|
||||
};
|
||||
|
||||
const mdAdapter = new MarkdownAdapter(createJob());
|
||||
const mdAdapter = new MarkdownAdapter(createJob(), provider);
|
||||
const rawBlockSnapshot = await mdAdapter.toBlockSnapshot({
|
||||
file: markdown,
|
||||
});
|
||||
@@ -2420,7 +2435,7 @@ describe('markdown to snapshot', () => {
|
||||
pageId: '',
|
||||
};
|
||||
|
||||
const mdAdapter = new MarkdownAdapter(createJob());
|
||||
const mdAdapter = new MarkdownAdapter(createJob(), provider);
|
||||
const rawSliceSnapshot = await mdAdapter.toSliceSnapshot({
|
||||
file: markdown,
|
||||
workspaceId: '',
|
||||
@@ -2471,7 +2486,7 @@ describe('markdown to snapshot', () => {
|
||||
pageId: '',
|
||||
};
|
||||
|
||||
const mdAdapter = new MarkdownAdapter(createJob());
|
||||
const mdAdapter = new MarkdownAdapter(createJob(), provider);
|
||||
const rawSliceSnapshot = await mdAdapter.toSliceSnapshot({
|
||||
file: markdown,
|
||||
workspaceId: '',
|
||||
@@ -2522,7 +2537,7 @@ describe('markdown to snapshot', () => {
|
||||
pageId: '',
|
||||
};
|
||||
|
||||
const mdAdapter = new MarkdownAdapter(createJob());
|
||||
const mdAdapter = new MarkdownAdapter(createJob(), provider);
|
||||
const rawSliceSnapshot = await mdAdapter.toSliceSnapshot({
|
||||
file: markdown,
|
||||
workspaceId: '',
|
||||
@@ -2700,7 +2715,7 @@ hhh
|
||||
],
|
||||
};
|
||||
|
||||
const mdAdapter = new MarkdownAdapter(createJob());
|
||||
const mdAdapter = new MarkdownAdapter(createJob(), provider);
|
||||
const rawBlockSnapshot = await mdAdapter.toBlockSnapshot({
|
||||
file: markdown,
|
||||
});
|
||||
@@ -2836,7 +2851,7 @@ hhh
|
||||
],
|
||||
};
|
||||
|
||||
const mdAdapter = new MarkdownAdapter(createJob());
|
||||
const mdAdapter = new MarkdownAdapter(createJob(), provider);
|
||||
const rawBlockSnapshot = await mdAdapter.toBlockSnapshot({
|
||||
file: markdown,
|
||||
});
|
||||
@@ -2972,7 +2987,7 @@ hhh
|
||||
],
|
||||
};
|
||||
|
||||
const mdAdapter = new MarkdownAdapter(createJob());
|
||||
const mdAdapter = new MarkdownAdapter(createJob(), provider);
|
||||
const rawBlockSnapshot = await mdAdapter.toBlockSnapshot({
|
||||
file: markdown,
|
||||
});
|
||||
@@ -3081,7 +3096,7 @@ bbb
|
||||
],
|
||||
};
|
||||
|
||||
const mdAdapter = new MarkdownAdapter(createJob());
|
||||
const mdAdapter = new MarkdownAdapter(createJob(), provider);
|
||||
const rawBlockSnapshot = await mdAdapter.toBlockSnapshot({
|
||||
file: markdown,
|
||||
});
|
||||
@@ -3131,7 +3146,7 @@ bbb
|
||||
],
|
||||
};
|
||||
|
||||
const mdAdapter = new MarkdownAdapter(createJob());
|
||||
const mdAdapter = new MarkdownAdapter(createJob(), provider);
|
||||
const rawBlockSnapshot = await mdAdapter.toBlockSnapshot({
|
||||
file: markdown,
|
||||
});
|
||||
@@ -3186,7 +3201,7 @@ bbb
|
||||
pageId: '',
|
||||
};
|
||||
|
||||
const mdAdapter = new MarkdownAdapter(createJob());
|
||||
const mdAdapter = new MarkdownAdapter(createJob(), provider);
|
||||
const rawSliceSnapshot = await mdAdapter.toSliceSnapshot({
|
||||
file: markdown,
|
||||
workspaceId: '',
|
||||
@@ -3238,7 +3253,7 @@ bbb
|
||||
],
|
||||
};
|
||||
|
||||
const mdAdapter = new MarkdownAdapter(createJob());
|
||||
const mdAdapter = new MarkdownAdapter(createJob(), provider);
|
||||
const rawBlockSnapshot = await mdAdapter.toBlockSnapshot({
|
||||
file: markdown,
|
||||
});
|
||||
@@ -3288,7 +3303,7 @@ bbb
|
||||
],
|
||||
};
|
||||
|
||||
const mdAdapter = new MarkdownAdapter(createJob());
|
||||
const mdAdapter = new MarkdownAdapter(createJob(), provider);
|
||||
const rawBlockSnapshot = await mdAdapter.toBlockSnapshot({
|
||||
file: markdown,
|
||||
});
|
||||
@@ -3339,7 +3354,7 @@ bbb
|
||||
],
|
||||
};
|
||||
|
||||
const mdAdapter = new MarkdownAdapter(createJob());
|
||||
const mdAdapter = new MarkdownAdapter(createJob(), provider);
|
||||
const rawBlockSnapshot = await mdAdapter.toBlockSnapshot({
|
||||
file: markdown,
|
||||
});
|
||||
@@ -3390,7 +3405,7 @@ bbb
|
||||
],
|
||||
};
|
||||
|
||||
const mdAdapter = new MarkdownAdapter(createJob());
|
||||
const mdAdapter = new MarkdownAdapter(createJob(), provider);
|
||||
const rawBlockSnapshot = await mdAdapter.toBlockSnapshot({
|
||||
file: markdown,
|
||||
});
|
||||
@@ -3511,7 +3526,7 @@ bbb
|
||||
],
|
||||
};
|
||||
|
||||
const mdAdapter = new MarkdownAdapter(createJob());
|
||||
const mdAdapter = new MarkdownAdapter(createJob(), provider);
|
||||
const rawBlockSnapshot = await mdAdapter.toBlockSnapshot({
|
||||
file: markdown,
|
||||
});
|
||||
@@ -3553,7 +3568,7 @@ bbb
|
||||
],
|
||||
};
|
||||
|
||||
const mdAdapter = new MarkdownAdapter(createJob());
|
||||
const mdAdapter = new MarkdownAdapter(createJob(), provider);
|
||||
const rawBlockSnapshot = await mdAdapter.toBlockSnapshot({
|
||||
file: markdown,
|
||||
});
|
||||
@@ -3603,7 +3618,7 @@ bbb
|
||||
],
|
||||
};
|
||||
|
||||
const mdAdapter = new MarkdownAdapter(createJob());
|
||||
const mdAdapter = new MarkdownAdapter(createJob(), provider);
|
||||
const rawBlockSnapshot = await mdAdapter.toBlockSnapshot({
|
||||
file: markdown,
|
||||
});
|
||||
@@ -3637,7 +3652,7 @@ bbb
|
||||
],
|
||||
};
|
||||
|
||||
const mdAdapter = new MarkdownAdapter(createJob());
|
||||
const mdAdapter = new MarkdownAdapter(createJob(), provider);
|
||||
const rawBlockSnapshot = await mdAdapter.toBlockSnapshot({
|
||||
file: markdown,
|
||||
});
|
||||
@@ -3835,7 +3850,7 @@ hhh
|
||||
const middleware: JobMiddleware = ({ adapterConfigs }) => {
|
||||
adapterConfigs.set('docLinkBaseUrl', 'https://example.com');
|
||||
};
|
||||
const mdAdapter = new MarkdownAdapter(createJob([middleware]));
|
||||
const mdAdapter = new MarkdownAdapter(createJob([middleware]), provider);
|
||||
const rawBlockSnapshot = await mdAdapter.toBlockSnapshot({
|
||||
file: markdown,
|
||||
});
|
||||
|
||||
@@ -1,8 +1,22 @@
|
||||
import { Container } from '@blocksuite/global/di';
|
||||
import { DocCollection, Schema } from '@blocksuite/store';
|
||||
import { describe, expect, test } from 'vitest';
|
||||
|
||||
import { defaultBlockMarkdownAdapterMatchers } from '../../_common/adapters/index.js';
|
||||
import { inlineDeltaToMarkdownAdapterMatchers } from '../../_common/adapters/markdown/delta-converter/inline-delta.js';
|
||||
import { markdownInlineToDeltaMatchers } from '../../_common/adapters/markdown/delta-converter/markdown-inline.js';
|
||||
import { markdownToMindmap } from '../../surface-block/mini-mindmap/mindmap-preview.js';
|
||||
|
||||
const container = new Container();
|
||||
[
|
||||
...markdownInlineToDeltaMatchers,
|
||||
...defaultBlockMarkdownAdapterMatchers,
|
||||
...inlineDeltaToMarkdownAdapterMatchers,
|
||||
].forEach(ext => {
|
||||
ext.setup(container);
|
||||
});
|
||||
const provider = container.provider();
|
||||
|
||||
describe('markdownToMindmap: convert markdown list to a mind map tree', () => {
|
||||
test('basic case', () => {
|
||||
const markdown = `
|
||||
@@ -15,7 +29,7 @@ describe('markdownToMindmap: convert markdown list to a mind map tree', () => {
|
||||
const collection = new DocCollection({ schema: new Schema() });
|
||||
collection.meta.initialize();
|
||||
const doc = collection.createDoc();
|
||||
const nodes = markdownToMindmap(markdown, doc);
|
||||
const nodes = markdownToMindmap(markdown, doc, provider);
|
||||
|
||||
expect(nodes).toEqual({
|
||||
text: 'Text A',
|
||||
@@ -53,7 +67,7 @@ describe('markdownToMindmap: convert markdown list to a mind map tree', () => {
|
||||
const collection = new DocCollection({ schema: new Schema() });
|
||||
collection.meta.initialize();
|
||||
const doc = collection.createDoc();
|
||||
const nodes = markdownToMindmap(markdown, doc);
|
||||
const nodes = markdownToMindmap(markdown, doc, provider);
|
||||
|
||||
expect(nodes).toEqual({
|
||||
text: 'Text A',
|
||||
@@ -85,7 +99,7 @@ describe('markdownToMindmap: convert markdown list to a mind map tree', () => {
|
||||
const collection = new DocCollection({ schema: new Schema() });
|
||||
collection.meta.initialize();
|
||||
const doc = collection.createDoc();
|
||||
const nodes = markdownToMindmap(markdown, doc);
|
||||
const nodes = markdownToMindmap(markdown, doc, provider);
|
||||
|
||||
expect(nodes).toEqual(null);
|
||||
});
|
||||
|
||||
@@ -2,6 +2,7 @@ import {
|
||||
AttachmentAdapterFactoryExtension,
|
||||
HtmlAdapterFactoryExtension,
|
||||
ImageAdapterFactoryExtension,
|
||||
MarkdownAdapterFactoryExtension,
|
||||
NotionHtmlAdapterFactoryExtension,
|
||||
NotionTextAdapterFactoryExtension,
|
||||
PlainTextAdapterFactoryExtension,
|
||||
@@ -10,7 +11,8 @@ import type { ExtensionType } from '@blocksuite/block-std';
|
||||
|
||||
import { htmlInlineToDeltaMatchers } from './html/delta-converter/html-inline.js';
|
||||
import { inlineDeltaToHtmlAdapterMatchers } from './html/delta-converter/inline-delta.js';
|
||||
import { MarkdownAdapterFactoryExtension } from './markdown/markdown.js';
|
||||
import { inlineDeltaToMarkdownAdapterMatchers } from './markdown/delta-converter/inline-delta.js';
|
||||
import { markdownInlineToDeltaMatchers } from './markdown/delta-converter/markdown-inline.js';
|
||||
import { MixTextAdapterFactoryExtension } from './mix-text.js';
|
||||
import { notionHtmlInlineToDeltaMatchers } from './notion-html/delta-converter/html-inline.js';
|
||||
import { inlineDeltaToPlainTextAdapterMatchers } from './plain-text/delta-converter/inline-delta.js';
|
||||
@@ -20,6 +22,8 @@ export const AdapterFactoryExtensions: ExtensionType[] = [
|
||||
...inlineDeltaToHtmlAdapterMatchers,
|
||||
...notionHtmlInlineToDeltaMatchers,
|
||||
...inlineDeltaToPlainTextAdapterMatchers,
|
||||
...markdownInlineToDeltaMatchers,
|
||||
...inlineDeltaToMarkdownAdapterMatchers,
|
||||
AttachmentAdapterFactoryExtension,
|
||||
ImageAdapterFactoryExtension,
|
||||
MarkdownAdapterFactoryExtension,
|
||||
|
||||
@@ -1,36 +1,36 @@
|
||||
import { bookmarkBlockMarkdownAdapterMatcher } from '@blocksuite/affine-block-bookmark';
|
||||
import { codeBlockMarkdownAdapterMatcher } from '@blocksuite/affine-block-code';
|
||||
import { databaseBlockMarkdownAdapterMatcher } from '@blocksuite/affine-block-database';
|
||||
import { dividerBlockMarkdownAdapterMatcher } from '@blocksuite/affine-block-divider';
|
||||
import { BookmarkBlockMarkdownAdapterExtension } from '@blocksuite/affine-block-bookmark';
|
||||
import { CodeBlockMarkdownAdapterExtension } from '@blocksuite/affine-block-code';
|
||||
import { DatabaseBlockMarkdownAdapterExtension } from '@blocksuite/affine-block-database';
|
||||
import { DividerBlockMarkdownAdapterExtension } from '@blocksuite/affine-block-divider';
|
||||
import {
|
||||
embedFigmaBlockMarkdownAdapterMatcher,
|
||||
embedGithubBlockMarkdownAdapterMatcher,
|
||||
embedLinkedDocBlockMarkdownAdapterMatcher,
|
||||
embedLoomBlockMarkdownAdapterMatcher,
|
||||
embedSyncedDocBlockMarkdownAdapterMatcher,
|
||||
embedYoutubeBlockMarkdownAdapterMatcher,
|
||||
EmbedFigmaMarkdownAdapterExtension,
|
||||
EmbedGithubMarkdownAdapterExtension,
|
||||
EmbedLinkedDocMarkdownAdapterExtension,
|
||||
EmbedLoomMarkdownAdapterExtension,
|
||||
EmbedSyncedDocMarkdownAdapterExtension,
|
||||
EmbedYoutubeMarkdownAdapterExtension,
|
||||
} from '@blocksuite/affine-block-embed';
|
||||
import { imageBlockMarkdownAdapterMatcher } from '@blocksuite/affine-block-image';
|
||||
import { latexBlockMarkdownAdapterMatcher } from '@blocksuite/affine-block-latex';
|
||||
import { listBlockMarkdownAdapterMatcher } from '@blocksuite/affine-block-list';
|
||||
import { paragraphBlockMarkdownAdapterMatcher } from '@blocksuite/affine-block-paragraph';
|
||||
import { ImageBlockMarkdownAdapterExtension } from '@blocksuite/affine-block-image';
|
||||
import { LatexBlockMarkdownAdapterExtension } from '@blocksuite/affine-block-latex';
|
||||
import { ListBlockMarkdownAdapterExtension } from '@blocksuite/affine-block-list';
|
||||
import { ParagraphBlockMarkdownAdapterExtension } from '@blocksuite/affine-block-paragraph';
|
||||
|
||||
import { rootBlockMarkdownAdapterMatcher } from '../../../root-block/adapters/markdown.js';
|
||||
import { RootBlockMarkdownAdapterExtension } from '../../../root-block/adapters/markdown.js';
|
||||
|
||||
export const defaultBlockMarkdownAdapterMatchers = [
|
||||
embedFigmaBlockMarkdownAdapterMatcher,
|
||||
embedGithubBlockMarkdownAdapterMatcher,
|
||||
embedLinkedDocBlockMarkdownAdapterMatcher,
|
||||
embedLoomBlockMarkdownAdapterMatcher,
|
||||
embedSyncedDocBlockMarkdownAdapterMatcher,
|
||||
embedYoutubeBlockMarkdownAdapterMatcher,
|
||||
listBlockMarkdownAdapterMatcher,
|
||||
paragraphBlockMarkdownAdapterMatcher,
|
||||
bookmarkBlockMarkdownAdapterMatcher,
|
||||
codeBlockMarkdownAdapterMatcher,
|
||||
databaseBlockMarkdownAdapterMatcher,
|
||||
dividerBlockMarkdownAdapterMatcher,
|
||||
imageBlockMarkdownAdapterMatcher,
|
||||
latexBlockMarkdownAdapterMatcher,
|
||||
rootBlockMarkdownAdapterMatcher,
|
||||
EmbedFigmaMarkdownAdapterExtension,
|
||||
EmbedGithubMarkdownAdapterExtension,
|
||||
EmbedLinkedDocMarkdownAdapterExtension,
|
||||
EmbedLoomMarkdownAdapterExtension,
|
||||
EmbedSyncedDocMarkdownAdapterExtension,
|
||||
EmbedYoutubeMarkdownAdapterExtension,
|
||||
ListBlockMarkdownAdapterExtension,
|
||||
ParagraphBlockMarkdownAdapterExtension,
|
||||
BookmarkBlockMarkdownAdapterExtension,
|
||||
CodeBlockMarkdownAdapterExtension,
|
||||
DatabaseBlockMarkdownAdapterExtension,
|
||||
DividerBlockMarkdownAdapterExtension,
|
||||
ImageBlockMarkdownAdapterExtension,
|
||||
LatexBlockMarkdownAdapterExtension,
|
||||
RootBlockMarkdownAdapterExtension,
|
||||
];
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
import { generateDocUrl } from '@blocksuite/affine-block-embed';
|
||||
import type { InlineDeltaToMarkdownAdapterMatcher } from '@blocksuite/affine-shared/adapters';
|
||||
import { InlineDeltaToMarkdownAdapterExtension } from '@blocksuite/affine-shared/adapters';
|
||||
import type { PhrasingContent } from 'mdast';
|
||||
import type RemarkMath from 'remark-math';
|
||||
|
||||
export const boldDeltaToMarkdownAdapterMatcher: InlineDeltaToMarkdownAdapterMatcher =
|
||||
{
|
||||
declare type _GLOBAL_ = typeof RemarkMath;
|
||||
|
||||
export const boldDeltaToMarkdownAdapterMatcher =
|
||||
InlineDeltaToMarkdownAdapterExtension({
|
||||
name: 'bold',
|
||||
match: delta => !!delta.attributes?.bold,
|
||||
toAST: (_, context) => {
|
||||
@@ -13,10 +16,10 @@ export const boldDeltaToMarkdownAdapterMatcher: InlineDeltaToMarkdownAdapterMatc
|
||||
children: [currentMdast],
|
||||
};
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
export const italicDeltaToMarkdownAdapterMatcher: InlineDeltaToMarkdownAdapterMatcher =
|
||||
{
|
||||
export const italicDeltaToMarkdownAdapterMatcher =
|
||||
InlineDeltaToMarkdownAdapterExtension({
|
||||
name: 'italic',
|
||||
match: delta => !!delta.attributes?.italic,
|
||||
toAST: (_, context) => {
|
||||
@@ -26,10 +29,10 @@ export const italicDeltaToMarkdownAdapterMatcher: InlineDeltaToMarkdownAdapterMa
|
||||
children: [currentMdast],
|
||||
};
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
export const strikeDeltaToMarkdownAdapterMatcher: InlineDeltaToMarkdownAdapterMatcher =
|
||||
{
|
||||
export const strikeDeltaToMarkdownAdapterMatcher =
|
||||
InlineDeltaToMarkdownAdapterExtension({
|
||||
name: 'strike',
|
||||
match: delta => !!delta.attributes?.strike,
|
||||
toAST: (_, context) => {
|
||||
@@ -39,20 +42,20 @@ export const strikeDeltaToMarkdownAdapterMatcher: InlineDeltaToMarkdownAdapterMa
|
||||
children: [currentMdast],
|
||||
};
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
export const inlineCodeDeltaToMarkdownAdapterMatcher: InlineDeltaToMarkdownAdapterMatcher =
|
||||
{
|
||||
export const inlineCodeDeltaToMarkdownAdapterMatcher =
|
||||
InlineDeltaToMarkdownAdapterExtension({
|
||||
name: 'inlineCode',
|
||||
match: delta => !!delta.attributes?.code,
|
||||
toAST: delta => ({
|
||||
type: 'inlineCode',
|
||||
value: delta.insert,
|
||||
}),
|
||||
};
|
||||
});
|
||||
|
||||
export const referenceDeltaToMarkdownAdapterMatcher: InlineDeltaToMarkdownAdapterMatcher =
|
||||
{
|
||||
export const referenceDeltaToMarkdownAdapterMatcher =
|
||||
InlineDeltaToMarkdownAdapterExtension({
|
||||
name: 'reference',
|
||||
match: delta => !!delta.attributes?.reference,
|
||||
toAST: (delta, context) => {
|
||||
@@ -86,10 +89,10 @@ export const referenceDeltaToMarkdownAdapterMatcher: InlineDeltaToMarkdownAdapte
|
||||
|
||||
return mdast;
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
export const linkDeltaToMarkdownAdapterMatcher: InlineDeltaToMarkdownAdapterMatcher =
|
||||
{
|
||||
export const linkDeltaToMarkdownAdapterMatcher =
|
||||
InlineDeltaToMarkdownAdapterExtension({
|
||||
name: 'link',
|
||||
match: delta => !!delta.attributes?.link,
|
||||
toAST: (delta, context) => {
|
||||
@@ -120,10 +123,10 @@ export const linkDeltaToMarkdownAdapterMatcher: InlineDeltaToMarkdownAdapterMatc
|
||||
}
|
||||
return mdast;
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
export const latexDeltaToMarkdownAdapterMatcher: InlineDeltaToMarkdownAdapterMatcher =
|
||||
{
|
||||
export const latexDeltaToMarkdownAdapterMatcher =
|
||||
InlineDeltaToMarkdownAdapterExtension({
|
||||
name: 'inlineLatex',
|
||||
match: delta => !!delta.attributes?.latex,
|
||||
toAST: delta => {
|
||||
@@ -139,15 +142,14 @@ export const latexDeltaToMarkdownAdapterMatcher: InlineDeltaToMarkdownAdapterMat
|
||||
}
|
||||
return mdast;
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
export const inlineDeltaToMarkdownAdapterMatchers: InlineDeltaToMarkdownAdapterMatcher[] =
|
||||
[
|
||||
referenceDeltaToMarkdownAdapterMatcher,
|
||||
linkDeltaToMarkdownAdapterMatcher,
|
||||
inlineCodeDeltaToMarkdownAdapterMatcher,
|
||||
boldDeltaToMarkdownAdapterMatcher,
|
||||
italicDeltaToMarkdownAdapterMatcher,
|
||||
strikeDeltaToMarkdownAdapterMatcher,
|
||||
latexDeltaToMarkdownAdapterMatcher,
|
||||
];
|
||||
export const inlineDeltaToMarkdownAdapterMatchers = [
|
||||
referenceDeltaToMarkdownAdapterMatcher,
|
||||
linkDeltaToMarkdownAdapterMatcher,
|
||||
inlineCodeDeltaToMarkdownAdapterMatcher,
|
||||
boldDeltaToMarkdownAdapterMatcher,
|
||||
italicDeltaToMarkdownAdapterMatcher,
|
||||
strikeDeltaToMarkdownAdapterMatcher,
|
||||
latexDeltaToMarkdownAdapterMatcher,
|
||||
];
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { MarkdownASTToDeltaMatcher } from '@blocksuite/affine-shared/adapters';
|
||||
import { MarkdownASTToDeltaExtension } from '@blocksuite/affine-shared/adapters';
|
||||
|
||||
export const markdownTextToDeltaMatcher: MarkdownASTToDeltaMatcher = {
|
||||
export const markdownTextToDeltaMatcher = MarkdownASTToDeltaExtension({
|
||||
name: 'text',
|
||||
match: ast => ast.type === 'text',
|
||||
toDelta: ast => {
|
||||
@@ -9,9 +9,9 @@ export const markdownTextToDeltaMatcher: MarkdownASTToDeltaMatcher = {
|
||||
}
|
||||
return [{ insert: ast.value }];
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
export const markdownInlineCodeToDeltaMatcher: MarkdownASTToDeltaMatcher = {
|
||||
export const markdownInlineCodeToDeltaMatcher = MarkdownASTToDeltaExtension({
|
||||
name: 'inlineCode',
|
||||
match: ast => ast.type === 'inlineCode',
|
||||
toDelta: ast => {
|
||||
@@ -20,9 +20,9 @@ export const markdownInlineCodeToDeltaMatcher: MarkdownASTToDeltaMatcher = {
|
||||
}
|
||||
return [{ insert: ast.value, attributes: { code: true } }];
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
export const markdownStrongToDeltaMatcher: MarkdownASTToDeltaMatcher = {
|
||||
export const markdownStrongToDeltaMatcher = MarkdownASTToDeltaExtension({
|
||||
name: 'strong',
|
||||
match: ast => ast.type === 'strong',
|
||||
toDelta: (ast, context) => {
|
||||
@@ -36,9 +36,9 @@ export const markdownStrongToDeltaMatcher: MarkdownASTToDeltaMatcher = {
|
||||
})
|
||||
);
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
export const markdownEmphasisToDeltaMatcher: MarkdownASTToDeltaMatcher = {
|
||||
export const markdownEmphasisToDeltaMatcher = MarkdownASTToDeltaExtension({
|
||||
name: 'emphasis',
|
||||
match: ast => ast.type === 'emphasis',
|
||||
toDelta: (ast, context) => {
|
||||
@@ -52,9 +52,9 @@ export const markdownEmphasisToDeltaMatcher: MarkdownASTToDeltaMatcher = {
|
||||
})
|
||||
);
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
export const markdownDeleteToDeltaMatcher: MarkdownASTToDeltaMatcher = {
|
||||
export const markdownDeleteToDeltaMatcher = MarkdownASTToDeltaExtension({
|
||||
name: 'delete',
|
||||
match: ast => ast.type === 'delete',
|
||||
toDelta: (ast, context) => {
|
||||
@@ -68,9 +68,9 @@ export const markdownDeleteToDeltaMatcher: MarkdownASTToDeltaMatcher = {
|
||||
})
|
||||
);
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
export const markdownLinkToDeltaMatcher: MarkdownASTToDeltaMatcher = {
|
||||
export const markdownLinkToDeltaMatcher = MarkdownASTToDeltaExtension({
|
||||
name: 'link',
|
||||
match: ast => ast.type === 'link',
|
||||
toDelta: (ast, context) => {
|
||||
@@ -119,15 +119,15 @@ export const markdownLinkToDeltaMatcher: MarkdownASTToDeltaMatcher = {
|
||||
})
|
||||
);
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
export const markdownListToDeltaMatcher: MarkdownASTToDeltaMatcher = {
|
||||
export const markdownListToDeltaMatcher = MarkdownASTToDeltaExtension({
|
||||
name: 'list',
|
||||
match: ast => ast.type === 'list',
|
||||
toDelta: () => [],
|
||||
};
|
||||
});
|
||||
|
||||
export const markdownInlineMathToDeltaMatcher: MarkdownASTToDeltaMatcher = {
|
||||
export const markdownInlineMathToDeltaMatcher = MarkdownASTToDeltaExtension({
|
||||
name: 'inlineMath',
|
||||
match: ast => ast.type === 'inlineMath',
|
||||
toDelta: ast => {
|
||||
@@ -136,9 +136,9 @@ export const markdownInlineMathToDeltaMatcher: MarkdownASTToDeltaMatcher = {
|
||||
}
|
||||
return [{ insert: ' ', attributes: { latex: ast.value } }];
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
export const markdownInlineToDeltaMatchers: MarkdownASTToDeltaMatcher[] = [
|
||||
export const markdownInlineToDeltaMatchers = [
|
||||
markdownTextToDeltaMatcher,
|
||||
markdownInlineCodeToDeltaMatcher,
|
||||
markdownStrongToDeltaMatcher,
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
export { defaultBlockMarkdownAdapterMatchers } from './block-matcher.js';
|
||||
export {
|
||||
MarkdownAdapter,
|
||||
MarkdownAdapterFactoryExtension,
|
||||
MarkdownAdapterFactoryIdentifier,
|
||||
} from './markdown.js';
|
||||
export { inlineDeltaToMarkdownAdapterMatchers } from './delta-converter/inline-delta.js';
|
||||
export { markdownInlineToDeltaMatchers } from './delta-converter/markdown-inline.js';
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
import { DefaultTheme, NoteDisplayMode } from '@blocksuite/affine-model';
|
||||
import { AdapterFactoryIdentifier } from '@blocksuite/affine-shared/adapters';
|
||||
import {
|
||||
AdapterFactoryIdentifier,
|
||||
MarkdownAdapter,
|
||||
} from '@blocksuite/affine-shared/adapters';
|
||||
import type { ExtensionType } from '@blocksuite/block-std';
|
||||
import type { ServiceProvider } from '@blocksuite/global/di';
|
||||
import type { DeltaInsert } from '@blocksuite/inline';
|
||||
import {
|
||||
type AssetsManager,
|
||||
@@ -22,8 +26,6 @@ import {
|
||||
type ToDocSnapshotPayload,
|
||||
} from '@blocksuite/store';
|
||||
|
||||
import { MarkdownAdapter } from './markdown/index.js';
|
||||
|
||||
export type MixText = string;
|
||||
|
||||
type MixTextToSliceSnapshotPayload = {
|
||||
@@ -37,9 +39,9 @@ type MixTextToSliceSnapshotPayload = {
|
||||
export class MixTextAdapter extends BaseAdapter<MixText> {
|
||||
private readonly _markdownAdapter: MarkdownAdapter;
|
||||
|
||||
constructor(job: Job) {
|
||||
constructor(job: Job, provider: ServiceProvider) {
|
||||
super(job);
|
||||
this._markdownAdapter = new MarkdownAdapter(job);
|
||||
this._markdownAdapter = new MarkdownAdapter(job, provider);
|
||||
}
|
||||
|
||||
private _splitDeltas(deltas: DeltaInsert[]): DeltaInsert[][] {
|
||||
@@ -353,8 +355,8 @@ export const MixTextAdapterFactoryIdentifier =
|
||||
|
||||
export const MixTextAdapterFactoryExtension: ExtensionType = {
|
||||
setup: di => {
|
||||
di.addImpl(MixTextAdapterFactoryIdentifier, () => ({
|
||||
get: (job: Job) => new MixTextAdapter(job),
|
||||
di.addImpl(MixTextAdapterFactoryIdentifier, provider => ({
|
||||
get: (job: Job) => new MixTextAdapter(job, provider),
|
||||
}));
|
||||
},
|
||||
};
|
||||
|
||||
@@ -1,12 +1,6 @@
|
||||
import { MindmapElementModel } from '@blocksuite/affine-model';
|
||||
import type { Viewport } from '@blocksuite/block-std/gfx';
|
||||
|
||||
export function isMindmapNode(el: BlockSuite.EdgelessModel) {
|
||||
return (
|
||||
el.group instanceof MindmapElementModel || el instanceof MindmapElementModel
|
||||
);
|
||||
}
|
||||
|
||||
export function isSingleMindMapNode(els: BlockSuite.EdgelessModel[]) {
|
||||
return els.length === 1 && els[0].group instanceof MindmapElementModel;
|
||||
}
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
import { MarkdownAdapter } from '@blocksuite/affine-shared/adapters';
|
||||
import { Container } from '@blocksuite/global/di';
|
||||
import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';
|
||||
import { assertExists, sha } from '@blocksuite/global/utils';
|
||||
import type { Doc, DocCollection } from '@blocksuite/store';
|
||||
import { extMimeMap, Job } from '@blocksuite/store';
|
||||
|
||||
import { MarkdownAdapter } from '../adapters/markdown/index.js';
|
||||
import { defaultBlockMarkdownAdapterMatchers } from '../adapters/index.js';
|
||||
import { inlineDeltaToMarkdownAdapterMatchers } from '../adapters/markdown/delta-converter/inline-delta.js';
|
||||
import { markdownInlineToDeltaMatchers } from '../adapters/markdown/delta-converter/markdown-inline.js';
|
||||
import {
|
||||
defaultImageProxyMiddleware,
|
||||
docLinkBaseURLMiddleware,
|
||||
@@ -12,6 +16,17 @@ import {
|
||||
} from './middlewares.js';
|
||||
import { createAssetsArchive, download, Unzip } from './utils.js';
|
||||
|
||||
const container = new Container();
|
||||
[
|
||||
...markdownInlineToDeltaMatchers,
|
||||
...defaultBlockMarkdownAdapterMatchers,
|
||||
...inlineDeltaToMarkdownAdapterMatchers,
|
||||
].forEach(ext => {
|
||||
ext.setup(container);
|
||||
});
|
||||
|
||||
const provider = container.provider();
|
||||
|
||||
type ImportMarkdownToBlockOptions = {
|
||||
doc: Doc;
|
||||
markdown: string;
|
||||
@@ -41,7 +56,7 @@ async function exportDoc(doc: Doc) {
|
||||
});
|
||||
const snapshot = job.docToSnapshot(doc);
|
||||
|
||||
const adapter = new MarkdownAdapter(job);
|
||||
const adapter = new MarkdownAdapter(job, provider);
|
||||
if (!snapshot) {
|
||||
return;
|
||||
}
|
||||
@@ -89,7 +104,7 @@ async function importMarkdownToBlock({
|
||||
collection: doc.collection,
|
||||
middlewares: [defaultImageProxyMiddleware, docLinkBaseURLMiddleware],
|
||||
});
|
||||
const adapter = new MarkdownAdapter(job);
|
||||
const adapter = new MarkdownAdapter(job, provider);
|
||||
const snapshot = await adapter.toSliceSnapshot({
|
||||
file: markdown,
|
||||
assets: job.assetsManager,
|
||||
@@ -129,7 +144,7 @@ async function importMarkdownToDoc({
|
||||
docLinkBaseURLMiddleware,
|
||||
],
|
||||
});
|
||||
const mdAdapter = new MarkdownAdapter(job);
|
||||
const mdAdapter = new MarkdownAdapter(job, provider);
|
||||
const page = await mdAdapter.toDoc({
|
||||
file: markdown,
|
||||
assets: job.assetsManager,
|
||||
@@ -195,7 +210,7 @@ async function importMarkdownZip({
|
||||
for (const [key, value] of pendingPathBlobIdMap.entries()) {
|
||||
pathBlobIdMap.set(key, value);
|
||||
}
|
||||
const mdAdapter = new MarkdownAdapter(job);
|
||||
const mdAdapter = new MarkdownAdapter(job, provider);
|
||||
const markdown = await blob.text();
|
||||
const doc = await mdAdapter.toDoc({
|
||||
file: markdown,
|
||||
|
||||
@@ -23,13 +23,19 @@ async function exportDocs(collection: DocCollection, docs: Doc[]) {
|
||||
);
|
||||
|
||||
const assets = zip.folder('assets');
|
||||
const pathBlobIdMap = job.assetsManager.getPathBlobIdMap();
|
||||
const assetsMap = job.assets;
|
||||
|
||||
for (const [id, blob] of assetsMap) {
|
||||
const ext = getAssetName(assetsMap, id).split('.').at(-1);
|
||||
const name = `${id}.${ext}`;
|
||||
await assets.file(name, blob);
|
||||
}
|
||||
await Promise.all(
|
||||
Array.from(pathBlobIdMap.values()).map(async blobId => {
|
||||
await job.assetsManager.readFromBlob(blobId);
|
||||
const ext = getAssetName(assetsMap, blobId).split('.').at(-1);
|
||||
const blob = assetsMap.get(blobId);
|
||||
if (blob) {
|
||||
await assets.file(`${blobId}.${ext}`, blob);
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
const downloadBlob = await zip.generate();
|
||||
return download(downloadBlob, `${collection.id}.bs.zip`);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { AttachmentBlockSpec } from '@blocksuite/affine-block-attachment';
|
||||
import { BookmarkBlockSpec } from '@blocksuite/affine-block-bookmark';
|
||||
import { CodeBlockSpec } from '@blocksuite/affine-block-code';
|
||||
import { DataViewBlockSpec } from '@blocksuite/affine-block-data-view';
|
||||
import { DatabaseBlockSpec } from '@blocksuite/affine-block-database';
|
||||
import { DividerBlockSpec } from '@blocksuite/affine-block-divider';
|
||||
import { EdgelessTextBlockSpec } from '@blocksuite/affine-block-edgeless-text';
|
||||
@@ -34,7 +35,6 @@ import {
|
||||
import type { ExtensionType } from '@blocksuite/block-std';
|
||||
|
||||
import { AdapterFactoryExtensions } from '../_common/adapters/extension.js';
|
||||
import { DataViewBlockSpec } from '../data-view-block/data-view-spec.js';
|
||||
|
||||
export const CommonBlockSpecs: ExtensionType[] = [
|
||||
DocDisplayMetaService,
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
import type { DataViewBlockModel } from './data-view-model.js';
|
||||
|
||||
export * from './data-view-block.js';
|
||||
export * from './data-view-model.js';
|
||||
export * from './data-view-spec.js';
|
||||
|
||||
declare global {
|
||||
namespace BlockSuite {
|
||||
interface BlockModels {
|
||||
'affine:data-view': DataViewBlockModel;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
import { effects as blockAttachmentEffects } from '@blocksuite/affine-block-attachment/effects';
|
||||
import { effects as blockBookmarkEffects } from '@blocksuite/affine-block-bookmark/effects';
|
||||
import { effects as blockCodeEffects } from '@blocksuite/affine-block-code/effects';
|
||||
import { effects as blockDataViewEffects } from '@blocksuite/affine-block-data-view/effects';
|
||||
import { effects as blockDatabaseEffects } from '@blocksuite/affine-block-database/effects';
|
||||
import { effects as blockDividerEffects } from '@blocksuite/affine-block-divider/effects';
|
||||
import { effects as blockEdgelessTextEffects } from '@blocksuite/affine-block-edgeless-text/effects';
|
||||
@@ -17,6 +18,7 @@ import { effects as componentAiItemEffects } from '@blocksuite/affine-components
|
||||
import { BlockSelection } from '@blocksuite/affine-components/block-selection';
|
||||
import { BlockZeroWidth } from '@blocksuite/affine-components/block-zero-width';
|
||||
import { effects as componentCaptionEffects } from '@blocksuite/affine-components/caption';
|
||||
import { effects as componentColorPickerEffects } from '@blocksuite/affine-components/color-picker';
|
||||
import { effects as componentContextMenuEffects } from '@blocksuite/affine-components/context-menu';
|
||||
import { effects as componentDatePickerEffects } from '@blocksuite/affine-components/date-picker';
|
||||
import { effects as componentDragIndicatorEffects } from '@blocksuite/affine-components/drag-indicator';
|
||||
@@ -38,14 +40,10 @@ import { effects as inlineEffects } from '@blocksuite/inline/effects';
|
||||
import type { BlockModel } from '@blocksuite/store';
|
||||
|
||||
import { registerSpecs } from './_specs/register-specs.js';
|
||||
import { DataViewBlockComponent } from './data-view-block/index.js';
|
||||
import { EdgelessAutoCompletePanel } from './root-block/edgeless/components/auto-complete/auto-complete-panel.js';
|
||||
import { EdgelessAutoComplete } from './root-block/edgeless/components/auto-complete/edgeless-auto-complete.js';
|
||||
import { EdgelessToolIconButton } from './root-block/edgeless/components/buttons/tool-icon-button.js';
|
||||
import { EdgelessToolbarButton } from './root-block/edgeless/components/buttons/toolbar-button.js';
|
||||
import { EdgelessColorPickerButton } from './root-block/edgeless/components/color-picker/button.js';
|
||||
import { EdgelessColorPicker } from './root-block/edgeless/components/color-picker/color-picker.js';
|
||||
import { EdgelessColorCustomButton } from './root-block/edgeless/components/color-picker/custom-button.js';
|
||||
import { EdgelessConnectorHandle } from './root-block/edgeless/components/connector/connector-handle.js';
|
||||
import {
|
||||
NOTE_SLICER_WIDGET,
|
||||
@@ -209,6 +207,7 @@ export function effects() {
|
||||
blockLatexEffects();
|
||||
blockEdgelessTextEffects();
|
||||
blockDividerEffects();
|
||||
blockDataViewEffects();
|
||||
blockCodeEffects();
|
||||
|
||||
componentCaptionEffects();
|
||||
@@ -220,6 +219,7 @@ export function effects() {
|
||||
componentDragIndicatorEffects();
|
||||
componentToggleButtonEffects();
|
||||
componentAiItemEffects();
|
||||
componentColorPickerEffects();
|
||||
|
||||
widgetScrollAnchoringEffects();
|
||||
widgetMobileToolbarEffects();
|
||||
@@ -234,17 +234,12 @@ export function effects() {
|
||||
customElements.define('affine-preview-root', PreviewRootBlockComponent);
|
||||
customElements.define('mini-mindmap-preview', MiniMindmapPreview);
|
||||
customElements.define('mini-mindmap-surface-block', MindmapSurfaceBlock);
|
||||
customElements.define('affine-data-view', DataViewBlockComponent);
|
||||
customElements.define('affine-edgeless-root', EdgelessRootBlockComponent);
|
||||
customElements.define('edgeless-copilot-panel', EdgelessCopilotPanel);
|
||||
customElements.define(
|
||||
'edgeless-copilot-toolbar-entry',
|
||||
EdgelessCopilotToolbarEntry
|
||||
);
|
||||
customElements.define(
|
||||
'edgeless-color-custom-button',
|
||||
EdgelessColorCustomButton
|
||||
);
|
||||
customElements.define('edgeless-connector-handle', EdgelessConnectorHandle);
|
||||
customElements.define('edgeless-zoom-toolbar', EdgelessZoomToolbar);
|
||||
customElements.define(
|
||||
@@ -331,13 +326,8 @@ export function effects() {
|
||||
EdgelessNavigatorSettingButton
|
||||
);
|
||||
customElements.define('edgeless-present-button', EdgelessPresentButton);
|
||||
customElements.define('edgeless-color-picker', EdgelessColorPicker);
|
||||
customElements.define('overlay-scrollbar', OverlayScrollbar);
|
||||
customElements.define('affine-template-loading', AffineTemplateLoading);
|
||||
customElements.define(
|
||||
'edgeless-color-picker-button',
|
||||
EdgelessColorPickerButton
|
||||
);
|
||||
customElements.define('edgeless-auto-complete', EdgelessAutoComplete);
|
||||
customElements.define(
|
||||
'edgeless-font-weight-and-style-panel',
|
||||
|
||||
@@ -7,6 +7,7 @@ import { splitElements } from './root-block/edgeless/utils/clipboard-utils.js';
|
||||
import { isCanvasElement } from './root-block/edgeless/utils/query.js';
|
||||
|
||||
export * from './_common/adapters/index.js';
|
||||
export * from './_common/adapters/markdown';
|
||||
export { type NavigatorMode } from './_common/edgeless/frame/consts.js';
|
||||
export {
|
||||
ExportManager,
|
||||
@@ -16,7 +17,6 @@ export * from './_common/test-utils/test-utils.js';
|
||||
export * from './_common/transformers/index.js';
|
||||
export { type AbstractEditor } from './_common/types.js';
|
||||
export * from './_specs/index.js';
|
||||
export * from './data-view-block';
|
||||
export { EdgelessTemplatePanel } from './root-block/edgeless/components/toolbar/template/template-panel.js';
|
||||
export type {
|
||||
Template,
|
||||
@@ -41,6 +41,7 @@ export {
|
||||
export * from '@blocksuite/affine-block-attachment';
|
||||
export * from '@blocksuite/affine-block-bookmark';
|
||||
export * from '@blocksuite/affine-block-code';
|
||||
export * from '@blocksuite/affine-block-data-view';
|
||||
export * from '@blocksuite/affine-block-database';
|
||||
export * from '@blocksuite/affine-block-divider';
|
||||
export * from '@blocksuite/affine-block-edgeless-text';
|
||||
@@ -108,6 +109,9 @@ export {
|
||||
ImageAdapter,
|
||||
ImageAdapterFactoryExtension,
|
||||
ImageAdapterFactoryIdentifier,
|
||||
MarkdownAdapter,
|
||||
MarkdownAdapterFactoryExtension,
|
||||
MarkdownAdapterFactoryIdentifier,
|
||||
NotionTextAdapter,
|
||||
NotionTextAdapterFactoryExtension,
|
||||
NotionTextAdapterFactoryIdentifier,
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
export * from './button.js';
|
||||
export * from './color-picker.js';
|
||||
export * from './types.js';
|
||||
@@ -1,6 +1,7 @@
|
||||
import type { Color, ColorScheme, Palette } from '@blocksuite/affine-model';
|
||||
import { isTransparent, resolveColor } from '@blocksuite/affine-model';
|
||||
import { unsafeCSSVarV2 } from '@blocksuite/affine-shared/theme';
|
||||
import { ColorEvent } from '@blocksuite/affine-shared/utils';
|
||||
import { css, html, LitElement, nothing, svg, type TemplateResult } from 'lit';
|
||||
import { property } from 'lit/decorators.js';
|
||||
import { classMap } from 'lit/directives/class-map.js';
|
||||
@@ -8,22 +9,6 @@ import { ifDefined } from 'lit/directives/if-defined.js';
|
||||
import { repeat } from 'lit/directives/repeat.js';
|
||||
import isEqual from 'lodash.isequal';
|
||||
|
||||
export class ColorEvent extends Event {
|
||||
detail: Palette;
|
||||
|
||||
constructor(
|
||||
type: string,
|
||||
{
|
||||
detail,
|
||||
composed,
|
||||
bubbles,
|
||||
}: { detail: Palette; composed: boolean; bubbles: boolean }
|
||||
) {
|
||||
super(type, { bubbles, composed });
|
||||
this.detail = detail;
|
||||
}
|
||||
}
|
||||
|
||||
function TransparentIcon(hollowCircle = false) {
|
||||
const CircleIcon: TemplateResult | typeof nothing = hollowCircle
|
||||
? svg`<circle cx="10" cy="10" r="8" fill="white" />`
|
||||
|
||||
@@ -3,11 +3,11 @@ import {
|
||||
DefaultTheme,
|
||||
type StrokeStyle,
|
||||
} from '@blocksuite/affine-model';
|
||||
import type { ColorEvent } from '@blocksuite/affine-shared/utils';
|
||||
import { WithDisposable } from '@blocksuite/global/utils';
|
||||
import { css, html, LitElement } from 'lit';
|
||||
import { property } from 'lit/decorators.js';
|
||||
|
||||
import type { ColorEvent } from './color-panel.js';
|
||||
import { type LineStyleEvent, LineStylesPanel } from './line-styles-panel.js';
|
||||
|
||||
export class StrokeStylePanel extends WithDisposable(LitElement) {
|
||||
|
||||
@@ -62,7 +62,6 @@ import { state } from 'lit/decorators.js';
|
||||
import { ifDefined } from 'lit/directives/if-defined.js';
|
||||
import { styleMap } from 'lit/directives/style-map.js';
|
||||
|
||||
import { isMindmapNode } from '../../../../_common/edgeless/mindmap/index.js';
|
||||
import type { EdgelessRootBlockComponent } from '../../edgeless-root-block.js';
|
||||
import type {
|
||||
EdgelessFrameManager,
|
||||
@@ -91,6 +90,7 @@ import {
|
||||
isEmbedYoutubeBlock,
|
||||
isFrameBlock,
|
||||
isImageBlock,
|
||||
isMindmapNode,
|
||||
isNoteBlock,
|
||||
} from '../../utils/query.js';
|
||||
import {
|
||||
|
||||
@@ -3,13 +3,13 @@ import {
|
||||
EditPropsStore,
|
||||
ThemeProvider,
|
||||
} from '@blocksuite/affine-shared/services';
|
||||
import type { ColorEvent } from '@blocksuite/affine-shared/utils';
|
||||
import type { GfxToolsFullOptionValue } from '@blocksuite/block-std/gfx';
|
||||
import { SignalWatcher } from '@blocksuite/global/utils';
|
||||
import { computed } from '@preact/signals-core';
|
||||
import { css, html, LitElement } from 'lit';
|
||||
import { property } from 'lit/decorators.js';
|
||||
|
||||
import type { ColorEvent } from '../../panel/color-panel.js';
|
||||
import type { LineWidthEvent } from '../../panel/line-width-panel.js';
|
||||
import { EdgelessToolbarToolMixin } from '../mixins/tool.mixin.js';
|
||||
|
||||
|
||||
@@ -8,13 +8,13 @@ import {
|
||||
EditPropsStore,
|
||||
ThemeProvider,
|
||||
} from '@blocksuite/affine-shared/services';
|
||||
import type { ColorEvent } from '@blocksuite/affine-shared/utils';
|
||||
import type { GfxToolsFullOptionValue } from '@blocksuite/block-std/gfx';
|
||||
import { SignalWatcher } from '@blocksuite/global/utils';
|
||||
import { computed } from '@preact/signals-core';
|
||||
import { css, html, LitElement } from 'lit';
|
||||
import { property } from 'lit/decorators.js';
|
||||
|
||||
import type { ColorEvent } from '../../panel/color-panel.js';
|
||||
import type { LineWidthEvent } from '../../panel/line-width-panel.js';
|
||||
import { EdgelessToolbarToolMixin } from '../mixins/tool.mixin.js';
|
||||
|
||||
|
||||
@@ -14,13 +14,13 @@ import {
|
||||
EditPropsStore,
|
||||
ThemeProvider,
|
||||
} from '@blocksuite/affine-shared/services';
|
||||
import type { ColorEvent } from '@blocksuite/affine-shared/utils';
|
||||
import { SignalWatcher, WithDisposable } from '@blocksuite/global/utils';
|
||||
import { computed, effect, type Signal, signal } from '@preact/signals-core';
|
||||
import { css, html, LitElement } from 'lit';
|
||||
import { property } from 'lit/decorators.js';
|
||||
|
||||
import type { EdgelessRootBlockComponent } from '../../../edgeless-root-block.js';
|
||||
import type { ColorEvent } from '../../panel/color-panel.js';
|
||||
import { ShapeComponentConfig } from './shape-menu-config.js';
|
||||
|
||||
export class EdgelessShapeMenu extends SignalWatcher(
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { DefaultTheme } from '@blocksuite/affine-model';
|
||||
import { ThemeProvider } from '@blocksuite/affine-shared/services';
|
||||
import type { ColorEvent } from '@blocksuite/affine-shared/utils';
|
||||
import type { GfxToolsFullOptionValue } from '@blocksuite/block-std/gfx';
|
||||
import { computed } from '@preact/signals-core';
|
||||
import { css, html, LitElement, nothing } from 'lit';
|
||||
import { property } from 'lit/decorators.js';
|
||||
|
||||
import type { ColorEvent } from '../../panel/color-panel.js';
|
||||
import { EdgelessToolbarToolMixin } from '../mixins/tool.mixin.js';
|
||||
|
||||
export class EdgelessTextMenu extends EdgelessToolbarToolMixin(LitElement) {
|
||||
|
||||
@@ -18,10 +18,8 @@ import {
|
||||
} from '@blocksuite/block-std/gfx';
|
||||
import type { Bound, IVec } from '@blocksuite/global/utils';
|
||||
|
||||
import {
|
||||
isMindmapNode,
|
||||
isSingleMindMapNode,
|
||||
} from '../../../../../_common/edgeless/mindmap/index.js';
|
||||
import { isSingleMindMapNode } from '../../../../../_common/edgeless/mindmap/index.js';
|
||||
import { isMindmapNode } from '../../../utils/query.js';
|
||||
import { DefaultModeDragType, DefaultToolExt, type DragState } from '../ext.js';
|
||||
import { calculateResponseArea } from './drag-utils.js';
|
||||
import type { MindMapIndicatorOverlay } from './indicator-overlay.js';
|
||||
|
||||
@@ -1,4 +1,12 @@
|
||||
import { EdgelessCRUDIdentifier } from '@blocksuite/affine-block-surface';
|
||||
import type {
|
||||
EdgelessColorPickerButton,
|
||||
PickColorEvent,
|
||||
} from '@blocksuite/affine-components/color-picker';
|
||||
import {
|
||||
packColor,
|
||||
packColorsWithColorScheme,
|
||||
} from '@blocksuite/affine-components/color-picker';
|
||||
import type {
|
||||
BrushElementModel,
|
||||
BrushProps,
|
||||
@@ -9,18 +17,12 @@ import {
|
||||
LineWidth,
|
||||
resolveColor,
|
||||
} from '@blocksuite/affine-model';
|
||||
import type { ColorEvent } from '@blocksuite/affine-shared/utils';
|
||||
import { countBy, maxBy, WithDisposable } from '@blocksuite/global/utils';
|
||||
import { html, LitElement, nothing } from 'lit';
|
||||
import { property, query } from 'lit/decorators.js';
|
||||
import { when } from 'lit/directives/when.js';
|
||||
|
||||
import type { EdgelessColorPickerButton } from '../../edgeless/components/color-picker/button.js';
|
||||
import type { PickColorEvent } from '../../edgeless/components/color-picker/types.js';
|
||||
import {
|
||||
packColor,
|
||||
packColorsWithColorScheme,
|
||||
} from '../../edgeless/components/color-picker/utils.js';
|
||||
import type { ColorEvent } from '../../edgeless/components/panel/color-panel.js';
|
||||
import type { LineWidthEvent } from '../../edgeless/components/panel/line-width-panel.js';
|
||||
import type { EdgelessRootBlockComponent } from '../../edgeless/edgeless-root-block.js';
|
||||
|
||||
|
||||
@@ -1,4 +1,12 @@
|
||||
import { EdgelessCRUDIdentifier } from '@blocksuite/affine-block-surface';
|
||||
import type {
|
||||
EdgelessColorPickerButton,
|
||||
PickColorEvent,
|
||||
} from '@blocksuite/affine-components/color-picker';
|
||||
import {
|
||||
packColor,
|
||||
packColorsWithColorScheme,
|
||||
} from '@blocksuite/affine-components/color-picker';
|
||||
import {
|
||||
AddTextIcon,
|
||||
ConnectorCWithArrowIcon,
|
||||
@@ -34,6 +42,7 @@ import {
|
||||
resolveColor,
|
||||
StrokeStyle,
|
||||
} from '@blocksuite/affine-model';
|
||||
import type { ColorEvent } from '@blocksuite/affine-shared/utils';
|
||||
import { countBy, maxBy, WithDisposable } from '@blocksuite/global/utils';
|
||||
import { html, LitElement, nothing, type TemplateResult } from 'lit';
|
||||
import { property, query } from 'lit/decorators.js';
|
||||
@@ -43,13 +52,6 @@ import { repeat } from 'lit/directives/repeat.js';
|
||||
import { styleMap } from 'lit/directives/style-map.js';
|
||||
import { when } from 'lit/directives/when.js';
|
||||
|
||||
import type { EdgelessColorPickerButton } from '../../edgeless/components/color-picker/button.js';
|
||||
import type { PickColorEvent } from '../../edgeless/components/color-picker/types.js';
|
||||
import {
|
||||
packColor,
|
||||
packColorsWithColorScheme,
|
||||
} from '../../edgeless/components/color-picker/utils.js';
|
||||
import type { ColorEvent } from '../../edgeless/components/panel/color-panel.js';
|
||||
import {
|
||||
type LineStyleEvent,
|
||||
LineStylesPanel,
|
||||
|
||||
@@ -1,4 +1,12 @@
|
||||
import { EdgelessCRUDIdentifier } from '@blocksuite/affine-block-surface';
|
||||
import type {
|
||||
EdgelessColorPickerButton,
|
||||
PickColorEvent,
|
||||
} from '@blocksuite/affine-components/color-picker';
|
||||
import {
|
||||
packColor,
|
||||
packColorsWithColorScheme,
|
||||
} from '@blocksuite/affine-components/color-picker';
|
||||
import {
|
||||
NoteIcon,
|
||||
RenameIcon,
|
||||
@@ -14,6 +22,7 @@ import {
|
||||
NoteDisplayMode,
|
||||
resolveColor,
|
||||
} from '@blocksuite/affine-model';
|
||||
import type { ColorEvent } from '@blocksuite/affine-shared/utils';
|
||||
import { matchFlavours } from '@blocksuite/affine-shared/utils';
|
||||
import { GfxExtensionIdentifier } from '@blocksuite/block-std/gfx';
|
||||
import {
|
||||
@@ -28,13 +37,6 @@ import { property, query } from 'lit/decorators.js';
|
||||
import { join } from 'lit/directives/join.js';
|
||||
import { when } from 'lit/directives/when.js';
|
||||
|
||||
import type { EdgelessColorPickerButton } from '../../edgeless/components/color-picker/button.js';
|
||||
import type { PickColorEvent } from '../../edgeless/components/color-picker/types.js';
|
||||
import {
|
||||
packColor,
|
||||
packColorsWithColorScheme,
|
||||
} from '../../edgeless/components/color-picker/utils.js';
|
||||
import type { ColorEvent } from '../../edgeless/components/panel/color-panel.js';
|
||||
import type { EdgelessRootBlockComponent } from '../../edgeless/edgeless-root-block.js';
|
||||
import type { EdgelessFrameManager } from '../../edgeless/frame-manager.js';
|
||||
import { mountFrameTitleEditor } from '../../edgeless/utils/text.js';
|
||||
|
||||
@@ -1,4 +1,12 @@
|
||||
import { EdgelessCRUDIdentifier } from '@blocksuite/affine-block-surface';
|
||||
import type {
|
||||
EdgelessColorPickerButton,
|
||||
PickColorEvent,
|
||||
} from '@blocksuite/affine-components/color-picker';
|
||||
import {
|
||||
packColor,
|
||||
packColorsWithColorScheme,
|
||||
} from '@blocksuite/affine-components/color-picker';
|
||||
import {
|
||||
ExpandIcon,
|
||||
LineStyleIcon,
|
||||
@@ -35,14 +43,6 @@ import { join } from 'lit/directives/join.js';
|
||||
import { createRef, type Ref, ref } from 'lit/directives/ref.js';
|
||||
import { when } from 'lit/directives/when.js';
|
||||
|
||||
import type {
|
||||
EdgelessColorPickerButton,
|
||||
PickColorEvent,
|
||||
} from '../../edgeless/components/color-picker/index.js';
|
||||
import {
|
||||
packColor,
|
||||
packColorsWithColorScheme,
|
||||
} from '../../edgeless/components/color-picker/utils.js';
|
||||
import {
|
||||
type LineStyleEvent,
|
||||
LineStylesPanel,
|
||||
|
||||
@@ -1,4 +1,12 @@
|
||||
import { EdgelessCRUDIdentifier } from '@blocksuite/affine-block-surface';
|
||||
import type {
|
||||
EdgelessColorPickerButton,
|
||||
PickColorEvent,
|
||||
} from '@blocksuite/affine-components/color-picker';
|
||||
import {
|
||||
packColor,
|
||||
packColorsWithColorScheme,
|
||||
} from '@blocksuite/affine-components/color-picker';
|
||||
import {
|
||||
AddTextIcon,
|
||||
ChangeShapeIcon,
|
||||
@@ -26,6 +34,7 @@ import {
|
||||
ShapeStyle,
|
||||
StrokeStyle,
|
||||
} from '@blocksuite/affine-model';
|
||||
import type { ColorEvent } from '@blocksuite/affine-shared/utils';
|
||||
import { countBy, maxBy, WithDisposable } from '@blocksuite/global/utils';
|
||||
import { css, html, LitElement, nothing, type TemplateResult } from 'lit';
|
||||
import { property, query } from 'lit/decorators.js';
|
||||
@@ -36,13 +45,6 @@ import { styleMap } from 'lit/directives/style-map.js';
|
||||
import { when } from 'lit/directives/when.js';
|
||||
import isEqual from 'lodash.isequal';
|
||||
|
||||
import type { EdgelessColorPickerButton } from '../../edgeless/components/color-picker/button.js';
|
||||
import type { PickColorEvent } from '../../edgeless/components/color-picker/types.js';
|
||||
import {
|
||||
packColor,
|
||||
packColorsWithColorScheme,
|
||||
} from '../../edgeless/components/color-picker/utils.js';
|
||||
import type { ColorEvent } from '../../edgeless/components/panel/color-panel.js';
|
||||
import {
|
||||
type LineStyleEvent,
|
||||
LineStylesPanel,
|
||||
|
||||
@@ -4,6 +4,14 @@ import {
|
||||
normalizeShapeBound,
|
||||
TextUtils,
|
||||
} from '@blocksuite/affine-block-surface';
|
||||
import type {
|
||||
EdgelessColorPickerButton,
|
||||
PickColorEvent,
|
||||
} from '@blocksuite/affine-components/color-picker';
|
||||
import {
|
||||
packColor,
|
||||
packColorsWithColorScheme,
|
||||
} from '@blocksuite/affine-components/color-picker';
|
||||
import {
|
||||
SmallArrowDownIcon,
|
||||
TextAlignCenterIcon,
|
||||
@@ -25,6 +33,7 @@ import {
|
||||
TextElementModel,
|
||||
type TextStyleProps,
|
||||
} from '@blocksuite/affine-model';
|
||||
import type { ColorEvent } from '@blocksuite/affine-shared/utils';
|
||||
import {
|
||||
Bound,
|
||||
countBy,
|
||||
@@ -37,15 +46,6 @@ import { choose } from 'lit/directives/choose.js';
|
||||
import { join } from 'lit/directives/join.js';
|
||||
import { when } from 'lit/directives/when.js';
|
||||
|
||||
import type {
|
||||
EdgelessColorPickerButton,
|
||||
PickColorEvent,
|
||||
} from '../../edgeless/components/color-picker/index.js';
|
||||
import {
|
||||
packColor,
|
||||
packColorsWithColorScheme,
|
||||
} from '../../edgeless/components/color-picker/utils.js';
|
||||
import type { ColorEvent } from '../../edgeless/components/panel/color-panel.js';
|
||||
import type { EdgelessRootBlockComponent } from '../../edgeless/edgeless-root-block.js';
|
||||
|
||||
const FONT_SIZE_LIST = [
|
||||
|
||||
@@ -33,8 +33,6 @@ export class EdgelessLockButton extends SignalWatcher(
|
||||
private _lock() {
|
||||
const { service, doc, std } = this.edgeless;
|
||||
|
||||
doc.captureSync();
|
||||
|
||||
// get most top selected elements(*) from tree, like in a tree below
|
||||
// G0
|
||||
// / \
|
||||
@@ -46,12 +44,16 @@ export class EdgelessLockButton extends SignalWatcher(
|
||||
// return [E1]
|
||||
|
||||
const selectedElements = this._selectedElements;
|
||||
if (selectedElements.length === 0) return;
|
||||
|
||||
const levels = selectedElements.map(element => element.groups.length);
|
||||
const topElement = selectedElements[levels.indexOf(Math.min(...levels))];
|
||||
const otherElements = selectedElements.filter(
|
||||
element => element !== topElement
|
||||
);
|
||||
|
||||
doc.captureSync();
|
||||
|
||||
// release other elements from their groups and group with top element
|
||||
otherElements.forEach(element => {
|
||||
// oxlint-disable-next-line unicorn/prefer-dom-node-remove
|
||||
@@ -97,9 +99,13 @@ export class EdgelessLockButton extends SignalWatcher(
|
||||
|
||||
private _unlock() {
|
||||
const { service, doc } = this.edgeless;
|
||||
|
||||
const selectedElements = this._selectedElements;
|
||||
if (selectedElements.length === 0) return;
|
||||
|
||||
doc.captureSync();
|
||||
|
||||
this._selectedElements.forEach(element => {
|
||||
selectedElements.forEach(element => {
|
||||
if (element instanceof GroupElementModel) {
|
||||
service.ungroup(element);
|
||||
} else {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { parseStringToRgba } from '@blocksuite/affine-components/color-picker';
|
||||
import {
|
||||
ColorScheme,
|
||||
FrameBlockModel,
|
||||
@@ -22,7 +23,6 @@ import { themeToVar } from '@toeverything/theme/v2';
|
||||
import { LitElement } from 'lit';
|
||||
import { property, state } from 'lit/decorators.js';
|
||||
|
||||
import { parseStringToRgba } from '../../edgeless/components/color-picker/utils.js';
|
||||
import type { EdgelessRootService } from '../../edgeless/index.js';
|
||||
import { frameTitleStyle, frameTitleStyleVars } from './styles.js';
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { addSiblingAttachmentBlocks } from '@blocksuite/affine-block-attachment';
|
||||
import { toggleEmbedCardCreateModal } from '@blocksuite/affine-block-bookmark';
|
||||
import type { DataViewBlockComponent } from '@blocksuite/affine-block-data-view';
|
||||
import {
|
||||
FigmaIcon,
|
||||
GithubIcon,
|
||||
@@ -51,7 +52,6 @@ import type { BlockModel } from '@blocksuite/store';
|
||||
import { Slice, Text } from '@blocksuite/store';
|
||||
import type { TemplateResult } from 'lit';
|
||||
|
||||
import type { DataViewBlockComponent } from '../../../data-view-block/index.js';
|
||||
import type { RootBlockComponent } from '../../types.js';
|
||||
import { formatDate, formatTime } from '../../utils/misc.js';
|
||||
import type { AffineLinkedDocWidget } from '../linked-doc/index.js';
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
// Import models only, the bundled file should not include anything else.
|
||||
import { DataViewBlockSchema } from '@blocksuite/affine-block-data-view';
|
||||
import { SurfaceBlockSchema } from '@blocksuite/affine-block-surface';
|
||||
import {
|
||||
AttachmentBlockSchema,
|
||||
@@ -26,8 +27,6 @@ import {
|
||||
import type { BlockSchema } from '@blocksuite/store';
|
||||
import type { z } from 'zod';
|
||||
|
||||
import { DataViewBlockSchema } from './data-view-block/data-view-model.js';
|
||||
|
||||
/** Built-in first party block models built for affine */
|
||||
export const AffineSchemas: z.infer<typeof BlockSchema>[] = [
|
||||
CodeBlockSchema,
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
||||
import type { SurfaceBlockModel } from '@blocksuite/affine-block-surface';
|
||||
import {
|
||||
MindmapStyleFour,
|
||||
@@ -10,7 +9,9 @@ import {
|
||||
type MindmapElementModel,
|
||||
MindmapStyle,
|
||||
} from '@blocksuite/affine-model';
|
||||
import { MarkdownAdapter } from '@blocksuite/affine-shared/adapters';
|
||||
import { BlockStdScope, type EditorHost } from '@blocksuite/block-std';
|
||||
import type { ServiceProvider } from '@blocksuite/global/di';
|
||||
import { WithDisposable } from '@blocksuite/global/utils';
|
||||
import {
|
||||
type Doc,
|
||||
@@ -24,8 +25,8 @@ import { css, html, LitElement, nothing } from 'lit';
|
||||
import { property, query } from 'lit/decorators.js';
|
||||
import { repeat } from 'lit/directives/repeat.js';
|
||||
import { styleMap } from 'lit/directives/style-map.js';
|
||||
import type { Root } from 'mdast';
|
||||
|
||||
import { MarkdownAdapter } from '../../_common/adapters/markdown/index.js';
|
||||
import { MiniMindmapSchema, MiniMindmapSpecs } from './spec.js';
|
||||
|
||||
const mindmapStyles = [
|
||||
@@ -140,7 +141,7 @@ export class MiniMindmapPreview extends WithDisposable(LitElement) {
|
||||
}
|
||||
|
||||
private _toMindmapNode(answer: string, doc: Doc) {
|
||||
return markdownToMindmap(answer, doc);
|
||||
return markdownToMindmap(answer, doc, this.host.std.provider);
|
||||
}
|
||||
|
||||
override connectedCallback(): void {
|
||||
@@ -240,11 +241,15 @@ type Node = {
|
||||
children: Node[];
|
||||
};
|
||||
|
||||
export const markdownToMindmap = (answer: string, doc: Doc) => {
|
||||
export const markdownToMindmap = (
|
||||
answer: string,
|
||||
doc: Doc,
|
||||
provider: ServiceProvider
|
||||
) => {
|
||||
let result: Node | null = null;
|
||||
const job = new Job({ collection: doc.collection });
|
||||
const markdown = new MarkdownAdapter(job);
|
||||
const ast = markdown['_markdownToAst'](answer);
|
||||
const markdown = new MarkdownAdapter(job, provider);
|
||||
const ast: Root = markdown['_markdownToAst'](answer);
|
||||
const traverse = (
|
||||
markdownNode: Unpacked<(typeof ast)['children']>,
|
||||
firstLevel = false
|
||||
|
||||
@@ -64,6 +64,9 @@
|
||||
{
|
||||
"path": "../affine/block-surface-ref"
|
||||
},
|
||||
{
|
||||
"path": "../affine/block-data-view"
|
||||
},
|
||||
{
|
||||
"path": "../affine/data-view"
|
||||
},
|
||||
|
||||
@@ -5,7 +5,7 @@ import type { DraftModel } from './draft.js';
|
||||
import { fromJSON, toJSON } from './json.js';
|
||||
import type { BlockSnapshot } from './type.js';
|
||||
|
||||
type BlockSnapshotLeaf = Pick<
|
||||
export type BlockSnapshotLeaf = Pick<
|
||||
BlockSnapshot,
|
||||
'id' | 'flavour' | 'props' | 'version'
|
||||
>;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { parseStringToRgba } from '@blocks/root-block/edgeless/components/color-picker/utils.js';
|
||||
import { parseStringToRgba } from '@blocksuite/affine-components/color-picker';
|
||||
import { expect, type Locator, type Page } from '@playwright/test';
|
||||
import { dragBetweenCoords } from 'utils/actions/drag.js';
|
||||
import {
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
"test": "yarn playwright test"
|
||||
},
|
||||
"dependencies": {
|
||||
"@blocksuite/affine-components": "workspace:*",
|
||||
"@blocksuite/affine-model": "workspace:*",
|
||||
"@blocksuite/block-std": "workspace:*",
|
||||
"@blocksuite/global": "workspace:*",
|
||||
|
||||
@@ -34,12 +34,10 @@ yarn affine @affine/server-native build
|
||||
## Prepare dev environment
|
||||
|
||||
```sh
|
||||
cd packages/backend/server
|
||||
|
||||
# uncomment all env variables here
|
||||
cp .env.example .env
|
||||
yarn prisma db push
|
||||
yarn data-migration run
|
||||
cp packages/backend/server/.env.example packages/backend/server/.env
|
||||
yarn affine server prisma db push
|
||||
yarn affine server data-migration run
|
||||
```
|
||||
|
||||
## Start server
|
||||
@@ -74,5 +72,5 @@ Now you should be able to start developing affine with server enabled.
|
||||
|
||||
```sh
|
||||
# available at http://localhost:5555
|
||||
yarn prisma studio
|
||||
yarn affine server prisma studio
|
||||
```
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
"test:copilot": "ava \"tests/**/copilot-*.spec.ts\"",
|
||||
"test:coverage": "c8 ava --concurrency 1 --serial",
|
||||
"test:copilot:coverage": "c8 ava --timeout=5m \"tests/**/copilot-*.spec.ts\"",
|
||||
"data-migration": "cross-env NODE_ENV=script node ./src/data/index.ts",
|
||||
"data-migration": "cross-env NODE_ENV=script r ./src/data/index.ts",
|
||||
"predeploy": "yarn prisma migrate deploy && NODE_ENV=script node --import ./scripts/register.js ./dist/data/index.js run",
|
||||
"postinstall": "prisma generate"
|
||||
},
|
||||
@@ -91,6 +91,7 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@affine-test/kit": "workspace:*",
|
||||
"@affine-tools/cli": "workspace:*",
|
||||
"@affine/server-native": "workspace:*",
|
||||
"@nestjs/testing": "^10.4.15",
|
||||
"@types/cookie-parser": "^1.4.8",
|
||||
|
||||
@@ -11,11 +11,12 @@ import { Lock } from './lock';
|
||||
const lockScript = `local key = KEYS[1]
|
||||
local owner = ARGV[1]
|
||||
|
||||
-- if lock is not exists or lock is owned by the owner
|
||||
-- then set lock to the owner and return 1, otherwise return 0
|
||||
-- if lock is not exists then set lock to the owner and return 1, otherwise return 0
|
||||
-- if the lock is not released correctly due to unexpected reasons
|
||||
-- lock will be released after 60 seconds
|
||||
if redis.call("get", key) == owner or redis.call("set", key, owner, "NX", "EX", 60) then
|
||||
if redis.call("get", key) == owner then
|
||||
return 0
|
||||
elseif redis.call("set", key, owner, "NX", "EX", 60) then
|
||||
return 1
|
||||
else
|
||||
return 0
|
||||
|
||||
@@ -3,6 +3,7 @@ import { randomUUID } from 'node:crypto';
|
||||
import { Inject, Injectable, Logger, Scope } from '@nestjs/common';
|
||||
import { ModuleRef, REQUEST } from '@nestjs/core';
|
||||
import type { Request } from 'express';
|
||||
import { nanoid } from 'nanoid';
|
||||
|
||||
import { GraphqlContext } from '../graphql';
|
||||
import { retryable } from '../utils/promise';
|
||||
@@ -14,7 +15,7 @@ export const MUTEX_WAIT = 100;
|
||||
@Injectable()
|
||||
export class Mutex {
|
||||
protected logger = new Logger(Mutex.name);
|
||||
private readonly clusterIdentifier = `cluster:${randomUUID()}`;
|
||||
private readonly clusterIdentifier = `cluster:${nanoid()}`;
|
||||
|
||||
constructor(protected readonly locker: Locker) {}
|
||||
|
||||
@@ -39,7 +40,10 @@ export class Mutex {
|
||||
* @param key resource key
|
||||
* @returns LockGuard
|
||||
*/
|
||||
async acquire(key: string, owner: string = this.clusterIdentifier) {
|
||||
async acquire(
|
||||
key: string,
|
||||
owner: string = `${this.clusterIdentifier}:${nanoid()}`
|
||||
) {
|
||||
try {
|
||||
return await retryable(
|
||||
() => this.locker.lock(owner, key),
|
||||
|
||||
@@ -176,6 +176,9 @@ export class UserSubscriptionManager extends SubscriptionManager {
|
||||
}
|
||||
: {
|
||||
mode: 'subscription' as const,
|
||||
subscription_data: {
|
||||
...trials,
|
||||
},
|
||||
};
|
||||
|
||||
return this.stripe.checkout.sessions.create({
|
||||
@@ -188,9 +191,6 @@ export class UserSubscriptionManager extends SubscriptionManager {
|
||||
],
|
||||
...mode,
|
||||
...discounts,
|
||||
subscription_data: {
|
||||
...trials,
|
||||
},
|
||||
success_url: this.url.link(params.successCallbackLink),
|
||||
});
|
||||
}
|
||||
|
||||
81
packages/backend/server/tests/mutex.spec.ts
Normal file
81
packages/backend/server/tests/mutex.spec.ts
Normal file
@@ -0,0 +1,81 @@
|
||||
import { randomUUID } from 'node:crypto';
|
||||
|
||||
import { TestingModule } from '@nestjs/testing';
|
||||
import ava, { TestFn } from 'ava';
|
||||
import Sinon from 'sinon';
|
||||
|
||||
import { Locker, Mutex } from '../src/base/mutex';
|
||||
import { SessionRedis } from '../src/base/redis';
|
||||
import { createTestingModule, sleep } from './utils';
|
||||
|
||||
const test = ava as TestFn<{
|
||||
module: TestingModule;
|
||||
mutex: Mutex;
|
||||
locker: Locker;
|
||||
session: SessionRedis;
|
||||
}>;
|
||||
|
||||
test.beforeEach(async t => {
|
||||
const module = await createTestingModule();
|
||||
|
||||
t.context.module = module;
|
||||
t.context.mutex = module.get(Mutex);
|
||||
t.context.locker = module.get(Locker);
|
||||
t.context.session = module.get(SessionRedis);
|
||||
});
|
||||
|
||||
test.afterEach(async t => {
|
||||
await t.context.module.close();
|
||||
});
|
||||
|
||||
const lockerPrefix = randomUUID();
|
||||
test('should be able to acquire lock', async t => {
|
||||
const { mutex } = t.context;
|
||||
|
||||
{
|
||||
t.truthy(
|
||||
await mutex.acquire(`${lockerPrefix}1`),
|
||||
'should be able to acquire lock'
|
||||
);
|
||||
t.falsy(
|
||||
await mutex.acquire(`${lockerPrefix}1`),
|
||||
'should not be able to acquire lock again'
|
||||
);
|
||||
}
|
||||
|
||||
{
|
||||
const lock1 = await mutex.acquire(`${lockerPrefix}2`);
|
||||
t.truthy(lock1);
|
||||
await lock1?.release();
|
||||
const lock2 = await mutex.acquire(`${lockerPrefix}2`);
|
||||
t.truthy(lock2);
|
||||
}
|
||||
});
|
||||
|
||||
test('should be able to acquire lock parallel', async t => {
|
||||
const { mutex, locker } = t.context;
|
||||
const spyedLocker = Sinon.spy(locker, 'lock');
|
||||
const requestLock = async (key: string) => {
|
||||
const lock = mutex.acquire(key);
|
||||
await using _lock = await lock;
|
||||
const lastCall = spyedLocker.lastCall.returnValue;
|
||||
try {
|
||||
// in rare cases, the lock can be acquired
|
||||
// in which case skip the error message check
|
||||
await lastCall;
|
||||
} catch {
|
||||
await t.throwsAsync(lastCall, {
|
||||
message: `Failed to acquire lock for resource [${key}]`,
|
||||
});
|
||||
}
|
||||
|
||||
await sleep(100);
|
||||
};
|
||||
|
||||
await t.notThrowsAsync(
|
||||
Promise.all(
|
||||
Array.from({ length: 10 }, _ => requestLock(`${lockerPrefix}3`))
|
||||
),
|
||||
'should be able to acquire lock parallel'
|
||||
);
|
||||
});
|
||||
@@ -61,6 +61,7 @@ describe('Entity validations', () => {
|
||||
id: f.string().primaryKey().default(nanoid),
|
||||
name: f.string(),
|
||||
color: f.string(),
|
||||
status: f.enum('active', 'inactive').optional(),
|
||||
},
|
||||
});
|
||||
|
||||
@@ -130,4 +131,15 @@ describe('Entity validations', () => {
|
||||
expect(tag.info).toBe(null);
|
||||
});
|
||||
});
|
||||
|
||||
test('should throw when trying to create entity with invalid enum value', () => {
|
||||
const client = createTagsClient();
|
||||
|
||||
expect(() =>
|
||||
// @ts-expect-error test
|
||||
client.tags.create({ name: 'test', status: 'not-active' })
|
||||
).toThrow(
|
||||
"[Table(tags)]: Field 'status' value 'not-active' is not valid. Expected one of [active, inactive]."
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
export type FieldType = 'string' | 'number' | 'boolean' | 'json';
|
||||
export type FieldType = 'string' | 'number' | 'boolean' | 'json' | 'enum';
|
||||
|
||||
export interface FieldSchema<Type = unknown> {
|
||||
type: FieldType;
|
||||
optional: boolean;
|
||||
isPrimaryKey: boolean;
|
||||
default?: () => Type;
|
||||
values?: Type[];
|
||||
}
|
||||
|
||||
export type TableSchema = Record<string, FieldSchema>;
|
||||
@@ -28,10 +29,12 @@ export class FieldSchemaBuilder<
|
||||
optional: false,
|
||||
isPrimaryKey: false,
|
||||
default: undefined,
|
||||
values: undefined,
|
||||
};
|
||||
|
||||
constructor(type: FieldType) {
|
||||
constructor(type: FieldType, values?: string[]) {
|
||||
this.schema.type = type;
|
||||
this.schema.values = values;
|
||||
}
|
||||
|
||||
optional() {
|
||||
@@ -56,7 +59,9 @@ export const f = {
|
||||
number: () => new FieldSchemaBuilder<number>('number'),
|
||||
boolean: () => new FieldSchemaBuilder<boolean>('boolean'),
|
||||
json: <T = any>() => new FieldSchemaBuilder<T>('json'),
|
||||
} satisfies Record<FieldType, () => FieldSchemaBuilder<any>>;
|
||||
enum: <T extends string>(...values: T[]) =>
|
||||
new FieldSchemaBuilder<T>('enum', values),
|
||||
} as const;
|
||||
|
||||
export const t = {
|
||||
document: <T extends TableSchemaBuilder>(schema: T) => {
|
||||
|
||||
@@ -70,7 +70,14 @@ export const dataValidators = {
|
||||
}
|
||||
|
||||
const typeGet = inputType(val);
|
||||
if (!typeMatches(field.type, typeGet)) {
|
||||
|
||||
if (field.type === 'enum') {
|
||||
if (!field.values?.includes(val)) {
|
||||
throw new Error(
|
||||
`[Table(${table.name})]: Field '${key}' value '${val}' is not valid. Expected one of [${field.values?.join(', ')}].`
|
||||
);
|
||||
}
|
||||
} else if (!typeMatches(field.type, typeGet)) {
|
||||
throw new Error(
|
||||
`[Table(${table.name})]: Field '${key}' type mismatch. Expected ${field.type} got ${typeGet}.`
|
||||
);
|
||||
@@ -103,7 +110,13 @@ export const dataValidators = {
|
||||
}
|
||||
|
||||
const typeGet = inputType(val);
|
||||
if (!typeMatches(field.type, typeGet)) {
|
||||
if (field.type === 'enum') {
|
||||
if (!field.values?.includes(val)) {
|
||||
throw new Error(
|
||||
`[Table(${table.name})]: Field '${key}' value '${val}' is not valid. Expected one of [${field.values?.join(', ')}].`
|
||||
);
|
||||
}
|
||||
} else if (!typeMatches(field.type, typeGet)) {
|
||||
throw new Error(
|
||||
`[Table(${table.name})]: Field '${key}' type mismatch. Expected type '${field.type}' but got '${typeGet}'.`
|
||||
);
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
{
|
||||
"extends": "../../../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"composite": true,
|
||||
"target": "ESNext",
|
||||
"module": "ESNext",
|
||||
"resolveJsonModule": true,
|
||||
"moduleResolution": "Node",
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"noEmit": false,
|
||||
"outDir": "./lib/tests",
|
||||
"types": ["node", "affine__env"],
|
||||
"allowJs": true
|
||||
},
|
||||
"references": [
|
||||
{
|
||||
"path": "./tsconfig.json"
|
||||
}
|
||||
],
|
||||
"include": ["./test"]
|
||||
}
|
||||
@@ -2,12 +2,11 @@ import '@sentry/electron/preload';
|
||||
|
||||
import { contextBridge } from 'electron';
|
||||
|
||||
import { appInfo, getElectronAPIs } from './electron-api';
|
||||
import { apis, appInfo, events, requestWebWorkerPort } from './electron-api';
|
||||
import { sharedStorage } from './shared-storage';
|
||||
|
||||
const { apis, events } = getElectronAPIs();
|
||||
|
||||
contextBridge.exposeInMainWorld('__appInfo', appInfo);
|
||||
contextBridge.exposeInMainWorld('__apis', apis);
|
||||
contextBridge.exposeInMainWorld('__events', events);
|
||||
contextBridge.exposeInMainWorld('__sharedStorage', sharedStorage);
|
||||
contextBridge.exposeInMainWorld('__requestWebWorkerPort', requestWebWorkerPort);
|
||||
|
||||
@@ -13,22 +13,6 @@ import {
|
||||
type RendererToHelper,
|
||||
} from '../shared/type';
|
||||
|
||||
export function getElectronAPIs() {
|
||||
const mainAPIs = getMainAPIs();
|
||||
const helperAPIs = getHelperAPIs();
|
||||
|
||||
return {
|
||||
apis: {
|
||||
...mainAPIs.apis,
|
||||
...helperAPIs.apis,
|
||||
},
|
||||
events: {
|
||||
...mainAPIs.events,
|
||||
...helperAPIs.events,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
type Schema =
|
||||
| 'affine'
|
||||
| 'affine-canary'
|
||||
@@ -248,3 +232,60 @@ function getHelperAPIs() {
|
||||
return { apis: {}, events: {} };
|
||||
}
|
||||
}
|
||||
|
||||
const mainAPIs = getMainAPIs();
|
||||
const helperAPIs = getHelperAPIs();
|
||||
|
||||
export const apis = {
|
||||
...mainAPIs.apis,
|
||||
...helperAPIs.apis,
|
||||
};
|
||||
|
||||
export const events = {
|
||||
...mainAPIs.events,
|
||||
...helperAPIs.events,
|
||||
};
|
||||
|
||||
// Create MessagePort that can be used by web workers
|
||||
export function requestWebWorkerPort() {
|
||||
const ch = new MessageChannel();
|
||||
|
||||
const localPort = ch.port1;
|
||||
const remotePort = ch.port2;
|
||||
|
||||
// todo: should be able to let the web worker use the electron APIs directly for better performance
|
||||
const flattenedAPIs = Object.entries(apis).flatMap(([namespace, api]) => {
|
||||
return Object.entries(api as any).map(([method, fn]) => [
|
||||
`${namespace}:${method}`,
|
||||
fn,
|
||||
]);
|
||||
});
|
||||
|
||||
AsyncCall(Object.fromEntries(flattenedAPIs), {
|
||||
channel: createMessagePortChannel(localPort),
|
||||
log: false,
|
||||
});
|
||||
|
||||
const cleanup = () => {
|
||||
remotePort.close();
|
||||
localPort.close();
|
||||
};
|
||||
|
||||
const portId = crypto.randomUUID();
|
||||
|
||||
setTimeout(() => {
|
||||
window.postMessage(
|
||||
{
|
||||
type: 'electron:request-api-port',
|
||||
portId,
|
||||
ports: [remotePort],
|
||||
},
|
||||
'*',
|
||||
[remotePort]
|
||||
);
|
||||
});
|
||||
|
||||
localPort.start();
|
||||
|
||||
return { portId, cleanup };
|
||||
}
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
// TODO(@forehalo): all packages would become 'module'
|
||||
const path = require('node:path');
|
||||
|
||||
module.exports.config = {
|
||||
entry: {
|
||||
app: './renderer/index.tsx',
|
||||
shell: './renderer/shell/index.tsx',
|
||||
},
|
||||
output: {
|
||||
path: path.resolve(__dirname, './renderer/dist'),
|
||||
},
|
||||
};
|
||||
@@ -30,10 +30,14 @@ import {
|
||||
} from '@affine/core/modules/workspace-engine';
|
||||
import { I18n } from '@affine/i18n';
|
||||
import {
|
||||
defaultBlockMarkdownAdapterMatchers,
|
||||
docLinkBaseURLMiddleware,
|
||||
inlineDeltaToMarkdownAdapterMatchers,
|
||||
MarkdownAdapter,
|
||||
markdownInlineToDeltaMatchers,
|
||||
titleMiddleware,
|
||||
} from '@blocksuite/affine/blocks';
|
||||
import { Container } from '@blocksuite/affine/global/di';
|
||||
import { Job } from '@blocksuite/affine/store';
|
||||
import { App as CapacitorApp } from '@capacitor/app';
|
||||
import { Browser } from '@capacitor/browser';
|
||||
@@ -175,7 +179,17 @@ const frameworkProvider = framework.provider();
|
||||
});
|
||||
const snapshot = job.docToSnapshot(blockSuiteDoc);
|
||||
|
||||
const adapter = new MarkdownAdapter(job);
|
||||
const container = new Container();
|
||||
[
|
||||
...markdownInlineToDeltaMatchers,
|
||||
...defaultBlockMarkdownAdapterMatchers,
|
||||
...inlineDeltaToMarkdownAdapterMatchers,
|
||||
].forEach(ext => {
|
||||
ext.setup(container);
|
||||
});
|
||||
const provider = container.provider();
|
||||
|
||||
const adapter = new MarkdownAdapter(job, provider);
|
||||
if (!snapshot) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -10,10 +10,14 @@ import type {
|
||||
} from '@blocksuite/affine/blocks';
|
||||
import {
|
||||
CodeBlockComponent,
|
||||
defaultBlockMarkdownAdapterMatchers,
|
||||
DividerBlockComponent,
|
||||
inlineDeltaToMarkdownAdapterMatchers,
|
||||
ListBlockComponent,
|
||||
markdownInlineToDeltaMatchers,
|
||||
ParagraphBlockComponent,
|
||||
} from '@blocksuite/affine/blocks';
|
||||
import { Container, type ServiceProvider } from '@blocksuite/affine/global/di';
|
||||
import { WithDisposable } from '@blocksuite/affine/global/utils';
|
||||
import {
|
||||
BlockViewType,
|
||||
@@ -192,8 +196,28 @@ export class TextRenderer extends WithDisposable(ShadowlessElement) {
|
||||
const latestAnswer = this._answers.pop();
|
||||
this._answers = [];
|
||||
const schema = this.schema ?? this.host?.std.doc.collection.schema;
|
||||
let provider: ServiceProvider;
|
||||
if (this.host) {
|
||||
provider = this.host.std.provider;
|
||||
} else {
|
||||
const container = new Container();
|
||||
[
|
||||
...markdownInlineToDeltaMatchers,
|
||||
...defaultBlockMarkdownAdapterMatchers,
|
||||
...inlineDeltaToMarkdownAdapterMatchers,
|
||||
].forEach(ext => {
|
||||
ext.setup(container);
|
||||
});
|
||||
|
||||
provider = container.provider();
|
||||
}
|
||||
if (latestAnswer && schema) {
|
||||
markDownToDoc(schema, latestAnswer, this.options.additionalMiddlewares)
|
||||
markDownToDoc(
|
||||
provider,
|
||||
schema,
|
||||
latestAnswer,
|
||||
this.options.additionalMiddlewares
|
||||
)
|
||||
.then(doc => {
|
||||
this.disposeDoc();
|
||||
this._doc = doc.blockCollection.getDoc({
|
||||
|
||||
@@ -12,6 +12,7 @@ import {
|
||||
PlainTextAdapter,
|
||||
titleMiddleware,
|
||||
} from '@blocksuite/affine/blocks';
|
||||
import type { ServiceProvider } from '@blocksuite/affine/global/di';
|
||||
import type { JobMiddleware, Schema } from '@blocksuite/affine/store';
|
||||
import { DocCollection, Job } from '@blocksuite/affine/store';
|
||||
import { assertExists } from '@blocksuite/global/utils';
|
||||
@@ -87,7 +88,7 @@ export async function getContentFromSlice(
|
||||
processTextInSnapshot(snapshot, host);
|
||||
const adapter =
|
||||
type === 'markdown'
|
||||
? new MarkdownAdapter(job)
|
||||
? new MarkdownAdapter(job, host.std.provider)
|
||||
: new PlainTextAdapter(job, host.std.provider);
|
||||
const content = await adapter.fromSliceSnapshot({
|
||||
snapshot,
|
||||
@@ -122,7 +123,7 @@ export const markdownToSnapshot = async (
|
||||
collection: host.std.doc.collection,
|
||||
middlewares: [defaultImageProxyMiddleware, pasteMiddleware(host.std)],
|
||||
});
|
||||
const markdownAdapter = new MixTextAdapter(job);
|
||||
const markdownAdapter = new MixTextAdapter(job, host.std.provider);
|
||||
const { blockVersions, workspaceVersion, pageVersion } =
|
||||
host.std.doc.collection.meta;
|
||||
if (!blockVersions || !workspaceVersion || !pageVersion)
|
||||
@@ -188,6 +189,7 @@ export async function replaceFromMarkdown(
|
||||
}
|
||||
|
||||
export async function markDownToDoc(
|
||||
provider: ServiceProvider,
|
||||
schema: Schema,
|
||||
answer: string,
|
||||
additionalMiddlewares?: JobMiddleware[]
|
||||
@@ -205,7 +207,7 @@ export async function markDownToDoc(
|
||||
collection,
|
||||
middlewares,
|
||||
});
|
||||
const mdAdapter = new MarkdownAdapter(job);
|
||||
const mdAdapter = new MarkdownAdapter(job, provider);
|
||||
const doc = await mdAdapter.toDoc({
|
||||
file: answer,
|
||||
assets: job.assetsManager,
|
||||
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
UnauthorizedError,
|
||||
} from '@blocksuite/affine/blocks';
|
||||
import { WithDisposable } from '@blocksuite/affine/global/utils';
|
||||
import { css, html, nothing, type PropertyValues } from 'lit';
|
||||
import { css, html, nothing } from 'lit';
|
||||
import { property, query, state } from 'lit/decorators.js';
|
||||
import { repeat } from 'lit/directives/repeat.js';
|
||||
import { styleMap } from 'lit/directives/style-map.js';
|
||||
@@ -139,25 +139,6 @@ export class ChatPanelMessages extends WithDisposable(ShadowlessElement) {
|
||||
@state()
|
||||
accessor showChatCards = true;
|
||||
|
||||
protected override updated(changedProperties: PropertyValues) {
|
||||
if (changedProperties.has('host')) {
|
||||
const { disposables } = this;
|
||||
|
||||
disposables.add(
|
||||
this.host.selection.slots.changed.on(() => {
|
||||
this._selectionValue = this.host.selection.value;
|
||||
})
|
||||
);
|
||||
const docModeService = this.host.std.get(DocModeProvider);
|
||||
disposables.add(
|
||||
docModeService.onPrimaryModeChange(
|
||||
() => this.requestUpdate(),
|
||||
this.host.doc.id
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private _renderAIOnboarding() {
|
||||
return this.isLoading ||
|
||||
!this.host?.doc.awarenessStore.getFlag('enable_ai_onboarding')
|
||||
@@ -284,13 +265,16 @@ export class ChatPanelMessages extends WithDisposable(ShadowlessElement) {
|
||||
|
||||
override connectedCallback() {
|
||||
super.connectedCallback();
|
||||
const { disposables } = this;
|
||||
const docModeService = this.host.std.get(DocModeProvider);
|
||||
|
||||
Promise.resolve(AIProvider.userInfo)
|
||||
.then(res => {
|
||||
this.avatarUrl = res?.avatarUrl ?? '';
|
||||
})
|
||||
.catch(console.error);
|
||||
this.disposables.add(
|
||||
|
||||
disposables.add(
|
||||
AIProvider.slots.userInfo.on(userInfo => {
|
||||
const { status, error } = this.chatContextValue;
|
||||
this.avatarUrl = userInfo?.avatarUrl ?? '';
|
||||
@@ -303,12 +287,22 @@ export class ChatPanelMessages extends WithDisposable(ShadowlessElement) {
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
this.disposables.add(
|
||||
disposables.add(
|
||||
AIProvider.slots.toggleChatCards.on(({ visible }) => {
|
||||
this.showChatCards = visible;
|
||||
})
|
||||
);
|
||||
disposables.add(
|
||||
this.host.selection.slots.changed.on(() => {
|
||||
this._selectionValue = this.host.selection.value;
|
||||
})
|
||||
);
|
||||
disposables.add(
|
||||
docModeService.onPrimaryModeChange(
|
||||
() => this.requestUpdate(),
|
||||
this.host.doc.id
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
renderItem(item: ChatItem, isLast: boolean) {
|
||||
|
||||
@@ -191,8 +191,10 @@ export class ChatPanel extends WithDisposable(ShadowlessElement) {
|
||||
|
||||
protected override updated(_changedProperties: PropertyValues) {
|
||||
if (_changedProperties.has('doc')) {
|
||||
this.chatContextValue.chatSessionId = null;
|
||||
this._resetItems();
|
||||
requestAnimationFrame(() => {
|
||||
this.chatContextValue.chatSessionId = null;
|
||||
this._resetItems();
|
||||
});
|
||||
}
|
||||
|
||||
if (
|
||||
|
||||
@@ -64,7 +64,7 @@ export const createMindmapExecuteRenderer: (
|
||||
}
|
||||
|
||||
ctx.set({
|
||||
node: markdownToMindmap(answer, host.doc),
|
||||
node: markdownToMindmap(answer, host.doc, host.std.provider),
|
||||
});
|
||||
|
||||
handler(host, ctx);
|
||||
|
||||
@@ -143,7 +143,11 @@ export const copyTextAnswer = async (panel: AffineAIPanelWidget) => {
|
||||
};
|
||||
|
||||
export const copyText = async (host: EditorHost, text: string) => {
|
||||
const previewDoc = await markDownToDoc(host.std.doc.schema, text);
|
||||
const previewDoc = await markDownToDoc(
|
||||
host.std.provider,
|
||||
host.std.doc.schema,
|
||||
text
|
||||
);
|
||||
const models = previewDoc
|
||||
.getBlocksByFlavour('affine:note')
|
||||
.map(b => b.model)
|
||||
|
||||
@@ -143,12 +143,12 @@ const CloudWorkSpaceList = ({
|
||||
),
|
||||
accountStatus === 'authenticated' && (
|
||||
<MenuItem key="sign-out" onClick={handleSignOut}>
|
||||
{t['com.affine.sign.out']()}
|
||||
{t['Sign out']()}
|
||||
</MenuItem>
|
||||
),
|
||||
accountStatus === 'unauthenticated' && (
|
||||
<MenuItem key="sign-in" onClick={handleSignIn}>
|
||||
{t['com.affine.sign.in']()}
|
||||
{t['Sign in']()}
|
||||
</MenuItem>
|
||||
),
|
||||
]}
|
||||
|
||||
@@ -206,6 +206,7 @@ const Dialog = ({
|
||||
loading={disabled}
|
||||
disabled={disabled}
|
||||
onClick={handleImportToSelectedWorkspace}
|
||||
data-testid="import-template-to-workspace-btn"
|
||||
>
|
||||
{selectedWorkspaceName &&
|
||||
t['com.affine.import-template.dialog.createDocToWorkspace']({
|
||||
|
||||
@@ -16,11 +16,15 @@ export const Component = () => {
|
||||
const [searchParams] = useSearchParams();
|
||||
const { jumpToIndex } = useNavigateHelper();
|
||||
useEffect(() => {
|
||||
globalDialogService.open('import-template', {
|
||||
const id = globalDialogService.open('import-template', {
|
||||
templateName: searchParams.get('name') ?? '',
|
||||
templateMode: (searchParams.get('mode') as DocMode) ?? 'page',
|
||||
snapshotUrl: searchParams.get('snapshotUrl') ?? '',
|
||||
});
|
||||
|
||||
return () => {
|
||||
globalDialogService.close(id);
|
||||
};
|
||||
}, [globalDialogService, jumpToIndex, searchParams]);
|
||||
// no ui for this route, just open the dialog
|
||||
return null;
|
||||
|
||||
@@ -429,7 +429,7 @@ export class AtMenuConfigService extends Service {
|
||||
|
||||
// only search docs by title, excluding blocks
|
||||
private searchDocs$(query: string) {
|
||||
return this.docsSearch.indexer.blockIndex
|
||||
return this.docsSearch.indexer.docIndex
|
||||
.aggregate$(
|
||||
{
|
||||
type: 'boolean',
|
||||
@@ -437,32 +437,21 @@ export class AtMenuConfigService extends Service {
|
||||
queries: [
|
||||
{
|
||||
type: 'match',
|
||||
field: 'content',
|
||||
field: 'title',
|
||||
match: query,
|
||||
},
|
||||
{
|
||||
type: 'boolean',
|
||||
occur: 'should',
|
||||
queries: [
|
||||
{
|
||||
type: 'match',
|
||||
field: 'flavour',
|
||||
match: 'affine:page',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
'docId',
|
||||
{
|
||||
hits: {
|
||||
fields: ['docId', 'content'],
|
||||
fields: ['docId', 'title'],
|
||||
pagination: {
|
||||
limit: 1,
|
||||
},
|
||||
highlights: [
|
||||
{
|
||||
field: 'content',
|
||||
field: 'title',
|
||||
before: `<span style="color: ${cssVarV2('text/emphasis')}">`,
|
||||
end: '</span>',
|
||||
},
|
||||
@@ -475,8 +464,8 @@ export class AtMenuConfigService extends Service {
|
||||
buckets.map(bucket => {
|
||||
return {
|
||||
id: bucket.key,
|
||||
title: bucket.hits.nodes[0].fields.content,
|
||||
highlights: bucket.hits.nodes[0].highlights.content[0],
|
||||
title: bucket.hits.nodes[0].fields.title,
|
||||
highlights: bucket.hits.nodes[0].highlights.title[0],
|
||||
};
|
||||
})
|
||||
)
|
||||
|
||||
@@ -26,7 +26,7 @@ export const AFFiNE_WORKSPACE_DB_SCHEMA = {
|
||||
id: f.string().primaryKey().optional().default(nanoid),
|
||||
name: f.string().optional(),
|
||||
type: f.string(),
|
||||
show: f.string().optional(),
|
||||
show: f.enum('always-show', 'always-hide', 'hide-when-empty').optional(),
|
||||
index: f.string().optional(),
|
||||
icon: f.string().optional(),
|
||||
additionalData: f.json().optional(),
|
||||
|
||||
@@ -1,10 +1,17 @@
|
||||
import { getElectronAPIs } from '@affine/electron-api/web-worker';
|
||||
import type {
|
||||
AttachmentBlockModel,
|
||||
BookmarkBlockModel,
|
||||
EmbedBlockModel,
|
||||
ImageBlockModel,
|
||||
} from '@blocksuite/affine/blocks';
|
||||
import { MarkdownAdapter } from '@blocksuite/affine/blocks';
|
||||
import {
|
||||
defaultBlockMarkdownAdapterMatchers,
|
||||
inlineDeltaToMarkdownAdapterMatchers,
|
||||
MarkdownAdapter,
|
||||
markdownInlineToDeltaMatchers,
|
||||
} from '@blocksuite/affine/blocks';
|
||||
import { Container } from '@blocksuite/affine/global/di';
|
||||
import {
|
||||
createYProxy,
|
||||
DocCollection,
|
||||
@@ -43,6 +50,11 @@ const LRU_CACHE_SIZE = 5;
|
||||
// lru cache for ydoc instances, last used at the end of the array
|
||||
const lruCache = [] as { doc: YDoc; hash: string }[];
|
||||
|
||||
const electronAPIs = BUILD_CONFIG.isElectron ? getElectronAPIs() : null;
|
||||
|
||||
// @ts-expect-error test
|
||||
globalThis.__electronAPIs = electronAPIs;
|
||||
|
||||
async function digest(data: Uint8Array) {
|
||||
if (
|
||||
globalThis.crypto &&
|
||||
@@ -168,11 +180,22 @@ function generateMarkdownPreviewBuilder(
|
||||
adapterConfigs.set('docLinkBaseUrl', baseUrl);
|
||||
};
|
||||
|
||||
const container = new Container();
|
||||
[
|
||||
...markdownInlineToDeltaMatchers,
|
||||
...defaultBlockMarkdownAdapterMatchers,
|
||||
...inlineDeltaToMarkdownAdapterMatchers,
|
||||
].forEach(ext => {
|
||||
ext.setup(container);
|
||||
});
|
||||
|
||||
const provider = container.provider();
|
||||
const markdownAdapter = new MarkdownAdapter(
|
||||
new Job({
|
||||
collection: markdownPreviewDocCollection,
|
||||
middlewares: [docLinkBaseURLMiddleware, titleMiddleware],
|
||||
})
|
||||
}),
|
||||
provider
|
||||
);
|
||||
|
||||
const markdownPreviewCache = new WeakMap<BlockDocumentInfo, string | null>();
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { DebugLogger } from '@affine/debug';
|
||||
import { connectWebWorker } from '@affine/electron-api/web-worker';
|
||||
import { MANUALLY_STOP, throwIfAborted } from '@toeverything/infra';
|
||||
|
||||
import type {
|
||||
@@ -12,6 +13,7 @@ const logger = new DebugLogger('affine:indexer-worker');
|
||||
|
||||
export async function createWorker(abort: AbortSignal) {
|
||||
let worker: Worker | null = null;
|
||||
let electronApiCleanup: (() => void) | null = null;
|
||||
while (throwIfAborted(abort)) {
|
||||
try {
|
||||
worker = await new Promise<Worker>((resolve, reject) => {
|
||||
@@ -29,6 +31,11 @@ export async function createWorker(abort: AbortSignal) {
|
||||
}
|
||||
});
|
||||
worker.postMessage({ type: 'init', msgId: 0 } as WorkerIngoingMessage);
|
||||
|
||||
if (BUILD_CONFIG.isElectron) {
|
||||
electronApiCleanup = connectWebWorker(worker);
|
||||
}
|
||||
|
||||
setTimeout(() => {
|
||||
reject('timeout');
|
||||
}, 1000 * 30 /* 30 sec */);
|
||||
@@ -97,6 +104,7 @@ export async function createWorker(abort: AbortSignal) {
|
||||
dispose: () => {
|
||||
terminateAbort.abort(MANUALLY_STOP);
|
||||
worker.terminate();
|
||||
electronApiCleanup?.();
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user