mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-24 22:09:08 +08:00
feat(core): move enable ai to feature flag (#8195)
This commit is contained in:
@@ -11,6 +11,13 @@ import { map } from 'rxjs';
|
||||
import type { EditorSettingProvider } from '../provider/editor-setting-provider';
|
||||
import { EditorSettingSchema } from '../schema';
|
||||
|
||||
type SettingItem<T> = {
|
||||
readonly value: T;
|
||||
set: (value: T) => void;
|
||||
// eslint-disable-next-line rxjs/finnish
|
||||
$: T;
|
||||
};
|
||||
|
||||
export class EditorSetting extends Entity {
|
||||
constructor(public readonly provider: EditorSettingProvider) {
|
||||
super();
|
||||
@@ -20,6 +27,27 @@ export class EditorSetting extends Entity {
|
||||
>(this.settings$, {});
|
||||
this.settingSignal = signal;
|
||||
this.disposables.push(cleanup);
|
||||
|
||||
Object.entries(EditorSettingSchema.shape).forEach(([flagKey, flag]) => {
|
||||
const livedata$ = this.settings$.selector(
|
||||
s => s[flagKey as keyof EditorSettingSchema]
|
||||
);
|
||||
const item = {
|
||||
...flag,
|
||||
get value() {
|
||||
return livedata$.value;
|
||||
},
|
||||
set: (value: any) => {
|
||||
this.set(flagKey as keyof EditorSettingSchema, value);
|
||||
},
|
||||
$: livedata$,
|
||||
} as SettingItem<unknown>;
|
||||
Object.defineProperty(this, flagKey, {
|
||||
get: () => {
|
||||
return item;
|
||||
},
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
settings$ = LiveData.from<EditorSettingSchema>(this.watchAll(), null as any);
|
||||
@@ -61,3 +89,7 @@ export class EditorSetting extends Entity {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export type EditorSettingExt = EditorSetting & {
|
||||
[K in keyof EditorSettingSchema]: SettingItem<EditorSettingSchema[K]>;
|
||||
};
|
||||
|
||||
@@ -16,7 +16,6 @@ export const fontStyleOptions = [
|
||||
}[];
|
||||
|
||||
const AffineEditorSettingSchema = z.object({
|
||||
enableAI: z.boolean().default(true),
|
||||
fontFamily: z.enum(['Sans', 'Serif', 'Mono', 'Custom']).default('Sans'),
|
||||
customFontFamily: z.string().default(''),
|
||||
newDocDefaultMode: z.enum(['edgeless', 'page']).default('page'),
|
||||
|
||||
@@ -6,11 +6,16 @@ import {
|
||||
WorkspaceInitialized,
|
||||
} from '@toeverything/infra';
|
||||
|
||||
import { EditorSetting } from '../entities/editor-setting';
|
||||
import {
|
||||
EditorSetting,
|
||||
type EditorSettingExt,
|
||||
} from '../entities/editor-setting';
|
||||
|
||||
@OnEvent(WorkspaceInitialized, e => e.onWorkspaceInitialized)
|
||||
export class EditorSettingService extends Service {
|
||||
editorSetting = this.framework.createEntity(EditorSetting);
|
||||
editorSetting = this.framework.createEntity(
|
||||
EditorSetting
|
||||
) as EditorSettingExt;
|
||||
|
||||
onWorkspaceInitialized(workspace: Workspace) {
|
||||
// set default mode for new doc
|
||||
|
||||
Reference in New Issue
Block a user