mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 20:38:52 +00:00
refactor(editor): rename model.doc to store (#12172)
This commit is contained in:
@@ -164,7 +164,7 @@ export class GfxBlockElementModel<
|
||||
}
|
||||
|
||||
get surface(): SurfaceBlockModel | null {
|
||||
const result = this.doc.getBlocksByFlavour('affine:surface');
|
||||
const result = this.store.getBlocksByFlavour('affine:surface');
|
||||
if (result.length === 0) return null;
|
||||
return result[0].model as SurfaceBlockModel;
|
||||
}
|
||||
@@ -257,11 +257,11 @@ export class GfxBlockElementModel<
|
||||
}
|
||||
|
||||
lock() {
|
||||
lockElementImpl(this.doc, this);
|
||||
lockElementImpl(this.store, this);
|
||||
}
|
||||
|
||||
unlock() {
|
||||
unlockElementImpl(this.doc, this);
|
||||
unlockElementImpl(this.store, this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ export function field<V, T extends GfxPrimitiveElementModel>(fallback?: V) {
|
||||
|
||||
if (this.yMap) {
|
||||
if (this.yMap.doc) {
|
||||
this.surface.doc.transact(() => {
|
||||
this.surface.store.transact(() => {
|
||||
this.yMap.set(prop as string, v);
|
||||
});
|
||||
} else {
|
||||
@@ -69,7 +69,7 @@ export function field<V, T extends GfxPrimitiveElementModel>(fallback?: V) {
|
||||
: convertProps(prop, originalVal, this);
|
||||
|
||||
if (this.yMap.doc) {
|
||||
this.surface.doc.transact(() => {
|
||||
this.surface.store.transact(() => {
|
||||
this.yMap.set(prop as string, val);
|
||||
});
|
||||
} else {
|
||||
|
||||
@@ -256,7 +256,7 @@ export abstract class GfxPrimitiveElementModel<
|
||||
}
|
||||
|
||||
lock() {
|
||||
lockElementImpl(this.surface.doc, this);
|
||||
lockElementImpl(this.surface.store, this);
|
||||
}
|
||||
|
||||
onCreated() {}
|
||||
@@ -278,7 +278,7 @@ export abstract class GfxPrimitiveElementModel<
|
||||
|
||||
if (getFieldPropsSet(this).has(prop as string)) {
|
||||
if (!isEqual(value, this.yMap.get(prop as string))) {
|
||||
this.surface.doc.transact(() => {
|
||||
this.surface.store.transact(() => {
|
||||
this.yMap.set(prop as string, value);
|
||||
});
|
||||
}
|
||||
@@ -339,7 +339,7 @@ export abstract class GfxPrimitiveElementModel<
|
||||
}
|
||||
|
||||
unlock() {
|
||||
unlockElementImpl(this.surface.doc, this);
|
||||
unlockElementImpl(this.surface.store, this);
|
||||
}
|
||||
|
||||
@local()
|
||||
@@ -396,7 +396,7 @@ export abstract class GfxGroupLikeElementModel<
|
||||
for (const key of this.childIds) {
|
||||
const element =
|
||||
this.surface.getElementById(key) ||
|
||||
(this.surface.doc.getModelById(key) as GfxBlockElementModel);
|
||||
(this.surface.store.getModelById(key) as GfxBlockElementModel);
|
||||
|
||||
element && elements.push(element);
|
||||
}
|
||||
|
||||
@@ -368,7 +368,7 @@ export class SurfaceBlockModel extends BlockModel<SurfaceBlockProps> {
|
||||
mount();
|
||||
});
|
||||
|
||||
Object.values(this.doc.blocks.peek()).forEach(block => {
|
||||
Object.values(this.store.blocks.peek()).forEach(block => {
|
||||
if (isGfxGroupCompatibleModel(block.model)) {
|
||||
this._groupLikeModels.set(block.id, block.model);
|
||||
}
|
||||
@@ -376,7 +376,7 @@ export class SurfaceBlockModel extends BlockModel<SurfaceBlockProps> {
|
||||
|
||||
elementsYMap.observe(onElementsMapChange);
|
||||
|
||||
const subscription = this.doc.slots.blockUpdated.subscribe(payload => {
|
||||
const subscription = this.store.slots.blockUpdated.subscribe(payload => {
|
||||
switch (payload.type) {
|
||||
case 'add':
|
||||
if (isGfxGroupCompatibleModel(payload.model)) {
|
||||
@@ -468,7 +468,7 @@ export class SurfaceBlockModel extends BlockModel<SurfaceBlockProps> {
|
||||
const disposables = new DisposableGroup();
|
||||
disposables.add(this.elementAdded.subscribe(updateIsEmpty));
|
||||
disposables.add(this.elementRemoved.subscribe(updateIsEmpty));
|
||||
this.doc.slots.blockUpdated.subscribe(payload => {
|
||||
this.store.slots.blockUpdated.subscribe(payload => {
|
||||
if (['add', 'delete'].includes(payload.type)) {
|
||||
updateIsEmpty();
|
||||
}
|
||||
@@ -503,7 +503,7 @@ export class SurfaceBlockModel extends BlockModel<SurfaceBlockProps> {
|
||||
addElement<T extends object = Record<string, unknown>>(
|
||||
props: Partial<T> & { type: string }
|
||||
) {
|
||||
if (this.doc.readonly) {
|
||||
if (this.store.readonly) {
|
||||
throw new Error('Cannot add element in readonly mode');
|
||||
}
|
||||
|
||||
@@ -535,7 +535,7 @@ export class SurfaceBlockModel extends BlockModel<SurfaceBlockProps> {
|
||||
|
||||
this._elementModels.set(id, elementModel);
|
||||
|
||||
this.doc.transact(() => {
|
||||
this.store.transact(() => {
|
||||
this.elements.getValue()!.set(id, elementModel.model.yMap);
|
||||
});
|
||||
|
||||
@@ -552,7 +552,7 @@ export class SurfaceBlockModel extends BlockModel<SurfaceBlockProps> {
|
||||
}
|
||||
|
||||
deleteElement(id: string) {
|
||||
if (this.doc.readonly) {
|
||||
if (this.store.readonly) {
|
||||
throw new Error('Cannot remove element in readonly mode');
|
||||
}
|
||||
|
||||
@@ -560,7 +560,7 @@ export class SurfaceBlockModel extends BlockModel<SurfaceBlockProps> {
|
||||
return;
|
||||
}
|
||||
|
||||
this.doc.transact(() => {
|
||||
this.store.transact(() => {
|
||||
const element = this.getElementById(id)!;
|
||||
const group = this.getGroup(id);
|
||||
|
||||
@@ -568,8 +568,8 @@ export class SurfaceBlockModel extends BlockModel<SurfaceBlockProps> {
|
||||
element.childIds.forEach(childId => {
|
||||
if (this.hasElementById(childId)) {
|
||||
this.deleteElement(childId);
|
||||
} else if (this.doc.hasBlock(childId)) {
|
||||
this.doc.deleteBlock(this.doc.getBlock(childId)!.model);
|
||||
} else if (this.store.hasBlock(childId)) {
|
||||
this.store.deleteBlock(this.store.getBlock(childId)!.model);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -610,7 +610,7 @@ export class SurfaceBlockModel extends BlockModel<SurfaceBlockProps> {
|
||||
elem =
|
||||
typeof elem === 'string'
|
||||
? ((this.getElementById(elem) ??
|
||||
this.doc.getBlock(elem)?.model) as GfxModel)
|
||||
this.store.getBlock(elem)?.model) as GfxModel)
|
||||
: elem;
|
||||
|
||||
if (!elem) return null;
|
||||
@@ -655,7 +655,7 @@ export class SurfaceBlockModel extends BlockModel<SurfaceBlockProps> {
|
||||
const el = this.getElementById(element);
|
||||
if (el) return isGfxGroupCompatibleModel(el);
|
||||
|
||||
const blockModel = this.doc.getBlock(element)?.model;
|
||||
const blockModel = this.store.getBlock(element)?.model;
|
||||
if (blockModel) return isGfxGroupCompatibleModel(blockModel);
|
||||
|
||||
return false;
|
||||
@@ -668,7 +668,7 @@ export class SurfaceBlockModel extends BlockModel<SurfaceBlockProps> {
|
||||
id: string,
|
||||
props: Partial<T>
|
||||
) {
|
||||
if (this.doc.readonly) {
|
||||
if (this.store.readonly) {
|
||||
throw new Error('Cannot update element in readonly mode');
|
||||
}
|
||||
|
||||
@@ -678,7 +678,7 @@ export class SurfaceBlockModel extends BlockModel<SurfaceBlockProps> {
|
||||
throw new Error(`Element ${id} is not found`);
|
||||
}
|
||||
|
||||
this.doc.transact(() => {
|
||||
this.store.transact(() => {
|
||||
props = this._propsToY(
|
||||
elementModel.type,
|
||||
props as Record<string, unknown>
|
||||
|
||||
@@ -97,16 +97,16 @@ export class BlockModel<Props extends object = object> {
|
||||
return this._childModels.value;
|
||||
}
|
||||
|
||||
get doc() {
|
||||
get store() {
|
||||
return this._store;
|
||||
}
|
||||
|
||||
set doc(doc: Store) {
|
||||
set store(doc: Store) {
|
||||
this._store = doc;
|
||||
}
|
||||
|
||||
get parent() {
|
||||
return this.doc.getParent(this);
|
||||
return this.store.getParent(this);
|
||||
}
|
||||
|
||||
get role() {
|
||||
|
||||
@@ -63,7 +63,7 @@ export class FlatSyncController {
|
||||
model.stash = this.stash;
|
||||
model.pop = this.pop;
|
||||
if (this.doc) {
|
||||
model.doc = this.doc;
|
||||
model.store = this.doc;
|
||||
}
|
||||
|
||||
const defaultProps = schema.model.props?.(internalPrimitives);
|
||||
|
||||
@@ -168,7 +168,7 @@ export class SyncController {
|
||||
model.stash = this.stash;
|
||||
model.pop = this.pop;
|
||||
if (this.doc) {
|
||||
model.doc = this.doc;
|
||||
model.store = this.doc;
|
||||
}
|
||||
|
||||
const proxy = new Proxy(signalWithProps, {
|
||||
|
||||
@@ -70,7 +70,7 @@ function getBlockViewType(query: Query, block: Block): BlockViewType {
|
||||
}
|
||||
|
||||
function setAncestorsToDisplayIfHidden(mode: QueryMode, block: Block) {
|
||||
const doc = block.model.doc;
|
||||
const doc = block.model.store;
|
||||
let parent = doc.getParent(block.model);
|
||||
while (parent) {
|
||||
const parentBlock = doc.getBlock(parent.id);
|
||||
|
||||
Reference in New Issue
Block a user