@blocksuite/store
Advanced tools
Comparing version 0.3.1-20230103122030-41785b2 to 0.3.1-20230104134918-4a6cec7
@@ -67,3 +67,3 @@ import * as Y from 'yjs'; | ||
} | ||
if (props.flavour === 'affine:group' && !yBlock.has('prop:xywh')) { | ||
if (props.flavour === 'affine:frame' && !yBlock.has('prop:xywh')) { | ||
yBlock.set('prop:xywh', props.xywh ?? '[0,0,720,480]'); | ||
@@ -70,0 +70,0 @@ } |
@@ -38,4 +38,4 @@ import * as Y from 'yjs'; | ||
historyUpdated: Signal<void>; | ||
rootAdded: Signal<BaseBlockModel>; | ||
rootDeleted: Signal<string>; | ||
rootAdded: Signal<BaseBlockModel | BaseBlockModel[]>; | ||
rootDeleted: Signal<string | string[]>; | ||
textUpdated: Signal<Y.YTextEvent>; | ||
@@ -50,2 +50,3 @@ updated: Signal<void>; | ||
get root(): BaseBlockModel | null; | ||
get rootLayer(): BaseBlockModel | null; | ||
get isEmpty(): boolean; | ||
@@ -68,3 +69,3 @@ get canUndo(): boolean; | ||
getNextSiblings(block: BaseBlockModel): BaseBlockModel[]; | ||
addBlock<T extends BlockProps>(blockProps: Partial<T>, parent?: BaseBlockModel | string, parentIndex?: number): string; | ||
addBlock<T extends BlockProps>(blockProps: Partial<T>, parent?: BaseBlockModel | string | null, parentIndex?: number): string; | ||
updateBlockById(id: string, props: Partial<BlockProps>): void; | ||
@@ -71,0 +72,0 @@ updateBlock<T extends Partial<BlockProps>>(model: BaseBlockModel, props: T): void; |
@@ -8,2 +8,3 @@ import * as Y from 'yjs'; | ||
import { assertValidChildren, initSysProps, syncBlockProps, trySyncTextProp, toBlockProps, matchFlavours, } from '../utils/utils.js'; | ||
import { tryMigrate } from './migrations.js'; | ||
const isWeb = typeof window !== 'undefined'; | ||
@@ -69,4 +70,7 @@ function createChildMap(yChildIds) { | ||
get root() { | ||
return this._root; | ||
return Array.isArray(this._root) ? this._root[0] : this._root; | ||
} | ||
get rootLayer() { | ||
return Array.isArray(this._root) ? this._root[1] : null; | ||
} | ||
get isEmpty() { | ||
@@ -119,5 +123,5 @@ return this._yBlocks.size === 0; | ||
getParent(block) { | ||
if (!this._root) | ||
if (!this.root) | ||
return null; | ||
return this.getParentById(this._root.id, block); | ||
return this.getParentById(this.root.id, block); | ||
} | ||
@@ -189,3 +193,3 @@ getPreviousSibling(block) { | ||
} | ||
const parentId = parent?.id ?? this._root?.id; | ||
const parentId = parent === null ? null : parent?.id ?? this.root?.id; | ||
if (parentId) { | ||
@@ -279,2 +283,3 @@ const yParent = this._yBlocks.get(parentId); | ||
} | ||
tryMigrate(this.doc); | ||
this._handleVersion(); | ||
@@ -337,5 +342,9 @@ this._initYBlocks(); | ||
const isRoot = this._blockMap.size === 0; | ||
let isSurface = false; | ||
const prefixedProps = yBlock.toJSON(); | ||
const props = toBlockProps(prefixedProps); | ||
const model = this._createBlockModel({ ...props, id }); | ||
if (model.flavour === 'affine:surface') { | ||
isSurface = true; | ||
} | ||
this._blockMap.set(props.id, model); | ||
@@ -375,2 +384,6 @@ if ( | ||
} | ||
else if (isSurface) { | ||
this._root = [this.root, model]; | ||
this.signals.rootAdded.emit(this._root); | ||
} | ||
else { | ||
@@ -377,0 +390,0 @@ const parent = this.getParent(model); |
{ | ||
"name": "@blocksuite/store", | ||
"version": "0.3.1-20230103122030-41785b2", | ||
"version": "0.3.1-20230104134918-4a6cec7", | ||
"description": "BlockSuite data store built for general purpose state management.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -17,3 +17,3 @@ /* eslint-disable @typescript-eslint/no-restricted-imports */ | ||
import { ListBlockModel } from '../../../blocks/src/list-block/list-model.js'; | ||
import { GroupBlockModel } from '../../../blocks/src/group-block/group-model.js'; | ||
import { FrameBlockModel } from '../../../blocks/src/frame-block/frame-model.js'; | ||
import { DividerBlockModel } from '../../../blocks/src/divider-block/divider-model.js'; | ||
@@ -33,3 +33,3 @@ import type { PageMeta } from '../workspace/index.js'; | ||
'affine:list': ListBlockModel, | ||
'affine:group': GroupBlockModel, | ||
'affine:frame': FrameBlockModel, | ||
'affine:divider': DividerBlockModel, | ||
@@ -36,0 +36,0 @@ } as const; |
@@ -98,3 +98,3 @@ import * as Y from 'yjs'; | ||
} | ||
if (props.flavour === 'affine:group' && !yBlock.has('prop:xywh')) { | ||
if (props.flavour === 'affine:frame' && !yBlock.has('prop:xywh')) { | ||
yBlock.set('prop:xywh', props.xywh ?? '[0,0,720,480]'); | ||
@@ -101,0 +101,0 @@ } |
@@ -25,2 +25,3 @@ import * as Y from 'yjs'; | ||
import type { BlockSuiteDoc } from '../yjs/index.js'; | ||
import { tryMigrate } from './migrations.js'; | ||
@@ -58,3 +59,3 @@ export type YBlock = Y.Map<unknown>; | ||
private _history!: Y.UndoManager; | ||
private _root: BaseBlockModel | null = null; | ||
private _root: BaseBlockModel | BaseBlockModel[] | null = null; | ||
private _blockMap = new Map<string, BaseBlockModel>(); | ||
@@ -71,4 +72,4 @@ private _splitSet = new Set<Text | PrelimText>(); | ||
historyUpdated: new Signal(), | ||
rootAdded: new Signal<BaseBlockModel>(), | ||
rootDeleted: new Signal<string>(), | ||
rootAdded: new Signal<BaseBlockModel | BaseBlockModel[]>(), | ||
rootDeleted: new Signal<string | string[]>(), | ||
textUpdated: new Signal<Y.YTextEvent>(), | ||
@@ -104,5 +105,9 @@ updated: new Signal(), | ||
get root() { | ||
return this._root; | ||
return Array.isArray(this._root) ? this._root[0] : this._root; | ||
} | ||
get rootLayer() { | ||
return Array.isArray(this._root) ? this._root[1] : null; | ||
} | ||
get isEmpty() { | ||
@@ -167,5 +172,5 @@ return this._yBlocks.size === 0; | ||
getParent(block: BaseBlockModel) { | ||
if (!this._root) return null; | ||
if (!this.root) return null; | ||
return this.getParentById(this._root.id, block); | ||
return this.getParentById(this.root.id, block); | ||
} | ||
@@ -231,3 +236,3 @@ | ||
blockProps: Partial<T>, | ||
parent?: BaseBlockModel | string, | ||
parent?: BaseBlockModel | string | null, | ||
parentIndex?: number | ||
@@ -261,3 +266,3 @@ ): string { | ||
const parentId = parent?.id ?? this._root?.id; | ||
const parentId = parent === null ? null : parent?.id ?? this.root?.id; | ||
@@ -373,2 +378,4 @@ if (parentId) { | ||
tryMigrate(this.doc); | ||
this._handleVersion(); | ||
@@ -467,2 +474,3 @@ this._initYBlocks(); | ||
const isRoot = this._blockMap.size === 0; | ||
let isSurface = false; | ||
@@ -472,2 +480,5 @@ const prefixedProps = yBlock.toJSON() as PrefixedBlockProps; | ||
const model = this._createBlockModel({ ...props, id }); | ||
if (model.flavour === 'affine:surface') { | ||
isSurface = true; | ||
} | ||
this._blockMap.set(props.id, model); | ||
@@ -514,2 +525,5 @@ | ||
this.signals.rootAdded.emit(model); | ||
} else if (isSurface) { | ||
this._root = [this.root as BaseBlockModel, model]; | ||
this.signals.rootAdded.emit(this._root); | ||
} else { | ||
@@ -516,0 +530,0 @@ const parent = this.getParent(model); |
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
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
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
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
456437
166
7491
3