@blocksuite/store
Advanced tools
Comparing version 0.4.0-20230114095726-16babb2 to 0.4.0-20230114163139-bef702b
@@ -77,3 +77,5 @@ /// <reference types="@blocksuite/global" /> | ||
deleteBlockById(id: string): void; | ||
deleteBlock(model: BaseBlockModel): void; | ||
deleteBlock(model: BaseBlockModel, options?: { | ||
bringChildrenTo: 'parent' | BaseBlockModel; | ||
}): void; | ||
/** Connect a rich text editor instance with a YText instance. */ | ||
@@ -80,0 +82,0 @@ attachRichText(id: string, quill: Quill): void; |
@@ -302,3 +302,5 @@ import * as Y from 'yjs'; | ||
} | ||
deleteBlock(model) { | ||
deleteBlock(model, options = { | ||
bringChildrenTo: 'parent', | ||
}) { | ||
if (this.awareness.isReadonly()) { | ||
@@ -313,5 +315,12 @@ console.error('cannot modify data in readonly mode'); | ||
} | ||
if (options.bringChildrenTo === 'parent' && parent) { | ||
parent.children.unshift(...model.children); | ||
} | ||
else if (options.bringChildrenTo instanceof BaseBlockModel) { | ||
options.bringChildrenTo.children.unshift(...model.children); | ||
} | ||
this._blockMap.delete(model.id); | ||
this.transact(() => { | ||
this._yBlocks.delete(model.id); | ||
const children = model.children.map(model => model.id); | ||
model.dispose(); | ||
@@ -324,2 +333,10 @@ if (parent) { | ||
} | ||
if (options.bringChildrenTo === 'parent' && parent) { | ||
yChildren.unshift(children); | ||
} | ||
else if (options.bringChildrenTo instanceof BaseBlockModel) { | ||
this.updateBlockById(options.bringChildrenTo.id, { | ||
children: options.bringChildrenTo.children, | ||
}); | ||
} | ||
} | ||
@@ -326,0 +343,0 @@ }); |
{ | ||
"name": "@blocksuite/store", | ||
"version": "0.4.0-20230114095726-16babb2", | ||
"version": "0.4.0-20230114163139-bef702b", | ||
"description": "BlockSuite data store built for general purpose state management.", | ||
@@ -11,3 +11,3 @@ "main": "dist/index.js", | ||
"dependencies": { | ||
"@blocksuite/global": "0.4.0-20230114095726-16babb2", | ||
"@blocksuite/global": "0.4.0-20230114163139-bef702b", | ||
"@types/flexsearch": "^0.7.3", | ||
@@ -25,3 +25,3 @@ "buffer": "^6.0.3", | ||
"cross-env": "^7.0.3", | ||
"lit": "^2.6.0", | ||
"lit": "^2.6.1", | ||
"yjs": "^13.5.44" | ||
@@ -28,0 +28,0 @@ }, |
@@ -397,3 +397,10 @@ import * as Y from 'yjs'; | ||
deleteBlock(model: BaseBlockModel) { | ||
deleteBlock( | ||
model: BaseBlockModel, | ||
options: { | ||
bringChildrenTo: 'parent' | BaseBlockModel; | ||
} = { | ||
bringChildrenTo: 'parent', | ||
} | ||
) { | ||
if (this.awareness.isReadonly()) { | ||
@@ -408,2 +415,7 @@ console.error('cannot modify data in readonly mode'); | ||
} | ||
if (options.bringChildrenTo === 'parent' && parent) { | ||
parent.children.unshift(...model.children); | ||
} else if (options.bringChildrenTo instanceof BaseBlockModel) { | ||
options.bringChildrenTo.children.unshift(...model.children); | ||
} | ||
this._blockMap.delete(model.id); | ||
@@ -413,2 +425,3 @@ | ||
this._yBlocks.delete(model.id); | ||
const children = model.children.map(model => model.id); | ||
model.dispose(); | ||
@@ -423,2 +436,9 @@ | ||
} | ||
if (options.bringChildrenTo === 'parent' && parent) { | ||
yChildren.unshift(children); | ||
} else if (options.bringChildrenTo instanceof BaseBlockModel) { | ||
this.updateBlockById(options.bringChildrenTo.id, { | ||
children: options.bringChildrenTo.children, | ||
}); | ||
} | ||
} | ||
@@ -425,0 +445,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
484544
7999
+ Added@blocksuite/global@0.4.0-20230114163139-bef702b(transitive)
- Removed@blocksuite/global@0.4.0-20230114095726-16babb2(transitive)