Skip to content

Commit

Permalink
fix(store): bring back remove page for subdoc (toeverything#3221)
Browse files Browse the repository at this point in the history
  • Loading branch information
Saul-Mirone authored Jun 27, 2023
1 parent 3682f92 commit 3cc34af
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 13 deletions.
9 changes: 5 additions & 4 deletions packages/blocks/src/__internal__/rich-text/reference-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,11 @@ export class AffineReference extends WithDisposable(ShadowlessElement) {
const refMeta = [...page.workspace.meta.pageMetas].find(
page => page.id === refAttribute.pageId
);
assertExists(refMeta);
this._refMeta = {
...refMeta,
};
this._refMeta = refMeta
? {
...refMeta,
}
: undefined;
};

private _onClick(e: MouseEvent) {
Expand Down
5 changes: 3 additions & 2 deletions packages/playground/src/components/debug-menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -701,8 +701,9 @@ function getTabGroupTemplate({
style="display: flex; overflow: hidden;"
@sl-tab-show=${(e: CustomEvent<{ name: string }>) => {
const otherPage = workspace.getPage(e.detail.name);
if (!otherPage) throw new Error('page not found');
editor.page = otherPage;
if (otherPage) {
editor.page = otherPage;
}
}}
>
${pageList.map(
Expand Down
6 changes: 3 additions & 3 deletions packages/store/src/__tests__/workspace.unit.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,9 +332,9 @@ describe('addBlock', () => {

// @ts-expect-error
assert.equal(workspace._pages.size, 1);
assert.deepEqual(
serializeWorkspace(page0.doc).spaces['space:page0'].blocks,
{}
assert.equal(
serializeWorkspace(page0.doc).spaces['space:page0'],
undefined
);

workspace.removePage(page1.id);
Expand Down
5 changes: 5 additions & 0 deletions packages/store/src/space.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ export class Space<
return this;
}

remove() {
this.destroy();
this.doc.spaces.delete(this.prefixedId);
}

destroy() {
this._ySpaceDoc.destroy();
this._onLoadSlot.dispose();
Expand Down
4 changes: 0 additions & 4 deletions packages/store/src/workspace/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,6 @@ export class Page extends Space<FlatBlockMap> {
return this._root;
}

getYBlockById(id: string) {
return this._yBlocks.get(id);
}

get isEmpty() {
return this._yBlocks.size === 0;
}
Expand Down
1 change: 1 addition & 0 deletions packages/store/src/workspace/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ export class Workspace {
this.meta.pageMetaRemoved.on(id => {
const page = this.getPage(id) as Page;
this._store.removeSpace(page);
page.remove();
this.slots.pageRemoved.emit(id);
});
}
Expand Down

0 comments on commit 3cc34af

Please sign in to comment.