mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-14 13:25:12 +00:00
refactor(editor): remove re-exports (#9406)
This commit is contained in:
@@ -1 +0,0 @@
|
||||
export { GfxBlockElementModel as GfxBlockModel } from '@blocksuite/block-std/gfx';
|
||||
@@ -1,11 +1,10 @@
|
||||
import type { EmbedCardStyle } from '@blocksuite/affine-model';
|
||||
import { WithDisposable } from '@blocksuite/global/utils';
|
||||
import { css, html, LitElement, nothing, type TemplateResult } from 'lit';
|
||||
import { property } from 'lit/decorators.js';
|
||||
import { classMap } from 'lit/directives/class-map.js';
|
||||
import { repeat } from 'lit/directives/repeat.js';
|
||||
|
||||
import type { EmbedCardStyle } from '../../../../_common/types.js';
|
||||
|
||||
export class CardStylePanel extends WithDisposable(LitElement) {
|
||||
static override styles = css`
|
||||
:host {
|
||||
|
||||
@@ -3,8 +3,8 @@ import {
|
||||
LassoFreeHandIcon,
|
||||
LassoPolygonalIcon,
|
||||
} from '@blocksuite/affine-components/icons';
|
||||
import { LassoMode } from '@blocksuite/affine-shared/types';
|
||||
|
||||
import { LassoMode } from '../../../../../_common/types.js';
|
||||
import type { DenseMenuBuilder } from '../common/type.js';
|
||||
|
||||
export const buildLassoDenseMenu: DenseMenuBuilder = edgeless => {
|
||||
|
||||
@@ -3,13 +3,13 @@ import {
|
||||
LassoFreeHandIcon,
|
||||
LassoPolygonalIcon,
|
||||
} from '@blocksuite/affine-components/icons';
|
||||
import { LassoMode } from '@blocksuite/affine-shared/types';
|
||||
import { WithDisposable } from '@blocksuite/global/utils';
|
||||
import { effect } from '@preact/signals-core';
|
||||
import { css, html, LitElement } from 'lit';
|
||||
import { query, state } from 'lit/decorators.js';
|
||||
import { styleMap } from 'lit/directives/style-map.js';
|
||||
|
||||
import { LassoMode } from '../../../../../_common/types.js';
|
||||
import { getTooltipWithShortcut } from '../../utils.js';
|
||||
import { QuickToolMixin } from '../mixins/quick-tool.mixin.js';
|
||||
|
||||
|
||||
@@ -13,10 +13,9 @@ import {
|
||||
QuoteIcon,
|
||||
TextIcon,
|
||||
} from '@blocksuite/affine-components/icons';
|
||||
import type { NoteChildrenFlavour } from '@blocksuite/affine-shared/types';
|
||||
import type { TemplateResult } from 'lit';
|
||||
|
||||
import type { NoteChildrenFlavour } from '../../../../../_common/utils/index.js';
|
||||
|
||||
export const BUTTON_GROUP_LENGTH = 10;
|
||||
|
||||
export type NoteMenuItem = {
|
||||
|
||||
@@ -3,17 +3,17 @@ import { addImages, LoadedImageIcon } from '@blocksuite/affine-block-image';
|
||||
import { AttachmentIcon, LinkIcon } from '@blocksuite/affine-components/icons';
|
||||
import { MAX_IMAGE_WIDTH } from '@blocksuite/affine-model';
|
||||
import { TelemetryProvider } from '@blocksuite/affine-shared/services';
|
||||
import type { NoteChildrenFlavour } from '@blocksuite/affine-shared/types';
|
||||
import {
|
||||
getImageFilesFromLocal,
|
||||
openFileOrFiles,
|
||||
} from '@blocksuite/affine-shared/utils';
|
||||
import type { GfxToolsFullOptionValue } from '@blocksuite/block-std/gfx';
|
||||
import { effect } from '@preact/signals-core';
|
||||
import { css, html, LitElement } from 'lit';
|
||||
import { property, state } from 'lit/decorators.js';
|
||||
import { repeat } from 'lit/directives/repeat.js';
|
||||
|
||||
import {
|
||||
getImageFilesFromLocal,
|
||||
type NoteChildrenFlavour,
|
||||
openFileOrFiles,
|
||||
} from '../../../../../_common/utils/index.js';
|
||||
import type { NoteToolOption } from '../../../gfx-tool/note-tool.js';
|
||||
import { getTooltipWithShortcut } from '../../utils.js';
|
||||
import { EdgelessToolbarToolMixin } from '../mixins/tool.mixin.js';
|
||||
|
||||
@@ -13,8 +13,10 @@ import {
|
||||
EditPropsStore,
|
||||
TelemetryProvider,
|
||||
} from '@blocksuite/affine-shared/services';
|
||||
import { LassoMode } from '@blocksuite/affine-shared/types';
|
||||
import { matchFlavours } from '@blocksuite/affine-shared/utils';
|
||||
import {
|
||||
GfxBlockElementModel,
|
||||
type GfxToolsMap,
|
||||
type GfxToolsOption,
|
||||
isGfxGroupCompatibleModel,
|
||||
@@ -27,9 +29,7 @@ import {
|
||||
isElementOutsideViewport,
|
||||
isSingleMindMapNode,
|
||||
} from '../../_common/edgeless/mindmap/index.js';
|
||||
import { LassoMode } from '../../_common/types.js';
|
||||
import { PageKeyboardManager } from '../keyboard/keyboard-manager.js';
|
||||
import { GfxBlockModel } from './block-model.js';
|
||||
import type { EdgelessRootBlockComponent } from './edgeless-root-block.js';
|
||||
import { CopilotTool } from './gfx-tool/copilot-tool.js';
|
||||
import { LassoTool } from './gfx-tool/lasso-tool.js';
|
||||
@@ -115,8 +115,8 @@ export class EdgelessPageKeyboardManager extends PageKeyboardManager {
|
||||
|
||||
if (
|
||||
selection.selectedElements.length === 1 &&
|
||||
selection.firstElement instanceof GfxBlockModel &&
|
||||
matchFlavours(selection.firstElement as GfxBlockModel, [
|
||||
selection.firstElement instanceof GfxBlockElementModel &&
|
||||
matchFlavours(selection.firstElement as GfxBlockElementModel, [
|
||||
'affine:note',
|
||||
])
|
||||
) {
|
||||
|
||||
@@ -15,6 +15,7 @@ import {
|
||||
FontLoaderService,
|
||||
ThemeProvider,
|
||||
} from '@blocksuite/affine-shared/services';
|
||||
import type { Viewport } from '@blocksuite/affine-shared/types';
|
||||
import {
|
||||
isTouchPadPinchEvent,
|
||||
requestConnectedFrame,
|
||||
@@ -38,7 +39,6 @@ import { query } from 'lit/decorators.js';
|
||||
import { repeat } from 'lit/directives/repeat.js';
|
||||
|
||||
import { isSingleMindMapNode } from '../../_common/edgeless/mindmap/index.js';
|
||||
import type { Viewport } from '../../_common/utils/index.js';
|
||||
import type { EdgelessRootBlockWidgetName } from '../types.js';
|
||||
import { EdgelessClipboardController } from './clipboard/clipboard.js';
|
||||
import type { EdgelessSelectedRectWidget } from './components/rects/edgeless-selected-rect.js';
|
||||
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
FontLoaderService,
|
||||
ThemeProvider,
|
||||
} from '@blocksuite/affine-shared/services';
|
||||
import { requestThrottledConnectedFrame } from '@blocksuite/affine-shared/utils';
|
||||
import type {
|
||||
GfxBlockComponent,
|
||||
SurfaceSelection,
|
||||
@@ -17,7 +18,6 @@ import { assertExists } from '@blocksuite/global/utils';
|
||||
import { css, html } from 'lit';
|
||||
import { query, state } from 'lit/decorators.js';
|
||||
|
||||
import { requestThrottledConnectedFrame } from '../../_common/utils/index.js';
|
||||
import type { EdgelessRootBlockWidgetName } from '../types.js';
|
||||
import type { EdgelessRootService } from './edgeless-root-service.js';
|
||||
import { getBackgroundGrid, isCanvasElement } from './utils/query.js';
|
||||
|
||||
@@ -23,6 +23,7 @@ import type {
|
||||
ReorderingDirection,
|
||||
} from '@blocksuite/block-std/gfx';
|
||||
import {
|
||||
GfxBlockElementModel,
|
||||
GfxControllerIdentifier,
|
||||
GfxExtensionIdentifier,
|
||||
isGfxGroupCompatibleModel,
|
||||
@@ -32,7 +33,6 @@ import { Bound, getCommonBound } from '@blocksuite/global/utils';
|
||||
import { effect } from '@preact/signals-core';
|
||||
|
||||
import { RootService } from '../root-service.js';
|
||||
import { GfxBlockModel } from './block-model.js';
|
||||
import type { EdgelessFrameManager } from './frame-manager.js';
|
||||
import { TemplateJob } from './services/template.js';
|
||||
import {
|
||||
@@ -60,7 +60,7 @@ export class EdgelessRootService extends RootService implements SurfaceContext {
|
||||
|
||||
TemplateJob = TemplateJob;
|
||||
|
||||
get blocks(): GfxBlockModel[] {
|
||||
get blocks(): GfxBlockElementModel[] {
|
||||
return this.layer.blocks;
|
||||
}
|
||||
|
||||
@@ -358,7 +358,7 @@ export class EdgelessRootService extends RootService implements SurfaceContext {
|
||||
});
|
||||
}
|
||||
|
||||
if (el instanceof GfxBlockModel) {
|
||||
if (el instanceof GfxBlockElementModel) {
|
||||
this.doc.deleteBlock(el);
|
||||
return;
|
||||
}
|
||||
@@ -376,7 +376,7 @@ export class EdgelessRootService extends RootService implements SurfaceContext {
|
||||
const index = this.layer.getReorderedIndex(element, direction);
|
||||
|
||||
// block should be updated in transaction
|
||||
if (element instanceof GfxBlockModel) {
|
||||
if (element instanceof GfxBlockElementModel) {
|
||||
this.doc.transact(() => {
|
||||
element.index = index;
|
||||
});
|
||||
|
||||
@@ -3,6 +3,7 @@ import { Overlay } from '@blocksuite/affine-block-surface';
|
||||
import {
|
||||
generateKeyBetweenV2,
|
||||
getTopElements,
|
||||
GfxBlockElementModel,
|
||||
type GfxController,
|
||||
GfxExtension,
|
||||
GfxExtensionIdentifier,
|
||||
@@ -22,7 +23,6 @@ import type { Doc } from '@blocksuite/store';
|
||||
import { DocCollection, Text } from '@blocksuite/store';
|
||||
|
||||
import type { FrameBlockModel, NoteBlockModel } from '../../index.js';
|
||||
import { GfxBlockModel } from './block-model.js';
|
||||
import { areSetsEqual } from './utils/misc.js';
|
||||
import { isFrameBlock } from './utils/query.js';
|
||||
|
||||
@@ -254,7 +254,7 @@ export class EdgelessFrameManager extends GfxExtension {
|
||||
doc.slots.blockUpdated.on(payload => {
|
||||
if (
|
||||
payload.type === 'add' &&
|
||||
payload.model instanceof GfxBlockModel &&
|
||||
payload.model instanceof GfxBlockElementModel &&
|
||||
renderableInEdgeless(doc, surfaceModel, payload.model)
|
||||
) {
|
||||
const frame = this.getFrameFromPoint(
|
||||
@@ -454,7 +454,7 @@ export class EdgelessFrameManager extends GfxExtension {
|
||||
|
||||
removeFromParentFrame(element: GfxModel) {
|
||||
const parentFrame = this.getParentFrame(element);
|
||||
// eslint-disable-next-line unicorn/prefer-dom-node-remove
|
||||
// oxlint-disable-next-line unicorn/prefer-dom-node-remove
|
||||
parentFrame?.removeChild(element);
|
||||
}
|
||||
|
||||
@@ -499,7 +499,7 @@ export function getBlocksInFrameBound(
|
||||
).concat(
|
||||
surface.children.filter(ele => {
|
||||
if (ele.id === model.id) return false;
|
||||
if (ele instanceof GfxBlockModel) {
|
||||
if (ele instanceof GfxBlockElementModel) {
|
||||
const blockBound = Bound.deserialize(ele.xywh);
|
||||
return fullyContained
|
||||
? bound.contains(blockBound)
|
||||
|
||||
@@ -25,6 +25,7 @@ import type { PointerEventState } from '@blocksuite/block-std';
|
||||
import {
|
||||
BaseTool,
|
||||
getTopElements,
|
||||
type GfxBlockElementModel,
|
||||
GfxExtensionIdentifier,
|
||||
type GfxModel,
|
||||
type GfxPrimitiveElementModel,
|
||||
@@ -43,7 +44,6 @@ import {
|
||||
import { effect } from '@preact/signals-core';
|
||||
|
||||
import { isSingleMindMapNode } from '../../../_common/edgeless/mindmap/index.js';
|
||||
import type { GfxBlockModel } from '../block-model.js';
|
||||
import type { EdgelessRootBlockComponent } from '../edgeless-root-block.js';
|
||||
import type { EdgelessFrameManager, FrameOverlay } from '../frame-manager.js';
|
||||
import { prepareCloneData } from '../utils/clone-utils.js';
|
||||
@@ -116,8 +116,8 @@ export class DefaultTool extends BaseTool {
|
||||
};
|
||||
|
||||
private readonly _pendingUpdates = new Map<
|
||||
GfxBlockModel | GfxPrimitiveElementModel,
|
||||
Partial<GfxBlockModel>
|
||||
GfxBlockElementModel | GfxPrimitiveElementModel,
|
||||
Partial<GfxBlockElementModel>
|
||||
>();
|
||||
|
||||
private _rafId: number | null = null;
|
||||
@@ -544,8 +544,8 @@ export class DefaultTool extends BaseTool {
|
||||
}
|
||||
|
||||
private _scheduleUpdate(
|
||||
element: GfxBlockModel | GfxPrimitiveElementModel,
|
||||
updates: Partial<GfxBlockModel>
|
||||
element: GfxBlockElementModel | GfxPrimitiveElementModel,
|
||||
updates: Partial<GfxBlockElementModel>
|
||||
) {
|
||||
this._pendingUpdates.set(element, updates);
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import {
|
||||
type SurfaceBlockComponent,
|
||||
} from '@blocksuite/affine-block-surface';
|
||||
import { ThemeProvider } from '@blocksuite/affine-shared/services';
|
||||
import { LassoMode } from '@blocksuite/affine-shared/types';
|
||||
import type { PointerEventState } from '@blocksuite/block-std';
|
||||
import { BaseTool } from '@blocksuite/block-std/gfx';
|
||||
import type { IPoint, IVec } from '@blocksuite/global/utils';
|
||||
@@ -17,8 +18,6 @@ import {
|
||||
Vec,
|
||||
} from '@blocksuite/global/utils';
|
||||
|
||||
import { LassoMode } from '../../../_common/types.js';
|
||||
|
||||
class LassoOverlay extends Overlay {
|
||||
d = '';
|
||||
|
||||
|
||||
@@ -4,15 +4,13 @@ import {
|
||||
DEFAULT_NOTE_WIDTH,
|
||||
} from '@blocksuite/affine-model';
|
||||
import { EditPropsStore } from '@blocksuite/affine-shared/services';
|
||||
import type { NoteChildrenFlavour } from '@blocksuite/affine-shared/types';
|
||||
import type { PointerEventState } from '@blocksuite/block-std';
|
||||
import { BaseTool } from '@blocksuite/block-std/gfx';
|
||||
import { Point } from '@blocksuite/global/utils';
|
||||
import { effect } from '@preact/signals-core';
|
||||
|
||||
import {
|
||||
hasClassNameInList,
|
||||
type NoteChildrenFlavour,
|
||||
} from '../../../_common/utils/index.js';
|
||||
import { hasClassNameInList } from '../../../_common/utils/index.js';
|
||||
import { addNote } from '../utils/common.js';
|
||||
import { EXCLUDING_MOUSE_OUT_CLASS_LIST } from '../utils/consts.js';
|
||||
import { DraggingNoteOverlay, NoteOverlay } from '../utils/tool-overlay.js';
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
export { GfxBlockModel as EdgelessBlockModel } from './block-model.js';
|
||||
export { FramePreview } from './components/frame/frame-preview.js';
|
||||
export * from './edgeless-root-block.js';
|
||||
export { EdgelessRootService } from './edgeless-root-service.js';
|
||||
|
||||
@@ -13,14 +13,13 @@ import {
|
||||
import type { BlockStdScope } from '@blocksuite/block-std';
|
||||
import {
|
||||
getTopElements,
|
||||
GfxBlockElementModel,
|
||||
type GfxModel,
|
||||
isGfxGroupCompatibleModel,
|
||||
type SerializedElement,
|
||||
} from '@blocksuite/block-std/gfx';
|
||||
import { type BlockSnapshot, Job } from '@blocksuite/store';
|
||||
|
||||
import { GfxBlockModel } from '../block-model.js';
|
||||
|
||||
/**
|
||||
* return all elements in the tree of the elements
|
||||
*/
|
||||
@@ -55,7 +54,7 @@ export function serializeElement(
|
||||
elements: GfxModel[],
|
||||
job: Job
|
||||
) {
|
||||
if (element instanceof GfxBlockModel) {
|
||||
if (element instanceof GfxBlockElementModel) {
|
||||
const snapshot = job.blockToSnapshot(element);
|
||||
if (!snapshot) {
|
||||
return;
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import type { GfxBlockElementModel } from '@blocksuite/block-std/gfx';
|
||||
import { deserializeXYWH } from '@blocksuite/global/utils';
|
||||
|
||||
import type { GfxBlockModel } from '../block-model.js';
|
||||
|
||||
export function xywhArrayToObject(element: GfxBlockModel) {
|
||||
export function xywhArrayToObject(element: GfxBlockElementModel) {
|
||||
const [x, y, w, h] = deserializeXYWH(element.xywh);
|
||||
return { x, y, w, h };
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ import {
|
||||
TextElementModel,
|
||||
} from '@blocksuite/affine-model';
|
||||
import type {
|
||||
GfxBlockElementModel,
|
||||
GfxModel,
|
||||
GfxPrimitiveElementModel,
|
||||
GfxToolsFullOptionValue,
|
||||
@@ -39,20 +40,19 @@ import {
|
||||
import type { BlockModel } from '@blocksuite/store';
|
||||
|
||||
import type { Connectable } from '../../../_common/utils/index.js';
|
||||
import type { GfxBlockModel } from '../block-model.js';
|
||||
import { getElementsWithoutGroup } from './group.js';
|
||||
|
||||
const { clamp } = CommonUtils;
|
||||
|
||||
export function isMindmapNode(
|
||||
element: GfxBlockModel | BlockSuite.EdgelessModel | null
|
||||
element: GfxBlockElementModel | BlockSuite.EdgelessModel | null
|
||||
) {
|
||||
return element?.group instanceof MindmapElementModel;
|
||||
}
|
||||
|
||||
export function isTopLevelBlock(
|
||||
selectable: BlockModel | BlockSuite.EdgelessModel | null
|
||||
): selectable is GfxBlockModel {
|
||||
): selectable is GfxBlockElementModel {
|
||||
return !!selectable && 'flavour' in selectable;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { RootBlockSchema } from '@blocksuite/affine-model';
|
||||
import type { Viewport } from '@blocksuite/affine-shared/types';
|
||||
import { Slot } from '@blocksuite/store';
|
||||
|
||||
import type { Viewport } from '../../_common/utils/index.js';
|
||||
import { RootService } from '../root-service.js';
|
||||
|
||||
export class PageRootService extends RootService {
|
||||
|
||||
@@ -9,7 +9,10 @@ import {
|
||||
PaletteIcon,
|
||||
} from '@blocksuite/affine-components/icons';
|
||||
import { renderToolbarSeparator } from '@blocksuite/affine-components/toolbar';
|
||||
import type { AttachmentBlockModel } from '@blocksuite/affine-model';
|
||||
import type {
|
||||
AttachmentBlockModel,
|
||||
EmbedCardStyle,
|
||||
} from '@blocksuite/affine-model';
|
||||
import {
|
||||
EMBED_CARD_HEIGHT,
|
||||
EMBED_CARD_WIDTH,
|
||||
@@ -21,7 +24,6 @@ import { html, LitElement, nothing } from 'lit';
|
||||
import { property } from 'lit/decorators.js';
|
||||
import { join } from 'lit/directives/join.js';
|
||||
|
||||
import type { EmbedCardStyle } from '../../../_common/types.js';
|
||||
import type { EdgelessRootBlockComponent } from '../../edgeless/edgeless-root-block.js';
|
||||
|
||||
export class EdgelessChangeAttachmentButton extends WithDisposable(LitElement) {
|
||||
|
||||
@@ -28,7 +28,11 @@ import {
|
||||
type MenuItem,
|
||||
renderToolbarSeparator,
|
||||
} from '@blocksuite/affine-components/toolbar';
|
||||
import { type AliasInfo, BookmarkStyles } from '@blocksuite/affine-model';
|
||||
import {
|
||||
type AliasInfo,
|
||||
BookmarkStyles,
|
||||
type EmbedCardStyle,
|
||||
} from '@blocksuite/affine-model';
|
||||
import {
|
||||
EMBED_CARD_HEIGHT,
|
||||
EMBED_CARD_WIDTH,
|
||||
@@ -52,7 +56,6 @@ import { ifDefined } from 'lit/directives/if-defined.js';
|
||||
import { join } from 'lit/directives/join.js';
|
||||
import { repeat } from 'lit/directives/repeat.js';
|
||||
|
||||
import type { EmbedCardStyle } from '../../../_common/types.js';
|
||||
import type { EdgelessRootBlockComponent } from '../../edgeless/edgeless-root-block.js';
|
||||
import {
|
||||
isBookmarkBlock,
|
||||
|
||||
@@ -30,15 +30,15 @@ import {
|
||||
ResetIcon,
|
||||
} from '@blocksuite/icons/lit';
|
||||
|
||||
import {
|
||||
createLinkedDocFromEdgelessElements,
|
||||
createLinkedDocFromNote,
|
||||
} from '../../../../_common/utils/render-linked-doc.js';
|
||||
import { duplicate } from '../../../edgeless/utils/clipboard-utils.js';
|
||||
import { getSortedCloneElements } from '../../../edgeless/utils/clone-utils.js';
|
||||
import { moveConnectors } from '../../../edgeless/utils/connector.js';
|
||||
import { deleteElements } from '../../../edgeless/utils/crud.js';
|
||||
import type { ElementToolbarMoreMenuContext } from './context.js';
|
||||
import {
|
||||
createLinkedDocFromEdgelessElements,
|
||||
createLinkedDocFromNote,
|
||||
} from './render-linked-doc.js';
|
||||
|
||||
type EmbedLinkBlockComponent =
|
||||
| EmbedGithubBlockComponent
|
||||
|
||||
@@ -0,0 +1,112 @@
|
||||
import { getSurfaceBlock } from '@blocksuite/affine-block-surface';
|
||||
import type { FrameBlockModel, NoteBlockModel } from '@blocksuite/affine-model';
|
||||
import { NoteDisplayMode } from '@blocksuite/affine-model';
|
||||
import { DocModeProvider } from '@blocksuite/affine-shared/services';
|
||||
import { getBlockProps } from '@blocksuite/affine-shared/utils';
|
||||
import type { EditorHost } from '@blocksuite/block-std';
|
||||
import { GfxBlockElementModel } from '@blocksuite/block-std/gfx';
|
||||
import { type BlockModel, type Doc } from '@blocksuite/store';
|
||||
|
||||
import {
|
||||
getElementProps,
|
||||
mapFrameIds,
|
||||
sortEdgelessElements,
|
||||
} from '../../../edgeless/utils/clone-utils.js';
|
||||
import { isFrameBlock, isNoteBlock } from '../../../edgeless/utils/query.js';
|
||||
|
||||
function addBlocksToDoc(targetDoc: Doc, model: BlockModel, parentId: string) {
|
||||
// Add current block to linked doc
|
||||
const blockProps = getBlockProps(model);
|
||||
const newModelId = targetDoc.addBlock(
|
||||
model.flavour as BlockSuite.Flavour,
|
||||
blockProps,
|
||||
parentId
|
||||
);
|
||||
// Add children to linked doc, parent is the new model
|
||||
const children = model.children;
|
||||
if (children.length > 0) {
|
||||
children.forEach(child => {
|
||||
addBlocksToDoc(targetDoc, child, newModelId);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export function createLinkedDocFromNote(
|
||||
doc: Doc,
|
||||
note: NoteBlockModel,
|
||||
docTitle?: string
|
||||
) {
|
||||
const linkedDoc = doc.collection.createDoc({});
|
||||
linkedDoc.load(() => {
|
||||
const rootId = linkedDoc.addBlock('affine:page', {
|
||||
title: new doc.Text(docTitle),
|
||||
});
|
||||
linkedDoc.addBlock('affine:surface', {}, rootId);
|
||||
const blockProps = getBlockProps(note);
|
||||
// keep note props & show in both mode
|
||||
const noteId = linkedDoc.addBlock(
|
||||
'affine:note',
|
||||
{
|
||||
...blockProps,
|
||||
hidden: false,
|
||||
displayMode: NoteDisplayMode.DocAndEdgeless,
|
||||
},
|
||||
rootId
|
||||
);
|
||||
// Add note to linked doc recursively
|
||||
note.children.forEach(model => {
|
||||
addBlocksToDoc(linkedDoc, model, noteId);
|
||||
});
|
||||
});
|
||||
|
||||
return linkedDoc;
|
||||
}
|
||||
|
||||
export function createLinkedDocFromEdgelessElements(
|
||||
host: EditorHost,
|
||||
elements: BlockSuite.EdgelessModel[],
|
||||
docTitle?: string
|
||||
) {
|
||||
const linkedDoc = host.doc.collection.createDoc({});
|
||||
linkedDoc.load(() => {
|
||||
const rootId = linkedDoc.addBlock('affine:page', {
|
||||
title: new host.doc.Text(docTitle),
|
||||
});
|
||||
const surfaceId = linkedDoc.addBlock('affine:surface', {}, rootId);
|
||||
const surface = getSurfaceBlock(linkedDoc);
|
||||
if (!surface) return;
|
||||
|
||||
const sortedElements = sortEdgelessElements(elements);
|
||||
const ids = new Map<string, string>();
|
||||
sortedElements.forEach(model => {
|
||||
let newId = model.id;
|
||||
if (model instanceof GfxBlockElementModel) {
|
||||
const blockProps = getBlockProps(model);
|
||||
if (isNoteBlock(model)) {
|
||||
newId = linkedDoc.addBlock('affine:note', blockProps, rootId);
|
||||
// Add note children to linked doc recursively
|
||||
model.children.forEach(model => {
|
||||
addBlocksToDoc(linkedDoc, model, newId);
|
||||
});
|
||||
} else {
|
||||
if (isFrameBlock(model)) {
|
||||
mapFrameIds(blockProps as unknown as FrameBlockModel, ids);
|
||||
}
|
||||
|
||||
newId = linkedDoc.addBlock(
|
||||
model.flavour as BlockSuite.Flavour,
|
||||
blockProps,
|
||||
surfaceId
|
||||
);
|
||||
}
|
||||
} else {
|
||||
const props = getElementProps(model, ids);
|
||||
newId = surface.addElement(props);
|
||||
}
|
||||
ids.set(model.id, newId);
|
||||
});
|
||||
});
|
||||
|
||||
host.std.get(DocModeProvider).setPrimaryMode('edgeless', linkedDoc.id);
|
||||
return linkedDoc;
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
NewIcon,
|
||||
NotionIcon,
|
||||
} from '@blocksuite/affine-components/icons';
|
||||
import { openFileOrFiles } from '@blocksuite/affine-shared/utils';
|
||||
import { WithDisposable } from '@blocksuite/global/utils';
|
||||
import type { DocCollection } from '@blocksuite/store';
|
||||
import { html, LitElement, type PropertyValues } from 'lit';
|
||||
@@ -14,7 +15,6 @@ import { query, state } from 'lit/decorators.js';
|
||||
import { HtmlTransformer } from '../../../../_common/transformers/html.js';
|
||||
import { MarkdownTransformer } from '../../../../_common/transformers/markdown.js';
|
||||
import { NotionHtmlTransformer } from '../../../../_common/transformers/notion-html.js';
|
||||
import { openFileOrFiles } from '../../../../_common/utils/index.js';
|
||||
import { styles } from './styles.js';
|
||||
|
||||
export type OnSuccessHandler = (
|
||||
|
||||
Reference in New Issue
Block a user