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

View File

@@ -454,19 +454,6 @@ describe('addBlock', () => {
);
assert.ok(called);
});
it('can set collection common meta fields', async () => {
const options = createTestOptions();
const collection = new TestWorkspace(options);
queueMicrotask(() => collection.meta.setName('hello'));
await waitOnce(collection.meta.commonFieldsUpdated);
assert.deepEqual(collection.meta.name, 'hello');
queueMicrotask(() => collection.meta.setAvatar('gengar.jpg'));
await waitOnce(collection.meta.commonFieldsUpdated);
assert.deepEqual(collection.meta.avatar, 'gengar.jpg');
});
});
describe('deleteBlock', () => {

View File

@@ -30,16 +30,9 @@ export interface WorkspaceMeta {
get properties(): DocsPropertiesMeta;
setProperties(meta: DocsPropertiesMeta): void;
get avatar(): string | undefined;
setAvatar(avatar: string): void;
get name(): string | undefined;
setName(name: string): void;
get docs(): unknown[] | undefined;
initialize(): void;
commonFieldsUpdated: Subject<void>;
docMetaAdded: Subject<string>;
docMetaRemoved: Subject<string>;
docMetaUpdated: Subject<void>;

View File

@@ -20,8 +20,6 @@ export interface Workspace {
slots: {
docListUpdated: Subject<void>;
docCreated: Subject<string>;
docRemoved: Subject<string>;
};
createDoc(docId?: string): Doc;

View File

@@ -386,7 +386,7 @@ export class Store {
console.error(e);
}
},
shouldTransact ? this.rootDoc.clientID : null
shouldTransact ? this.spaceDoc.clientID : null
);
}

View File

@@ -23,9 +23,10 @@ export abstract class BaseReactiveYData<
protected _onObserve = (event: Y.YEvent<any>, handler: () => void) => {
if (
event.transaction.origin?.proxy !== true &&
(!event.transaction.local ||
event.transaction.origin instanceof Y.UndoManager)
event.transaction.origin?.force === true ||
(event.transaction.origin?.proxy !== true &&
(!event.transaction.local ||
event.transaction.origin instanceof Y.UndoManager))
) {
handler();
}

View File

@@ -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();

View File

@@ -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;
}