@nocobase/plugin-ui-layout 2.2.0-alpha.2

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.
Files changed (55) hide show
  1. package/LICENSE.txt +107 -0
  2. package/README.md +17 -0
  3. package/client-v2.d.ts +2 -0
  4. package/client-v2.js +1 -0
  5. package/client.d.ts +2 -0
  6. package/client.js +1 -0
  7. package/dist/client/index.d.ts +9 -0
  8. package/dist/client/index.js +10 -0
  9. package/dist/client/plugin.d.ts +12 -0
  10. package/dist/client-v2/647.3a2f92424b5ce814.js +10 -0
  11. package/dist/client-v2/983.f95caf8d9687987d.js +10 -0
  12. package/dist/client-v2/index.d.ts +11 -0
  13. package/dist/client-v2/index.js +10 -0
  14. package/dist/client-v2/layoutRegistration.d.ts +28 -0
  15. package/dist/client-v2/locale.d.ts +9 -0
  16. package/dist/client-v2/mobileOpenViewAction.d.ts +206 -0
  17. package/dist/client-v2/mobilePageModelResolution.d.ts +9 -0
  18. package/dist/client-v2/mobileRouteRepository.d.ts +44 -0
  19. package/dist/client-v2/models/MobileLayoutModel.d.ts +102 -0
  20. package/dist/client-v2/models/MobileMenuComponents.d.ts +10 -0
  21. package/dist/client-v2/models/MobileMenuModels.d.ts +97 -0
  22. package/dist/client-v2/models/MobileMenuUtils.d.ts +30 -0
  23. package/dist/client-v2/models/MobilePageModels.d.ts +26 -0
  24. package/dist/client-v2/models/mobileComponents.d.ts +18 -0
  25. package/dist/client-v2/models/mobileFlowCompat.d.ts +61 -0
  26. package/dist/client-v2/models/mobileThemeToken.d.ts +25 -0
  27. package/dist/client-v2/pages/RoutesPage.d.ts +22 -0
  28. package/dist/client-v2/pages/UiLayoutsPage.d.ts +80 -0
  29. package/dist/client-v2/permissions/LayoutAwareDesktopRoutesPermissionsTab.d.ts +22 -0
  30. package/dist/client-v2/permissions/layoutAwareDesktopRoutesPermissions.d.ts +22 -0
  31. package/dist/client-v2/plugin.d.ts +14 -0
  32. package/dist/constants.d.ts +29 -0
  33. package/dist/constants.js +64 -0
  34. package/dist/externalVersion.js +33 -0
  35. package/dist/index.d.ts +10 -0
  36. package/dist/index.js +48 -0
  37. package/dist/locale/en-US.json +163 -0
  38. package/dist/locale/zh-CN.json +163 -0
  39. package/dist/server/collections/desktopRoutes.d.ts +14 -0
  40. package/dist/server/collections/desktopRoutes.js +48 -0
  41. package/dist/server/collections/uiLayouts.d.ts +10 -0
  42. package/dist/server/collections/uiLayouts.js +85 -0
  43. package/dist/server/ensureDefaultUiLayout.d.ts +10 -0
  44. package/dist/server/ensureDefaultUiLayout.js +129 -0
  45. package/dist/server/index.d.ts +9 -0
  46. package/dist/server/index.js +42 -0
  47. package/dist/server/migrations/20260601090000-ensure-default-admin-layout.d.ts +13 -0
  48. package/dist/server/migrations/20260601090000-ensure-default-admin-layout.js +39 -0
  49. package/dist/server/migrations/20260615090000-backfill-admin-layout-desktop-routes.d.ts +15 -0
  50. package/dist/server/migrations/20260615090000-backfill-admin-layout-desktop-routes.js +94 -0
  51. package/dist/server/plugin.d.ts +19 -0
  52. package/dist/server/plugin.js +662 -0
  53. package/package.json +37 -0
  54. package/server.d.ts +2 -0
  55. package/server.js +1 -0
@@ -0,0 +1,129 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
10
+ var __defProp = Object.defineProperty;
11
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
12
+ var __getOwnPropNames = Object.getOwnPropertyNames;
13
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
14
+ var __export = (target, all) => {
15
+ for (var name in all)
16
+ __defProp(target, name, { get: all[name], enumerable: true });
17
+ };
18
+ var __copyProps = (to, from, except, desc) => {
19
+ if (from && typeof from === "object" || typeof from === "function") {
20
+ for (let key of __getOwnPropNames(from))
21
+ if (!__hasOwnProp.call(to, key) && key !== except)
22
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
23
+ }
24
+ return to;
25
+ };
26
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
27
+ var ensureDefaultUiLayout_exports = {};
28
+ __export(ensureDefaultUiLayout_exports, {
29
+ ensureDefaultUiLayout: () => ensureDefaultUiLayout
30
+ });
31
+ module.exports = __toCommonJS(ensureDefaultUiLayout_exports);
32
+ var import_constants = require("../constants");
33
+ const GENERATED_DEFAULT_TITLE = "Untitled";
34
+ const DEFAULT_ADMIN_UI_LAYOUT_PROTECTED_FIELDS = [
35
+ "layoutType",
36
+ "routeName",
37
+ "routePath",
38
+ "authCheck",
39
+ "enabled"
40
+ ];
41
+ function getFallbackTitle(record) {
42
+ if (record.uid === import_constants.DEFAULT_ADMIN_UI_LAYOUT.uid) {
43
+ return import_constants.DEFAULT_ADMIN_UI_LAYOUT.title;
44
+ }
45
+ if (record.layoutType === import_constants.UI_LAYOUT_TYPE_MOBILE) {
46
+ return "Mobile layout";
47
+ }
48
+ if (record.layoutType === import_constants.UI_LAYOUT_TYPE_DESKTOP) {
49
+ return "Desktop layout";
50
+ }
51
+ return record.routeName || record.uid;
52
+ }
53
+ function shouldBackfillTitle(title) {
54
+ return !title || title === GENERATED_DEFAULT_TITLE;
55
+ }
56
+ async function ensureUiLayoutTitles(repository, transaction) {
57
+ const records = await repository.find({ transaction });
58
+ for (const record of records) {
59
+ if (!shouldBackfillTitle(record.get("title"))) {
60
+ continue;
61
+ }
62
+ await repository.update({
63
+ filterByTk: record.get("uid"),
64
+ values: {
65
+ title: getFallbackTitle(record.toJSON())
66
+ },
67
+ transaction
68
+ });
69
+ }
70
+ }
71
+ async function ensureDefaultMobileUiLayout(repository, transaction) {
72
+ const existed = await repository.findOne({
73
+ filter: {
74
+ uid: import_constants.DEFAULT_MOBILE_UI_LAYOUT.uid
75
+ },
76
+ transaction
77
+ });
78
+ if (existed) {
79
+ return;
80
+ }
81
+ await repository.create({
82
+ values: import_constants.DEFAULT_MOBILE_UI_LAYOUT,
83
+ transaction
84
+ });
85
+ }
86
+ async function ensureDefaultUiLayout(db) {
87
+ await db.sequelize.transaction(async (transaction) => {
88
+ const repository = db.getRepository("uiLayouts");
89
+ const existed = await repository.findOne({
90
+ filter: {
91
+ uid: import_constants.DEFAULT_ADMIN_UI_LAYOUT.uid
92
+ },
93
+ transaction
94
+ });
95
+ if (!existed) {
96
+ await repository.create({
97
+ values: import_constants.DEFAULT_ADMIN_UI_LAYOUT,
98
+ transaction
99
+ });
100
+ await ensureDefaultMobileUiLayout(repository, transaction);
101
+ await ensureUiLayoutTitles(repository, transaction);
102
+ return;
103
+ }
104
+ const values = {};
105
+ for (const field of DEFAULT_ADMIN_UI_LAYOUT_PROTECTED_FIELDS) {
106
+ if (existed.get(field) !== import_constants.DEFAULT_ADMIN_UI_LAYOUT[field]) {
107
+ Object.assign(values, {
108
+ [field]: import_constants.DEFAULT_ADMIN_UI_LAYOUT[field]
109
+ });
110
+ }
111
+ }
112
+ if (shouldBackfillTitle(existed.get("title"))) {
113
+ values.title = import_constants.DEFAULT_ADMIN_UI_LAYOUT.title;
114
+ }
115
+ if (Object.keys(values).length) {
116
+ await repository.update({
117
+ filterByTk: existed.get("uid"),
118
+ values,
119
+ transaction
120
+ });
121
+ }
122
+ await ensureUiLayoutTitles(repository, transaction);
123
+ await ensureDefaultMobileUiLayout(repository, transaction);
124
+ });
125
+ }
126
+ // Annotate the CommonJS export names for ESM import in node:
127
+ 0 && (module.exports = {
128
+ ensureDefaultUiLayout
129
+ });
@@ -0,0 +1,9 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+ export { default } from './plugin';
@@ -0,0 +1,42 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
10
+ var __create = Object.create;
11
+ var __defProp = Object.defineProperty;
12
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
13
+ var __getOwnPropNames = Object.getOwnPropertyNames;
14
+ var __getProtoOf = Object.getPrototypeOf;
15
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
16
+ var __export = (target, all) => {
17
+ for (var name in all)
18
+ __defProp(target, name, { get: all[name], enumerable: true });
19
+ };
20
+ var __copyProps = (to, from, except, desc) => {
21
+ if (from && typeof from === "object" || typeof from === "function") {
22
+ for (let key of __getOwnPropNames(from))
23
+ if (!__hasOwnProp.call(to, key) && key !== except)
24
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
25
+ }
26
+ return to;
27
+ };
28
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
29
+ // If the importer is in node compatibility mode or this is not an ESM
30
+ // file that has been converted to a CommonJS file using a Babel-
31
+ // compatible transform (i.e. "__esModule" has not been set), then set
32
+ // "default" to the CommonJS "module.exports" for node compatibility.
33
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
34
+ mod
35
+ ));
36
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
37
+ var server_exports = {};
38
+ __export(server_exports, {
39
+ default: () => import_plugin.default
40
+ });
41
+ module.exports = __toCommonJS(server_exports);
42
+ var import_plugin = __toESM(require("./plugin"));
@@ -0,0 +1,13 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+ import { Migration } from '@nocobase/server';
10
+ export default class extends Migration {
11
+ on: string;
12
+ up(): Promise<void>;
13
+ }
@@ -0,0 +1,39 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
10
+ var __defProp = Object.defineProperty;
11
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
12
+ var __getOwnPropNames = Object.getOwnPropertyNames;
13
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
14
+ var __export = (target, all) => {
15
+ for (var name in all)
16
+ __defProp(target, name, { get: all[name], enumerable: true });
17
+ };
18
+ var __copyProps = (to, from, except, desc) => {
19
+ if (from && typeof from === "object" || typeof from === "function") {
20
+ for (let key of __getOwnPropNames(from))
21
+ if (!__hasOwnProp.call(to, key) && key !== except)
22
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
23
+ }
24
+ return to;
25
+ };
26
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
27
+ var ensure_default_admin_layout_exports = {};
28
+ __export(ensure_default_admin_layout_exports, {
29
+ default: () => ensure_default_admin_layout_default
30
+ });
31
+ module.exports = __toCommonJS(ensure_default_admin_layout_exports);
32
+ var import_server = require("@nocobase/server");
33
+ var import_ensureDefaultUiLayout = require("../ensureDefaultUiLayout");
34
+ class ensure_default_admin_layout_default extends import_server.Migration {
35
+ on = "afterSync";
36
+ async up() {
37
+ await (0, import_ensureDefaultUiLayout.ensureDefaultUiLayout)(this.db);
38
+ }
39
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+ import type { Database } from '@nocobase/database';
10
+ import { Migration } from '@nocobase/server';
11
+ export declare function backfillAdminLayoutDesktopRoutes(db: Database): Promise<void>;
12
+ export default class extends Migration {
13
+ on: string;
14
+ up(): Promise<void>;
15
+ }
@@ -0,0 +1,94 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
10
+ var __defProp = Object.defineProperty;
11
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
12
+ var __getOwnPropNames = Object.getOwnPropertyNames;
13
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
14
+ var __export = (target, all) => {
15
+ for (var name in all)
16
+ __defProp(target, name, { get: all[name], enumerable: true });
17
+ };
18
+ var __copyProps = (to, from, except, desc) => {
19
+ if (from && typeof from === "object" || typeof from === "function") {
20
+ for (let key of __getOwnPropNames(from))
21
+ if (!__hasOwnProp.call(to, key) && key !== except)
22
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
23
+ }
24
+ return to;
25
+ };
26
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
27
+ var backfill_admin_layout_desktop_routes_exports = {};
28
+ __export(backfill_admin_layout_desktop_routes_exports, {
29
+ backfillAdminLayoutDesktopRoutes: () => backfillAdminLayoutDesktopRoutes,
30
+ default: () => backfill_admin_layout_desktop_routes_default
31
+ });
32
+ module.exports = __toCommonJS(backfill_admin_layout_desktop_routes_exports);
33
+ var import_server = require("@nocobase/server");
34
+ var import_constants = require("../../constants");
35
+ function hasRelationRecords(route, relationName) {
36
+ const records = route.get(relationName);
37
+ return Array.isArray(records) && records.length > 0;
38
+ }
39
+ function hasRelation(db, collectionName, relationName) {
40
+ var _a;
41
+ return !!((_a = db.getCollection(collectionName)) == null ? void 0 : _a.getField(relationName));
42
+ }
43
+ async function backfillAdminLayoutDesktopRoutesInTransaction(db, transaction) {
44
+ if (!db.getCollection("desktopRoutes") || !db.getCollection("uiLayouts")) {
45
+ return;
46
+ }
47
+ if (!hasRelation(db, "desktopRoutes", "uiLayouts")) {
48
+ return;
49
+ }
50
+ const adminLayout = await db.getRepository("uiLayouts").findOne({
51
+ filterByTk: import_constants.DEFAULT_ADMIN_UI_LAYOUT.uid,
52
+ transaction
53
+ });
54
+ if (!adminLayout) {
55
+ return;
56
+ }
57
+ const hasMultiPortalRelation = !!db.getCollection("multiPortals") && hasRelation(db, "desktopRoutes", "multiPortals");
58
+ const appends = hasMultiPortalRelation ? ["uiLayouts", "multiPortals"] : ["uiLayouts"];
59
+ const routes = await db.getRepository("desktopRoutes").find({
60
+ appends,
61
+ transaction
62
+ });
63
+ for (const route of routes) {
64
+ const routeId = route.get("id");
65
+ if (routeId === null || routeId === void 0) {
66
+ continue;
67
+ }
68
+ if (hasRelationRecords(route, "uiLayouts")) {
69
+ continue;
70
+ }
71
+ if (hasMultiPortalRelation && hasRelationRecords(route, "multiPortals")) {
72
+ continue;
73
+ }
74
+ await db.getRepository("desktopRoutes.uiLayouts", routeId).set({
75
+ tk: [import_constants.DEFAULT_ADMIN_UI_LAYOUT.uid],
76
+ transaction
77
+ });
78
+ }
79
+ }
80
+ async function backfillAdminLayoutDesktopRoutes(db) {
81
+ await db.sequelize.transaction(async (transaction) => {
82
+ await backfillAdminLayoutDesktopRoutesInTransaction(db, transaction);
83
+ });
84
+ }
85
+ class backfill_admin_layout_desktop_routes_default extends import_server.Migration {
86
+ on = "afterSync";
87
+ async up() {
88
+ await backfillAdminLayoutDesktopRoutes(this.db);
89
+ }
90
+ }
91
+ // Annotate the CommonJS export names for ESM import in node:
92
+ 0 && (module.exports = {
93
+ backfillAdminLayoutDesktopRoutes
94
+ });
@@ -0,0 +1,19 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+ import { Plugin } from '@nocobase/server';
10
+ export declare class PluginUiLayoutServer extends Plugin {
11
+ afterAdd(): Promise<void>;
12
+ beforeLoad(): Promise<void>;
13
+ load(): Promise<void>;
14
+ install(): Promise<void>;
15
+ afterEnable(): Promise<void>;
16
+ afterDisable(): Promise<void>;
17
+ remove(): Promise<void>;
18
+ }
19
+ export default PluginUiLayoutServer;