@blocksuite/global
Advanced tools
Comparing version 0.4.1-20230225180029-daf8dec to 0.4.1-20230226175811-d32fc6d
@@ -91,27 +91,2 @@ // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
} | ||
import type { | ||
// Model | ||
CodeBlockModel, | ||
DatabaseBlockModel, | ||
DividerBlockModel, | ||
EmbedBlockModel, | ||
FrameBlockModel, | ||
ListBlockModel, | ||
PageBlockModel, | ||
ParagraphBlockModel, | ||
SurfaceBlockModel, | ||
} from '@blocksuite/blocks/models'; | ||
export type BlockModels = { | ||
'affine:paragraph': ParagraphBlockModel; | ||
'affine:page': PageBlockModel; | ||
'affine:list': ListBlockModel; | ||
'affine:frame': FrameBlockModel; | ||
'affine:code': CodeBlockModel; | ||
'affine:divider': DividerBlockModel; | ||
'affine:embed': EmbedBlockModel; | ||
'affine:surface': SurfaceBlockModel; | ||
'affine:database': DatabaseBlockModel; | ||
}; | ||
} | ||
@@ -118,0 +93,0 @@ |
{ | ||
"name": "@blocksuite/global", | ||
"version": "0.4.1-20230225180029-daf8dec", | ||
"version": "0.4.1-20230226175811-d32fc6d", | ||
"types": "./index.d.ts", | ||
@@ -16,2 +16,3 @@ "type": "module", | ||
"./database": "./src/database.ts", | ||
"./types": "./src/types.ts", | ||
"./utils": "./src/utils.ts", | ||
@@ -18,0 +19,0 @@ "./debug": "./src/debug.ts", |
export * from './consts/affine-style-consts.js'; | ||
export * from './consts/blockhub.js'; | ||
export const BLOCK_ID_ATTR = 'data-block-id' as const; | ||
export const BLOCK_SERVICE_LOADING_ATTR = 'data-service-loading' as const; | ||
export const BLOCK_ID_ATTR = 'data-block-id'; | ||
export const BLOCK_SERVICE_LOADING_ATTR = 'data-service-loading'; | ||
export const PREVENT_DEFAULT = false; | ||
@@ -7,0 +7,0 @@ export const ALLOW_DEFAULT = true; |
@@ -0,1 +1,5 @@ | ||
import type { BaseBlockModel } from '@blocksuite/store'; | ||
import type { BlockModels } from './types.js'; | ||
export type { Disposable } from './utils/disposable.js'; | ||
@@ -26,13 +30,23 @@ export { DisposableGroup, flattenDisposable } from './utils/disposable.js'; | ||
export function matchFlavours< | ||
Key extends keyof BlockSuiteInternal.BlockModels & | ||
string = keyof BlockSuiteInternal.BlockModels & string | ||
>( | ||
model: { flavour: Key }, | ||
expected: readonly Key[] | ||
): boolean /* model is BlockModels[Key] */ { | ||
return expected.includes(model.flavour as Key); | ||
type BlockModelKey = keyof BlockModels; | ||
type Flavours<T> = T extends BlockModelKey[] ? BlockModels[T[number]] : never; | ||
type Writeable<T> = { -readonly [P in keyof T]: T[P] }; | ||
export function matchFlavours<Key extends Readonly<Array<string>>>( | ||
model: BaseBlockModel, | ||
expected: Key | ||
): model is Flavours<Writeable<Key>> { | ||
return expected.includes(model.flavour); | ||
} | ||
// export function matchFlavours< | ||
// Key extends keyof BlockModels & | ||
// string = keyof BlockModels & string | ||
// >( | ||
// model: { flavour: Key }, | ||
// expected: readonly Key[] | ||
// ): model is BlockModels[Key] { | ||
// return expected.includes(model.flavour as Key); | ||
// } | ||
export const nonTextBlock: (keyof BlockSuiteInternal.BlockModels)[] = [ | ||
export const nonTextBlock: (keyof BlockModels)[] = [ | ||
'affine:database', | ||
@@ -45,7 +59,6 @@ 'affine:divider', | ||
export const isNonTextBlock = < | ||
Key extends keyof BlockSuiteInternal.BlockModels & | ||
string = keyof BlockSuiteInternal.BlockModels & string | ||
>(model: { | ||
flavour: Key; | ||
}) => matchFlavours(model, nonTextBlock); | ||
Key extends keyof BlockModels & string = keyof BlockModels & string | ||
>( | ||
model: BaseBlockModel | ||
) => matchFlavours(model, nonTextBlock); | ||
@@ -52,0 +65,0 @@ type Allowed = |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
124716
30
2232