@blocksuite/affine-model
Advanced tools
Comparing version 0.0.0-canary-20240904001311 to 0.0.0-canary-20240904094417
@@ -1,6 +0,7 @@ | ||
import type { GfxElementGeometry, PointTestOptions } from '@blocksuite/block-std/gfx'; | ||
import type { GfxBlockElementModel } from '@blocksuite/block-std/gfx'; | ||
import { type GfxContainerElement, type GfxElementGeometry, type PointTestOptions, gfxContainerSymbol } from '@blocksuite/block-std/gfx'; | ||
import { Bound, type SerializedXYWH } from '@blocksuite/global/utils'; | ||
import { type Text } from '@blocksuite/store'; | ||
import type { Color } from '../../consts/index.js'; | ||
type FrameBlockProps = { | ||
export type FrameBlockProps = { | ||
title: Text; | ||
@@ -10,2 +11,3 @@ background: Color; | ||
index: string; | ||
childElementIds?: Record<string, boolean>; | ||
}; | ||
@@ -27,7 +29,13 @@ export declare const FrameBlockSchema: { | ||
declare const FrameBlockModel_base: { | ||
new (): import("@blocksuite/block-std/gfx").GfxBlockElementModel<FrameBlockProps>; | ||
new (): GfxBlockElementModel<FrameBlockProps>; | ||
}; | ||
export declare class FrameBlockModel extends FrameBlockModel_base implements GfxElementGeometry { | ||
export declare class FrameBlockModel extends FrameBlockModel_base implements GfxElementGeometry, GfxContainerElement { | ||
[gfxContainerSymbol]: true; | ||
addChild(element: BlockSuite.EdgelessModel | string): void; | ||
containsBound(bound: Bound): boolean; | ||
includesPoint(x: number, y: number, _: PointTestOptions): boolean; | ||
intersectsBound(selectedBound: Bound): boolean; | ||
removeChild(element: BlockSuite.EdgelessModel | string): void; | ||
get childElements(): import("@blocksuite/block-std/gfx").GfxModel[]; | ||
get childIds(): string[]; | ||
} | ||
@@ -34,0 +42,0 @@ declare global { |
@@ -0,1 +1,3 @@ | ||
var _a; | ||
import { SurfaceBlockModel, gfxContainerSymbol, } from '@blocksuite/block-std/gfx'; | ||
import { Bound } from '@blocksuite/global/utils'; | ||
@@ -11,2 +13,3 @@ import { BlockModel, defineBlockSchema } from '@blocksuite/store'; | ||
index: 'a0', | ||
childElementIds: Object.create(null), | ||
}), | ||
@@ -24,8 +27,21 @@ metadata: { | ||
export class FrameBlockModel extends GfxCompatible(BlockModel) { | ||
constructor() { | ||
super(...arguments); | ||
this[_a] = true; | ||
} | ||
static { _a = gfxContainerSymbol; } | ||
addChild(element) { | ||
const id = typeof element === 'string' ? element : element.id; | ||
this.doc.transact(() => { | ||
if (!this.childElementIds) | ||
this.childElementIds = {}; | ||
this.childElementIds[id] = true; | ||
}); | ||
} | ||
containsBound(bound) { | ||
return this.elementBound.contains(bound); | ||
} | ||
includesPoint(x, y, _) { | ||
const bound = Bound.deserialize(this.xywh); | ||
const hit = bound.isPointNearBound([x, y], 5); | ||
if (hit) | ||
return true; | ||
return this.externalBound?.isPointInBound([x, y]) ?? false; | ||
return bound.isPointInBound([x, y]); | ||
} | ||
@@ -36,3 +52,26 @@ intersectsBound(selectedBound) { | ||
} | ||
removeChild(element) { | ||
const id = typeof element === 'string' ? element : element.id; | ||
this.doc.transact(() => { | ||
this.childElementIds && delete this.childElementIds[id]; | ||
}); | ||
} | ||
get childElements() { | ||
const surface = this.doc | ||
.getBlocks() | ||
.find(model => model instanceof SurfaceBlockModel); | ||
if (!surface) | ||
return []; | ||
const elements = []; | ||
for (const key of this.childIds) { | ||
const element = surface.getElementById(key) || | ||
surface.doc.getBlockById(key); | ||
element && elements.push(element); | ||
} | ||
return elements; | ||
} | ||
get childIds() { | ||
return [...(this.childElementIds ? Object.keys(this.childElementIds) : [])]; | ||
} | ||
} | ||
//# sourceMappingURL=frame-model.js.map |
@@ -104,2 +104,3 @@ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) { | ||
const result = super.serialize(); | ||
result.xywh = this.xywh; | ||
return result; | ||
@@ -106,0 +107,0 @@ } |
{ | ||
"name": "@blocksuite/affine-model", | ||
"version": "0.0.0-canary-20240904001311", | ||
"version": "0.0.0-canary-20240904094417", | ||
"description": "Default BlockSuite editable blocks.", | ||
@@ -12,6 +12,6 @@ "type": "module", | ||
"zod": "^3.23.8", | ||
"@blocksuite/global": "0.0.0-canary-20240904001311", | ||
"@blocksuite/block-std": "0.0.0-canary-20240904001311", | ||
"@blocksuite/inline": "0.0.0-canary-20240904001311", | ||
"@blocksuite/store": "0.0.0-canary-20240904001311" | ||
"@blocksuite/block-std": "0.0.0-canary-20240904094417", | ||
"@blocksuite/global": "0.0.0-canary-20240904094417", | ||
"@blocksuite/store": "0.0.0-canary-20240904094417", | ||
"@blocksuite/inline": "0.0.0-canary-20240904094417" | ||
}, | ||
@@ -18,0 +18,0 @@ "exports": { |
@@ -1,6 +0,10 @@ | ||
import type { | ||
GfxElementGeometry, | ||
PointTestOptions, | ||
import type { GfxBlockElementModel } from '@blocksuite/block-std/gfx'; | ||
import { | ||
type GfxContainerElement, | ||
type GfxElementGeometry, | ||
type PointTestOptions, | ||
SurfaceBlockModel, | ||
gfxContainerSymbol, | ||
} from '@blocksuite/block-std/gfx'; | ||
import { Bound, type SerializedXYWH } from '@blocksuite/global/utils'; | ||
@@ -13,3 +17,3 @@ import { BlockModel, type Text, defineBlockSchema } from '@blocksuite/store'; | ||
type FrameBlockProps = { | ||
export type FrameBlockProps = { | ||
title: Text; | ||
@@ -19,2 +23,3 @@ background: Color; | ||
index: string; | ||
childElementIds?: Record<string, boolean>; | ||
}; | ||
@@ -29,2 +34,3 @@ | ||
index: 'a0', | ||
childElementIds: Object.create(null), | ||
}), | ||
@@ -44,13 +50,23 @@ metadata: { | ||
extends GfxCompatible<FrameBlockProps>(BlockModel) | ||
implements GfxElementGeometry | ||
implements GfxElementGeometry, GfxContainerElement | ||
{ | ||
override includesPoint(x: number, y: number, _: PointTestOptions): boolean { | ||
const bound = Bound.deserialize(this.xywh); | ||
const hit = bound.isPointNearBound([x, y], 5); | ||
[gfxContainerSymbol] = true as const; | ||
if (hit) return true; | ||
addChild(element: BlockSuite.EdgelessModel | string): void { | ||
const id = typeof element === 'string' ? element : element.id; | ||
this.doc.transact(() => { | ||
if (!this.childElementIds) this.childElementIds = {}; | ||
this.childElementIds[id] = true; | ||
}); | ||
} | ||
return this.externalBound?.isPointInBound([x, y]) ?? false; | ||
override containsBound(bound: Bound): boolean { | ||
return this.elementBound.contains(bound); | ||
} | ||
override includesPoint(x: number, y: number, _: PointTestOptions): boolean { | ||
const bound = Bound.deserialize(this.xywh); | ||
return bound.isPointInBound([x, y]); | ||
} | ||
override intersectsBound(selectedBound: Bound): boolean { | ||
@@ -62,2 +78,32 @@ const bound = Bound.deserialize(this.xywh); | ||
} | ||
removeChild(element: BlockSuite.EdgelessModel | string): void { | ||
const id = typeof element === 'string' ? element : element.id; | ||
this.doc.transact(() => { | ||
this.childElementIds && delete this.childElementIds[id]; | ||
}); | ||
} | ||
get childElements() { | ||
const surface = this.doc | ||
.getBlocks() | ||
.find(model => model instanceof SurfaceBlockModel); | ||
if (!surface) return []; | ||
const elements: BlockSuite.EdgelessModel[] = []; | ||
for (const key of this.childIds) { | ||
const element = | ||
surface.getElementById(key) || | ||
(surface.doc.getBlockById(key) as GfxBlockElementModel); | ||
element && elements.push(element); | ||
} | ||
return elements; | ||
} | ||
get childIds() { | ||
return [...(this.childElementIds ? Object.keys(this.childElementIds) : [])]; | ||
} | ||
} | ||
@@ -64,0 +110,0 @@ |
@@ -85,2 +85,3 @@ import type { | ||
const result = super.serialize(); | ||
result.xywh = this.xywh; | ||
return result as SerializedGroupElement; | ||
@@ -87,0 +88,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
555095
7659
+ Added@blocksuite/block-std@0.0.0-canary-20240904094417(transitive)
+ Added@blocksuite/global@0.0.0-canary-20240904094417(transitive)
+ Added@blocksuite/inline@0.0.0-canary-20240904094417(transitive)
+ Added@blocksuite/store@0.0.0-canary-20240904094417(transitive)
+ Added@blocksuite/sync@0.0.0-canary-20240904094417(transitive)
+ Addedlodash.clonedeep@4.5.0(transitive)
- Removed@blocksuite/block-std@0.0.0-canary-20240904001311(transitive)
- Removed@blocksuite/global@0.0.0-canary-20240904001311(transitive)
- Removed@blocksuite/inline@0.0.0-canary-20240904001311(transitive)
- Removed@blocksuite/store@0.0.0-canary-20240904001311(transitive)
- Removed@blocksuite/sync@0.0.0-canary-20240904001311(transitive)