editor-settings.ts 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import {
  2. Schema, Model, Document,
  3. } from 'mongoose';
  4. import { IEditorSettings, ITextlintSettings } from '~/interfaces/editor-settings';
  5. import { getOrCreateModel } from '../util/mongoose-utils';
  6. export interface EditorSettingsDocument extends IEditorSettings, Document {
  7. userId: Schema.Types.ObjectId,
  8. }
  9. export type EditorSettingsModel = Model<EditorSettingsDocument>
  10. const textlintSettingsSchema = new Schema<ITextlintSettings>({
  11. neverAskBeforeDownloadLargeFiles: { type: Boolean, default: false },
  12. textlintRules: {
  13. type: [
  14. { name: { type: String }, options: { type: Object }, isEnabled: { type: Boolean } },
  15. ],
  16. },
  17. });
  18. const editorSettingsSchema = new Schema<EditorSettingsDocument, EditorSettingsModel>({
  19. userId: { type: Schema.Types.ObjectId },
  20. theme: { type: String },
  21. keymapMode: { type: String },
  22. styleActiveLine: { type: Boolean, default: false },
  23. renderMathJaxInRealtime: { type: Boolean, default: true },
  24. renderDrawioInRealtime: { type: Boolean, default: true },
  25. autoFormatMarkdownTable: { type: Boolean, default: true },
  26. textlintSettings: textlintSettingsSchema,
  27. });
  28. export default getOrCreateModel<EditorSettingsDocument, EditorSettingsModel>('EditorSettings', editorSettingsSchema);