@nocobase/plugin-theme-editor 0.14.0-alpha.6 → 0.14.0-alpha.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,12 +1,13 @@
1
1
  module.exports = {
2
- "@nocobase/client": "0.14.0-alpha.6",
2
+ "@nocobase/client": "0.14.0-alpha.8",
3
3
  "react": "18.2.0",
4
4
  "antd": "5.8.6",
5
5
  "lodash": "4.17.21",
6
- "@nocobase/server": "0.14.0-alpha.6",
6
+ "@nocobase/server": "0.14.0-alpha.8",
7
7
  "@ant-design/cssinjs": "1.13.2",
8
8
  "@ant-design/icons": "5.1.4",
9
- "@nocobase/utils": "0.14.0-alpha.6",
9
+ "@nocobase/utils": "0.14.0-alpha.8",
10
10
  "react-i18next": "11.18.6",
11
+ "@nocobase/database": "0.14.0-alpha.8",
11
12
  "@emotion/css": "11.11.2"
12
13
  };
@@ -15,7 +15,6 @@ declare const locale: {
15
15
  'Add new theme': string;
16
16
  'Edit based on current theme': string;
17
17
  'Create a brand new theme': string;
18
- 'Default theme of antd': string;
19
18
  Dark: string;
20
19
  Compact: string;
21
20
  'Compact dark': string;
@@ -37,8 +37,6 @@ const locale = {
37
37
  "Add new theme": "\u6DFB\u52A0\u65B0\u4E3B\u9898",
38
38
  "Edit based on current theme": "\u57FA\u4E8E\u5F53\u524D\u4E3B\u9898\u8FDB\u884C\u7F16\u8F91",
39
39
  "Create a brand new theme": "\u521B\u5EFA\u4E00\u4E2A\u5168\u65B0\u7684\u4E3B\u9898",
40
- // 内置主题的名字
41
- "Default theme of antd": "antd \u9ED8\u8BA4\u4E3B\u9898",
42
40
  Dark: "\u6697\u9ED1",
43
41
  Compact: "\u7D27\u51D1",
44
42
  "Compact dark": "\u7D27\u51D1\u6697\u9ED1",
@@ -1,6 +1,6 @@
1
1
  import { ThemeItem } from '../types';
2
2
  /** antd 默认主题 */
3
- export declare const antd: Omit<ThemeItem, 'id'>;
3
+ export declare const defaultTheme: Omit<ThemeItem, 'id'>;
4
4
  export declare const dark: Omit<ThemeItem, 'id'>;
5
5
  export declare const compact: Omit<ThemeItem, 'id'>;
6
6
  /** 同时包含 `紧凑` 和 `暗黑` 两种模式 */
@@ -17,18 +17,19 @@ var __copyProps = (to, from, except, desc) => {
17
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
18
  var builtinThemes_exports = {};
19
19
  __export(builtinThemes_exports, {
20
- antd: () => antd,
21
20
  compact: () => compact,
22
21
  compactDark: () => compactDark,
23
- dark: () => dark
22
+ dark: () => dark,
23
+ defaultTheme: () => defaultTheme
24
24
  });
25
25
  module.exports = __toCommonJS(builtinThemes_exports);
26
- const antd = {
26
+ const defaultTheme = {
27
27
  config: {
28
- name: "Default theme of antd"
28
+ name: "Default"
29
29
  },
30
30
  optional: true,
31
- isBuiltIn: true
31
+ isBuiltIn: true,
32
+ uid: "default"
32
33
  };
33
34
  const dark = {
34
35
  config: {
@@ -37,7 +38,8 @@ const dark = {
37
38
  algorithm: "darkAlgorithm"
38
39
  },
39
40
  optional: true,
40
- isBuiltIn: true
41
+ isBuiltIn: true,
42
+ uid: "dark"
41
43
  };
42
44
  const compact = {
43
45
  config: {
@@ -46,7 +48,8 @@ const compact = {
46
48
  algorithm: "compactAlgorithm"
47
49
  },
48
50
  optional: true,
49
- isBuiltIn: true
51
+ isBuiltIn: true,
52
+ uid: "compact"
50
53
  };
51
54
  const compactDark = {
52
55
  config: {
@@ -55,12 +58,13 @@ const compactDark = {
55
58
  algorithm: ["compactAlgorithm", "darkAlgorithm"]
56
59
  },
57
60
  optional: true,
58
- isBuiltIn: true
61
+ isBuiltIn: true,
62
+ uid: "compact_dark"
59
63
  };
60
64
  // Annotate the CommonJS export names for ESM import in node:
61
65
  0 && (module.exports = {
62
- antd,
63
66
  compact,
64
67
  compactDark,
65
- dark
68
+ dark,
69
+ defaultTheme
66
70
  });
@@ -0,0 +1,5 @@
1
+ import { Migration } from '@nocobase/server';
2
+ export default class ThemeEditorMigration extends Migration {
3
+ up(): Promise<void>;
4
+ down(): Promise<void>;
5
+ }
@@ -0,0 +1,79 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var theme_editor_exports = {};
19
+ __export(theme_editor_exports, {
20
+ default: () => ThemeEditorMigration
21
+ });
22
+ module.exports = __toCommonJS(theme_editor_exports);
23
+ var import_server = require("@nocobase/server");
24
+ var import_utils = require("@nocobase/utils");
25
+ var import_builtinThemes = require("../builtinThemes");
26
+ class ThemeEditorMigration extends import_server.Migration {
27
+ async up() {
28
+ const result = await this.app.version.satisfies("<0.14.0-alpha.8");
29
+ if (!result) {
30
+ return;
31
+ }
32
+ const repository = this.db.getRepository("themeConfig");
33
+ if (!repository) {
34
+ return;
35
+ }
36
+ const collection = this.db.getCollection("themeConfig");
37
+ await collection.sync();
38
+ const themes = {
39
+ [import_builtinThemes.defaultTheme.uid]: import_builtinThemes.defaultTheme,
40
+ [import_builtinThemes.dark.uid]: import_builtinThemes.dark,
41
+ [import_builtinThemes.compact.uid]: import_builtinThemes.compact,
42
+ [import_builtinThemes.compactDark.uid]: import_builtinThemes.compactDark
43
+ };
44
+ const items = await repository.find();
45
+ for (const item of items) {
46
+ if (item.uid) {
47
+ if (themes[item.uid]) {
48
+ delete themes[item.uid];
49
+ }
50
+ continue;
51
+ }
52
+ const config = item.get("config");
53
+ if (config.name === "Default theme of antd") {
54
+ item.set("uid", import_builtinThemes.defaultTheme.uid);
55
+ config.name = import_builtinThemes.defaultTheme.config.name;
56
+ item.set("config", config);
57
+ item.changed("config", true);
58
+ delete themes[import_builtinThemes.defaultTheme.uid];
59
+ } else if (config.name === import_builtinThemes.dark.config.name) {
60
+ item.set("uid", import_builtinThemes.dark.uid);
61
+ delete themes[import_builtinThemes.dark.uid];
62
+ } else if (config.name === import_builtinThemes.compact.config.name) {
63
+ item.set("uid", import_builtinThemes.compact.uid);
64
+ delete themes[import_builtinThemes.compact.uid];
65
+ } else if (config.name === import_builtinThemes.compactDark.config.name) {
66
+ item.set("uid", import_builtinThemes.compactDark.uid);
67
+ delete themes[import_builtinThemes.compactDark.uid];
68
+ } else {
69
+ item.set("uid", (0, import_utils.uid)());
70
+ }
71
+ await item.save();
72
+ }
73
+ if (Object.values(themes).length > 0) {
74
+ await repository.create({ values: Object.values(themes) });
75
+ }
76
+ }
77
+ async down() {
78
+ }
79
+ }
@@ -2,7 +2,7 @@ import { InstallOptions, Plugin } from '@nocobase/server';
2
2
  export declare class ThemeEditorPlugin extends Plugin {
3
3
  theme: any;
4
4
  afterAdd(): void;
5
- beforeLoad(): void;
5
+ beforeLoad(): Promise<void>;
6
6
  load(): Promise<void>;
7
7
  install(options?: InstallOptions): Promise<void>;
8
8
  afterEnable(): Promise<void>;
@@ -22,12 +22,20 @@ __export(plugin_exports, {
22
22
  });
23
23
  module.exports = __toCommonJS(plugin_exports);
24
24
  var import_server = require("@nocobase/server");
25
+ var import_path = require("path");
25
26
  var import_builtinThemes = require("./builtinThemes");
26
27
  class ThemeEditorPlugin extends import_server.Plugin {
27
28
  theme;
28
29
  afterAdd() {
29
30
  }
30
- beforeLoad() {
31
+ async beforeLoad() {
32
+ this.db.addMigrations({
33
+ namespace: "theme-editor",
34
+ directory: (0, import_path.resolve)(__dirname, "./migrations"),
35
+ context: {
36
+ plugin: this
37
+ }
38
+ });
31
39
  }
32
40
  async load() {
33
41
  this.db.collection({
@@ -46,10 +54,14 @@ class ThemeEditorPlugin extends import_server.Plugin {
46
54
  {
47
55
  type: "boolean",
48
56
  name: "isBuiltIn"
57
+ },
58
+ {
59
+ type: "uid",
60
+ name: "uid"
49
61
  }
50
62
  ]
51
63
  });
52
- this.app.acl.allow("themeConfig", "list", "loggedIn");
64
+ this.app.acl.allow("themeConfig", "list", "public");
53
65
  this.app.acl.registerSnippet({
54
66
  name: `pm.${this.name}.themeConfig`,
55
67
  actions: ["themeConfig:*"]
@@ -62,7 +74,7 @@ class ThemeEditorPlugin extends import_server.Plugin {
62
74
  }
63
75
  if (await themeRepo.count() === 0) {
64
76
  await themeRepo.create({
65
- values: [import_builtinThemes.antd, import_builtinThemes.dark, import_builtinThemes.compact, import_builtinThemes.compactDark]
77
+ values: [import_builtinThemes.defaultTheme, import_builtinThemes.dark, import_builtinThemes.compact, import_builtinThemes.compactDark]
66
78
  });
67
79
  }
68
80
  }
package/dist/types.d.ts CHANGED
@@ -10,6 +10,7 @@ export interface ThemeItem {
10
10
  /** 主题是否可选 */
11
11
  optional: boolean;
12
12
  isBuiltIn?: boolean;
13
+ uid?: string;
13
14
  }
14
15
  export type Theme = {
15
16
  name: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/plugin-theme-editor",
3
- "version": "0.14.0-alpha.6",
3
+ "version": "0.14.0-alpha.8",
4
4
  "main": "dist/server/index.js",
5
5
  "displayName": "Theme editor",
6
6
  "displayName.zh-CN": "主题编辑器",
@@ -30,5 +30,5 @@
30
30
  "@nocobase/test": "0.x",
31
31
  "@nocobase/utils": "0.x"
32
32
  },
33
- "gitHead": "7f2858222231c207030b57704a0bb6ebc98e4e45"
33
+ "gitHead": "59c82fef6e34707802b5841f5ec4d9b3b6b68abb"
34
34
  }