refactor(core): implement doc created/updated by service (#12150)

<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
## Summary by CodeRabbit

- **New Features**
  - Documents now automatically track and display "created by" and "updated by" user information.
  - Document creation and update timestamps are now managed and shown more accurately.
  - Workspace and document metadata (name, avatar) updates are more responsive and reliable.
  - Document creation supports middleware for customizing properties and behavior.

- **Improvements**
  - Simplified and unified event handling for document list updates, reducing redundant event subscriptions.
  - Enhanced integration of editor and theme settings into the document creation process.
  - Explicit Yjs document initialization for improved workspace stability and reliability.
  - Consolidated journal-related metadata display in document icons and titles for clarity.

- **Bug Fixes**
  - Fixed inconsistencies in how workspace and document names are set and updated.
  - Improved accuracy of "last updated" indicators by handling timestamps automatically.

- **Refactor**
  - Removed deprecated event subjects and direct metadata manipulation in favor of more robust, reactive patterns.
  - Streamlined document creation logic across various features (quick search, journal, recording, etc.).
  - Simplified user avatar display components and removed cloud metadata dependencies.
  - Removed legacy editor setting and theme service dependencies from multiple modules.

- **Chores**
  - Updated internal APIs and interfaces to support new metadata and event handling mechanisms.
  - Cleaned up unused code and dependencies related to editor settings and theme services.
  - Skipped flaky end-to-end test to improve test suite stability.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
EYHN
2025-05-08 07:53:33 +00:00
parent 93d74ff220
commit 2d1600fa00
56 changed files with 496 additions and 458 deletions
@@ -30,10 +30,6 @@ export class TestMeta implements WorkspaceMeta {
) {
this._handleDocMetaEvent();
}
if (hasKey('name') || hasKey('avatar')) {
this._handleCommonFieldsEvent();
}
});
};
@@ -45,8 +41,6 @@ export class TestMeta implements WorkspaceMeta {
DocCollectionMetaState[keyof DocCollectionMetaState]
>;
commonFieldsUpdated = new Subject<void>();
readonly doc: Y.Doc;
docMetaAdded = new Subject<string>();
@@ -57,10 +51,6 @@ export class TestMeta implements WorkspaceMeta {
readonly id: string = 'meta';
get avatar() {
return this._proxy.avatar;
}
get docMetas() {
if (!this._proxy.pages) {
return [] as DocMeta[];
@@ -72,10 +62,6 @@ export class TestMeta implements WorkspaceMeta {
return this._proxy.pages;
}
get name() {
return this._proxy.name;
}
get properties(): DocsPropertiesMeta {
const meta = this._proxy.properties;
if (!meta) {
@@ -102,10 +88,6 @@ export class TestMeta implements WorkspaceMeta {
this._yMap.observeDeep(this._handleDocCollectionMetaEvents);
}
private _handleCommonFieldsEvent() {
this.commonFieldsUpdated.next();
}
private _handleDocMetaEvent() {
const { docMetas, _prevDocs } = this;
@@ -173,12 +155,6 @@ export class TestMeta implements WorkspaceMeta {
}, this.doc.clientID);
}
setAvatar(avatar: string) {
this.doc.transact(() => {
this._proxy.avatar = avatar;
}, this.doc.clientID);
}
setDocMeta(id: string, props: Partial<DocMeta>) {
const docs = (this.docs as DocMeta[]) ?? [];
const index = docs.findIndex((doc: DocMeta) => id === doc.id);
@@ -196,12 +172,6 @@ export class TestMeta implements WorkspaceMeta {
}, this.doc.clientID);
}
setName(name: string) {
this.doc.transact(() => {
this._proxy.name = name;
}, this.doc.clientID);
}
setProperties(meta: DocsPropertiesMeta) {
this._proxy.properties = meta;
this.docMetaUpdated.next();
@@ -67,8 +67,6 @@ export class TestWorkspace implements Workspace {
slots = {
docListUpdated: new Subject<void>(),
docRemoved: new Subject<string>(),
docCreated: new Subject<string>(),
};
get docs() {
@@ -132,7 +130,6 @@ export class TestWorkspace implements Workspace {
if (!space) return;
this.blockCollections.delete(id);
space.remove();
this.slots.docRemoved.next(id);
});
}
@@ -168,7 +165,6 @@ export class TestWorkspace implements Workspace {
createDate: Date.now(),
tags: [],
});
this.slots.docCreated.next(id);
return this.getDoc(id) as Doc;
}