Skip to content

Commit

Permalink
refactor: models -> schemas (toeverything#6312)
Browse files Browse the repository at this point in the history
  • Loading branch information
Saul-Mirone authored Feb 28, 2024
1 parent 6d3a709 commit 8ebbb44
Show file tree
Hide file tree
Showing 51 changed files with 101 additions and 153 deletions.
3 changes: 0 additions & 3 deletions packages/blocks/models.js

This file was deleted.

12 changes: 6 additions & 6 deletions packages/blocks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"exports": {
"./dist/*": "./dist/*",
".": "./src/index.ts",
"./models": "./src/models.ts"
"./schemas": "./src/schemas.ts"
},
"publishConfig": {
"access": "public",
Expand All @@ -71,9 +71,9 @@
"module": "./dist/index.js",
"import": "./dist/index.js"
},
"./models": {
"types": "./dist/models.d.ts",
"default": "./dist/models.js"
"./schemas": {
"types": "./dist/schemas.d.ts",
"default": "./dist/schemas.js"
}
}
},
Expand All @@ -82,7 +82,7 @@
"dist",
"!src/__tests__",
"!dist/__tests__",
"models.d.ts",
"models.js"
"schemas.d.ts",
"schemas.js"
]
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/* eslint-disable */
// @ts-ignore
export * from './dist/models';
export * from './dist/schemas';
3 changes: 3 additions & 0 deletions packages/blocks/schemas.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/* eslint-disable */
/// <reference types="./dist/schemas.d.ts" />
export * from './dist/schemas.js';
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ describe('DatabaseManager', () => {
noteBlockId = doc.addBlock('affine:note', {}, rootId);

databaseBlockId = doc.addBlock(
'affine:database' as BlockSuite.ModelKeys,
'affine:database' as BlockSuite.Flavour,
{
columns: [],
titleColumn: 'Title',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export class EmbedCardMoreMenu extends WithDisposable(LitElement) {
const parent = doc.getParent(model);
const index = parent?.children.indexOf(model);
doc.addBlock(
model.flavour as BlockSuite.ModelKeys,
model.flavour as BlockSuite.Flavour,
duplicateProps,
parent,
index
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import {
focusTitle,
} from '../../../_common/utils/selection.js';
import type { ListBlockModel } from '../../../list-block/index.js';
import type { Flavour } from '../../../models.js';
import type { RootBlockModel } from '../../../root-block/index.js';
import type { ExtendedModel } from '../../types.js';

Expand Down Expand Up @@ -862,7 +861,7 @@ function handleParagraphBlockForwardDelete(
// TODO
return false;
} else {
const ignoreForwardDeleteFlavourList: Flavour[] = [
const ignoreForwardDeleteFlavourList: BlockSuite.Flavour[] = [
'affine:database',
'affine:image',
'affine:code',
Expand Down
3 changes: 1 addition & 2 deletions packages/blocks/src/_common/configs/text-conversion.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { TemplateResult } from 'lit';

import type { BlockSchemas } from '../../models.js';
import {
BulletedListIcon,
CheckBoxIcon,
Expand All @@ -22,7 +21,7 @@ import {
* which are also used for registering hotkeys for converting block flavours.
*/
interface TextConversionConfig {
flavour: keyof BlockSchemas;
flavour: BlockSuite.Flavour;
type?: string;
name: string;
hotkey: string[] | null;
Expand Down
10 changes: 5 additions & 5 deletions packages/blocks/src/_common/configs/text-format/consts.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import type { Flavour } from '../../../models.js';

// corresponding to `formatText` command
export const FORMAT_TEXT_SUPPORT_FLAVOURS: Flavour[] = [
export const FORMAT_TEXT_SUPPORT_FLAVOURS: BlockSuite.Flavour[] = [
'affine:paragraph',
'affine:list',
];
// corresponding to `formatBlock` command
export const FORMAT_BLOCK_SUPPORT_FLAVOURS: Flavour[] = [
export const FORMAT_BLOCK_SUPPORT_FLAVOURS: BlockSuite.Flavour[] = [
'affine:paragraph',
'affine:list',
];
// corresponding to `formatNative` command
export const FORMAT_NATIVE_SUPPORT_FLAVOURS: Flavour[] = ['affine:database'];
export const FORMAT_NATIVE_SUPPORT_FLAVOURS: BlockSuite.Flavour[] = [
'affine:database',
];
21 changes: 14 additions & 7 deletions packages/blocks/src/_common/configs/text-format/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
} from '@blocksuite/inline';
import type { BlockElement, EditorHost } from '@blocksuite/lit';

import type { Flavour } from '../../../models.js';
import { BLOCK_ID_ATTR } from '../../consts.js';
import type {
AffineInlineEditor,
Expand Down Expand Up @@ -59,7 +58,9 @@ function getCombinedFormat(host: EditorHost): AffineTextAttributes {
.getSelectedBlocks({
types: ['text'],
filter: el =>
FORMAT_TEXT_SUPPORT_FLAVOURS.includes(el.model.flavour as Flavour),
FORMAT_TEXT_SUPPORT_FLAVOURS.includes(
el.model.flavour as BlockSuite.Flavour
),
})
.inline((ctx, next) => {
const { selectedBlocks } = ctx;
Expand Down Expand Up @@ -89,7 +90,9 @@ function getCombinedFormat(host: EditorHost): AffineTextAttributes {
.getSelectedBlocks({
types: ['block'],
filter: el =>
FORMAT_BLOCK_SUPPORT_FLAVOURS.includes(el.model.flavour as Flavour),
FORMAT_BLOCK_SUPPORT_FLAVOURS.includes(
el.model.flavour as BlockSuite.Flavour
),
})
.inline((ctx, next) => {
const { selectedBlocks } = ctx;
Expand Down Expand Up @@ -133,7 +136,7 @@ function getCombinedFormat(host: EditorHost): AffineTextAttributes {
const blockElement = el.closest<BlockElement>(`[${BLOCK_ID_ATTR}]`);
if (blockElement) {
return FORMAT_NATIVE_SUPPORT_FLAVOURS.includes(
blockElement.model.flavour as Flavour
blockElement.model.flavour as BlockSuite.Flavour
);
}
return false;
Expand Down Expand Up @@ -195,7 +198,9 @@ export function isFormatSupported(host: EditorHost) {
.getSelectedBlocks({
types: ['text'],
filter: el =>
FORMAT_TEXT_SUPPORT_FLAVOURS.includes(el.model.flavour as Flavour),
FORMAT_TEXT_SUPPORT_FLAVOURS.includes(
el.model.flavour as BlockSuite.Flavour
),
})
.inline((ctx, next) => {
const { currentTextSelection, selectedBlocks } = ctx;
Expand Down Expand Up @@ -223,7 +228,9 @@ export function isFormatSupported(host: EditorHost) {
.getSelectedBlocks({
types: ['block'],
filter: el =>
FORMAT_BLOCK_SUPPORT_FLAVOURS.includes(el.model.flavour as Flavour),
FORMAT_BLOCK_SUPPORT_FLAVOURS.includes(
el.model.flavour as BlockSuite.Flavour
),
})
.inline((ctx, next) => {
const { selectedBlocks } = ctx;
Expand Down Expand Up @@ -258,7 +265,7 @@ export function isFormatSupported(host: EditorHost) {
const blockElement = el.closest<BlockElement>(`[${BLOCK_ID_ATTR}]`);
if (blockElement) {
return FORMAT_NATIVE_SUPPORT_FLAVOURS.includes(
blockElement.model.flavour as Flavour
blockElement.model.flavour as BlockSuite.Flavour
);
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import {
isInsidePageEditor,
matchFlavours,
} from '../../_common/utils/index.js';
import type { RootBlockModel } from '../../models.js';
import type { EdgelessRootBlockComponent } from '../../root-block/edgeless/edgeless-root-block.js';
import { getBlocksInFrame } from '../../root-block/edgeless/frame-manager.js';
import type { EdgelessBlockModel } from '../../root-block/edgeless/type.js';
import { xywhArrayToObject } from '../../root-block/edgeless/utils/convert.js';
import { getBackgroundGrid } from '../../root-block/edgeless/utils/query.js';
import type { RootBlockModel } from '../../root-block/index.js';
import type { IBound } from '../../surface-block/consts.js';
import type { ElementModel } from '../../surface-block/element-model/index.js';
import type { Renderer } from '../../surface-block/index.js';
Expand Down
3 changes: 2 additions & 1 deletion packages/blocks/src/_common/transformers/middlewares.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { assertExists } from '@blocksuite/global/utils';
import type { DeltaOperation, JobMiddleware } from '@blocksuite/store';

import type { DatabaseBlockModel } from '../../database-block/index.js';
import type { ListBlockModel, ParagraphBlockModel } from '../../models.js';
import type { ListBlockModel } from '../../list-block/index.js';
import type { ParagraphBlockModel } from '../../paragraph-block/index.js';
import { DEFAULT_IMAGE_PROXY_ENDPOINT } from '../consts.js';

export const replaceIdMiddleware: JobMiddleware = ({ slots, workspace }) => {
Expand Down
3 changes: 2 additions & 1 deletion packages/blocks/src/_common/utils/render-linked-doc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import { render, type TemplateResult } from 'lit';

import type { EmbedLinkedDocBlockComponent } from '../../embed-linked-doc-block/embed-linked-doc-block.js';
import type { EmbedSyncedDocCard } from '../../embed-synced-doc-block/components/embed-synced-doc-card.js';
import type { ImageBlockModel, NoteBlockModel } from '../../models.js';
import type { ImageBlockModel } from '../../image-block/index.js';
import type { NoteBlockModel } from '../../note-block/index.js';
import { Bound, getCommonBound } from '../../surface-block/utils/bound.js';
import { deserializeXYWH } from '../../surface-block/utils/xywh.js';
import type { SurfaceRefBlockModel } from '../../surface-ref-block/surface-ref-model.js';
Expand Down
3 changes: 2 additions & 1 deletion packages/blocks/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ export * from './embed-youtube-block/index.js';
export * from './frame-block/index.js';
export * from './image-block/index.js';
export * from './list-block/index.js';
export * from './models.js';
export * from './note-block/index.js';
export * from './paragraph-block/index.js';
export { EdgelessComponentToolbar } from './root-block/edgeless/components/component-toolbar/component-toolbar.js';
Expand All @@ -92,6 +91,7 @@ export type {
TemplateManager,
} from './root-block/edgeless/components/toolbar/template/template-type.js';
export * from './root-block/index.js';
export * from './schemas.js';
export {
Bound,
BrushElementModel,
Expand All @@ -107,6 +107,7 @@ export {
ShapeElementModel,
ShapeStyle,
StrokeStyle,
SurfaceBlockModel,
TextElementModel,
} from './surface-block/index.js';
export { SurfaceBlockComponent } from './surface-block/surface-block.js';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
} from '@blocksuite/store';

import { matchFlavours } from '../../../_common/utils/index.js';
import type { CodeBlockModel } from '../../../models.js';
import type { CodeBlockModel } from '../../../code-block/index.js';
import type { ParagraphBlockModel } from '../../../paragraph-block/index.js';

const findLast = (snapshot: BlockSnapshot): BlockSnapshot => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { INLINE_ROOT_ATTR, type InlineRootElement } from '@blocksuite/inline';

import { FORMAT_BLOCK_SUPPORT_FLAVOURS } from '../../../_common/configs/text-format/consts.js';
import type { AffineTextAttributes } from '../../../_common/inline/presets/affine-inline-specs.js';
import type { Flavour } from '../../../models.js';

// for block selection
export const formatBlockCommand: Command<
Expand Down Expand Up @@ -39,7 +38,9 @@ export const formatBlockCommand: Command<
.getSelectedBlocks({
blockSelections,
filter: el =>
FORMAT_BLOCK_SUPPORT_FLAVOURS.includes(el.model.flavour as Flavour),
FORMAT_BLOCK_SUPPORT_FLAVOURS.includes(
el.model.flavour as BlockSuite.Flavour
),
types: ['block'],
})
.inline((ctx, next) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import type { BlockElement } from '@blocksuite/lit';
import { FORMAT_NATIVE_SUPPORT_FLAVOURS } from '../../../_common/configs/text-format/consts.js';
import { BLOCK_ID_ATTR } from '../../../_common/consts.js';
import type { AffineTextAttributes } from '../../../_common/inline/presets/affine-inline-specs.js';
import type { Flavour } from '../../../models.js';

// for native range
export const formatNativeCommand: Command<
Expand Down Expand Up @@ -40,7 +39,7 @@ export const formatNativeCommand: Command<
const blockElement = el.closest<BlockElement>(`[${BLOCK_ID_ATTR}]`);
if (blockElement) {
return FORMAT_NATIVE_SUPPORT_FLAVOURS.includes(
blockElement.model.flavour as Flavour
blockElement.model.flavour as BlockSuite.Flavour
);
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { INLINE_ROOT_ATTR, type InlineRootElement } from '@blocksuite/inline';
import { FORMAT_TEXT_SUPPORT_FLAVOURS } from '../../../_common/configs/text-format/consts.js';
import type { AffineTextAttributes } from '../../../_common/inline/presets/affine-inline-specs.js';
import { clearMarksOnDiscontinuousInput } from '../../../_common/utils/inline-editor.js';
import type { Flavour } from '../../../models.js';

// for text selection
export const formatTextCommand: Command<
Expand Down Expand Up @@ -35,7 +34,9 @@ export const formatTextCommand: Command<
.getSelectedBlocks({
textSelection,
filter: el =>
FORMAT_TEXT_SUPPORT_FLAVOURS.includes(el.model.flavour as Flavour),
FORMAT_TEXT_SUPPORT_FLAVOURS.includes(
el.model.flavour as BlockSuite.Flavour
),
types: ['text'],
})
.inline((ctx, next) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { assertExists } from '@blocksuite/global/utils';
import { Workspace } from '@blocksuite/store';

import type { NoteBlockModel } from '../../../../models.js';
import type { NoteBlockModel } from '../../../../note-block/index.js';
import {
CanvasTextFontFamily,
CanvasTextFontStyle,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
} from '../../../../_common/icons/edgeless.js';
import { SmallDocIcon } from '../../../../_common/icons/text.js';
import { requestConnectedFrame } from '../../../../_common/utils/event.js';
import type { NoteBlockModel } from '../../../../models.js';
import type { NoteBlockModel } from '../../../../note-block/index.js';
import { Bound } from '../../../../surface-block/index.js';
import type { SurfaceBlockComponent } from '../../../../surface-block/surface-block.js';
import type { EdgelessRootBlockComponent } from '../../edgeless-root-block.js';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { customElement } from 'lit/decorators.js';
import { styleMap } from 'lit/directives/style-map.js';
import { html } from 'lit/static-html.js';

import type { BookmarkBlockModel } from '../../../../../models.js';
import type { BookmarkBlockModel } from '../../../../../bookmark-block/index.js';
import { Bound } from '../../../../../surface-block/index.js';
import { EdgelessPortalBase } from '../edgeless-portal-base.js';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ import {
NoteDisplayMode,
type TopLevelBlockModel,
} from '../../../../_common/utils/index.js';
import type { SurfaceBlockComponent } from '../../../../index.js';
import type { FrameBlockModel } from '../../../../models.js';
import type {
FrameBlockModel,
SurfaceBlockComponent,
} from '../../../../index.js';
import type { NoteBlockModel } from '../../../../note-block/index.js';
import type { GroupElementModel } from '../../../../surface-block/index.js';
import { type EdgelessBlockType } from '../../../../surface-block/index.js';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@ import {
SYNCED_MIN_HEIGHT,
SYNCED_MIN_WIDTH,
} from '../../../../embed-synced-doc-block/styles.js';
import type { EmbedHtmlModel, EmbedSyncedDocModel } from '../../../../index.js';
import type { BookmarkBlockModel } from '../../../../models.js';
import type {
BookmarkBlockModel,
EmbedHtmlModel,
EmbedSyncedDocModel,
} from '../../../../index.js';
import { NoteBlockModel } from '../../../../note-block/note-model.js';
import { normalizeTextBound } from '../../../../surface-block/canvas-renderer/element-renderer/text/utils.js';
import { TextElementModel } from '../../../../surface-block/element-model/text.js';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
isInsidePageEditor,
} from '../../../_common/utils/query.js';
import { isUrlInClipboard } from '../../../_common/utils/url.js';
import type { AttachmentBlockModel } from '../../../attachment-block/index.js';
import {
type BookmarkBlockModel,
BookmarkStyles,
Expand All @@ -43,7 +44,6 @@ import type { EmbedSyncedDocModel } from '../../../embed-synced-doc-block/embed-
import type { EmbedYoutubeModel } from '../../../embed-youtube-block/embed-youtube-model.js';
import type { FrameBlockModel } from '../../../frame-block/frame-model.js';
import type { ImageBlockModel } from '../../../image-block/image-model.js';
import type { AttachmentBlockModel } from '../../../models.js';
import type { NoteBlockModel } from '../../../note-block/note-model.js';
import type { IBound } from '../../../surface-block/consts.js';
import type { EdgelessElementType } from '../../../surface-block/edgeless-types.js';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@ import {
SURFACE_IMAGE_CARD_HEIGHT,
SURFACE_IMAGE_CARD_WIDTH,
} from '../../image-block/components/image-card.js';
import type { ImageBlockProps } from '../../image-block/image-model.js';
import type {
ImageBlockModel,
ImageBlockProps,
} from '../../image-block/image-model.js';
import type { AttachmentBlockProps } from '../../index.js';
import type { ImageBlockModel } from '../../models.js';
import {
Bound,
type IBound,
Expand Down
Loading

0 comments on commit 8ebbb44

Please sign in to comment.