@nocobase/plugin-block-template 1.6.0-alpha.29
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.
- package/LICENSE.txt +161 -0
- package/README.md +1 -0
- package/client.d.ts +2 -0
- package/client.js +1 -0
- package/dist/client/collections/blockTemplates.d.ts +46 -0
- package/dist/client/components/AddNewTemplate.d.ts +3 -0
- package/dist/client/components/BlockTemplateInfoContext.d.ts +11 -0
- package/dist/client/components/BlockTemplateList.d.ts +10 -0
- package/dist/client/components/BlockTemplateMenusProvider.d.ts +22 -0
- package/dist/client/components/BlockTemplateMobilePage.d.ts +10 -0
- package/dist/client/components/BlockTemplatePage.d.ts +10 -0
- package/dist/client/components/ConfigureLink.d.ts +10 -0
- package/dist/client/components/DisabledDeleteItem.d.ts +10 -0
- package/dist/client/components/RevertSetting.d.ts +10 -0
- package/dist/client/components/TemplateGridDecorator.d.ts +10 -0
- package/dist/client/components/index.d.ts +17 -0
- package/dist/client/constants.d.ts +11 -0
- package/dist/client/hooks/index.d.ts +14 -0
- package/dist/client/hooks/useBulkDestroyAction.d.ts +11 -0
- package/dist/client/hooks/useCreateActionProps.d.ts +12 -0
- package/dist/client/hooks/useDeleteAction.d.ts +11 -0
- package/dist/client/hooks/useDuplicateAction.d.ts +11 -0
- package/dist/client/hooks/useEditActionProps.d.ts +12 -0
- package/dist/client/hooks/useEditFormProps.d.ts +11 -0
- package/dist/client/hooks/useIsInTemplate.d.ts +16 -0
- package/dist/client/index.d.ts +25 -0
- package/dist/client/index.js +10 -0
- package/dist/client/initializers/TemplateBlockInitializer.d.ts +16 -0
- package/dist/client/initializers/index.d.ts +10 -0
- package/dist/client/initializers/templateBlockInitializerItem.d.ts +10 -0
- package/dist/client/locale.d.ts +10 -0
- package/dist/client/schemas/blockTemplates.d.ts +10 -0
- package/dist/client/schemas/bulkDestroySchema.d.ts +61 -0
- package/dist/client/schemas/createActionSchema.d.ts +70 -0
- package/dist/client/schemas/editActionSchema.d.ts +66 -0
- package/dist/client/schemas/index.d.ts +12 -0
- package/dist/client/settings/disabledDeleteSetting.d.ts +15 -0
- package/dist/client/settings/revertSetting.d.ts +15 -0
- package/dist/client/utils/interceptors.d.ts +15 -0
- package/dist/client/utils/schema.d.ts +21 -0
- package/dist/client/utils/setting.d.ts +13 -0
- package/dist/client/utils/template.d.ts +50 -0
- package/dist/externalVersion.js +30 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +48 -0
- package/dist/locale/en-US.json +37 -0
- package/dist/locale/zh-CN.json +37 -0
- package/dist/server/actions/destroy.d.ts +10 -0
- package/dist/server/actions/destroy.js +137 -0
- package/dist/server/actions/index.d.ts +11 -0
- package/dist/server/actions/index.js +34 -0
- package/dist/server/actions/link.d.ts +10 -0
- package/dist/server/actions/link.js +43 -0
- package/dist/server/actions/saveSchema.d.ts +10 -0
- package/dist/server/actions/saveSchema.js +46 -0
- package/dist/server/collections/blockTemplateLinks.d.ts +2 -0
- package/dist/server/collections/blockTemplateLinks.js +56 -0
- package/dist/server/collections/blockTemplates.d.ts +10 -0
- package/dist/server/collections/blockTemplates.js +91 -0
- package/dist/server/index.d.ts +9 -0
- package/dist/server/index.js +42 -0
- package/dist/server/middlewares/templateData.d.ts +17 -0
- package/dist/server/middlewares/templateData.js +122 -0
- package/dist/server/plugin.d.ts +18 -0
- package/dist/server/plugin.js +59 -0
- package/dist/server/utils/index.d.ts +1 -0
- package/dist/server/utils/index.js +30 -0
- package/dist/server/utils/template.d.ts +13 -0
- package/dist/server/utils/template.js +392 -0
- package/package.json +23 -0
- package/server.d.ts +2 -0
- package/server.js +1 -0
|
@@ -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,17 @@
|
|
|
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 { Context } from '@nocobase/actions';
|
|
10
|
+
/**
|
|
11
|
+
* Template data middleware
|
|
12
|
+
* Handles UI Schema related requests and fills template data
|
|
13
|
+
*
|
|
14
|
+
* @param ctx - Context object containing request and response information
|
|
15
|
+
* @param next - Next middleware function
|
|
16
|
+
*/
|
|
17
|
+
export declare function templateDataMiddleware(ctx: Context, next: any): Promise<void>;
|
|
@@ -0,0 +1,122 @@
|
|
|
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 templateData_exports = {};
|
|
38
|
+
__export(templateData_exports, {
|
|
39
|
+
templateDataMiddleware: () => templateDataMiddleware
|
|
40
|
+
});
|
|
41
|
+
module.exports = __toCommonJS(templateData_exports);
|
|
42
|
+
var import_lodash = __toESM(require("lodash"));
|
|
43
|
+
var import_template = require("../utils/template");
|
|
44
|
+
async function templateDataMiddleware(ctx, next) {
|
|
45
|
+
await next();
|
|
46
|
+
if (ctx.action.resourceName === "uiSchemas" && ["getProperties", "getJsonSchema", "getParentJsonSchema"].includes(ctx.action.actionName)) {
|
|
47
|
+
const schema = ctx.body;
|
|
48
|
+
const schemaRepository = ctx.db.getRepository("uiSchemas");
|
|
49
|
+
const blockTemplateRepository = ctx.db.getRepository("blockTemplates");
|
|
50
|
+
await convertTemplateRootRefToUid(schema, schemaRepository);
|
|
51
|
+
await fillTemplateData(schema, schemaRepository, blockTemplateRepository).catch((e) => {
|
|
52
|
+
ctx.logger.error(e);
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
async function convertTemplateRootRefToUid(schema, schemaRepository) {
|
|
57
|
+
if (schema == null ? void 0 : schema["x-template-root-ref"]) {
|
|
58
|
+
const rootParentUid = schema["x-template-root-ref"]["x-template-uid"];
|
|
59
|
+
const rootParentSchema = await schemaRepository.getJsonSchema(rootParentUid, { readFromCache: true });
|
|
60
|
+
const templateRootUid = import_lodash.default.get(rootParentSchema, schema["x-template-root-ref"]["x-path"]);
|
|
61
|
+
if (templateRootUid) {
|
|
62
|
+
schema["x-template-root-uid"] = templateRootUid;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
async function fillTemplateData(schema, schemaRepository, blockTemplateRepository) {
|
|
67
|
+
const [uids, keys] = collectBlockTemplateData(schema);
|
|
68
|
+
if (uids.size > 0) {
|
|
69
|
+
schema["x-template-schemas"] = {};
|
|
70
|
+
}
|
|
71
|
+
if (keys.size > 0) {
|
|
72
|
+
schema["x-template-infos"] = {};
|
|
73
|
+
}
|
|
74
|
+
if (!schema["x-template-root-uid"] && schema["x-template-uid"]) {
|
|
75
|
+
const template = await schemaRepository.getJsonSchema(schema["x-template-uid"], {
|
|
76
|
+
includeAsyncNode: true,
|
|
77
|
+
readFromCache: true
|
|
78
|
+
});
|
|
79
|
+
const newSchema = (0, import_template.mergeSchema)(template, schema, import_lodash.default.cloneDeep(template));
|
|
80
|
+
(0, import_template.cleanSchema)(newSchema, schema["x-template-uid"]);
|
|
81
|
+
import_lodash.default.merge(schema, newSchema);
|
|
82
|
+
}
|
|
83
|
+
const chunkSize = 5;
|
|
84
|
+
const uidChunks = import_lodash.default.chunk(Array.from(uids), chunkSize);
|
|
85
|
+
for (const uidChunk of uidChunks) {
|
|
86
|
+
const batchResults = await Promise.all(
|
|
87
|
+
uidChunk.map(
|
|
88
|
+
(uid) => schemaRepository.getJsonSchema(uid, { readFromCache: true }).then((templateSchema) => [uid, templateSchema])
|
|
89
|
+
)
|
|
90
|
+
);
|
|
91
|
+
for (const [uid, templateSchema] of batchResults) {
|
|
92
|
+
schema["x-template-schemas"][uid] = templateSchema;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
const templates = await blockTemplateRepository.find({
|
|
96
|
+
filter: {
|
|
97
|
+
key: { $in: Array.from(keys) }
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
for (const template of templates) {
|
|
101
|
+
schema["x-template-infos"][template.key] = template;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
function collectBlockTemplateData(schema, data = [/* @__PURE__ */ new Set(), /* @__PURE__ */ new Set()]) {
|
|
105
|
+
if (schema == null ? void 0 : schema["x-template-root-uid"]) {
|
|
106
|
+
data[0].add(schema["x-template-root-uid"]);
|
|
107
|
+
}
|
|
108
|
+
if (schema == null ? void 0 : schema["x-block-template-key"]) {
|
|
109
|
+
data[1].add(schema["x-block-template-key"]);
|
|
110
|
+
}
|
|
111
|
+
if (!(schema == null ? void 0 : schema.properties)) {
|
|
112
|
+
return data;
|
|
113
|
+
}
|
|
114
|
+
for (const property of Object.values(schema.properties)) {
|
|
115
|
+
collectBlockTemplateData(property, data);
|
|
116
|
+
}
|
|
117
|
+
return data;
|
|
118
|
+
}
|
|
119
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
120
|
+
0 && (module.exports = {
|
|
121
|
+
templateDataMiddleware
|
|
122
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
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 PluginBlockTemplateServer extends Plugin {
|
|
11
|
+
beforeLoad(): void;
|
|
12
|
+
load(): Promise<void>;
|
|
13
|
+
install(): Promise<void>;
|
|
14
|
+
afterEnable(): Promise<void>;
|
|
15
|
+
afterDisable(): Promise<void>;
|
|
16
|
+
remove(): Promise<void>;
|
|
17
|
+
}
|
|
18
|
+
export default PluginBlockTemplateServer;
|
|
@@ -0,0 +1,59 @@
|
|
|
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 plugin_exports = {};
|
|
28
|
+
__export(plugin_exports, {
|
|
29
|
+
PluginBlockTemplateServer: () => PluginBlockTemplateServer,
|
|
30
|
+
default: () => plugin_default
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(plugin_exports);
|
|
33
|
+
var import_server = require("@nocobase/server");
|
|
34
|
+
var import_actions = require("./actions");
|
|
35
|
+
var import_templateData = require("./middlewares/templateData");
|
|
36
|
+
class PluginBlockTemplateServer extends import_server.Plugin {
|
|
37
|
+
beforeLoad() {
|
|
38
|
+
this.app.acl.allow("blockTemplates", "*", "loggedIn");
|
|
39
|
+
this.app.resourceManager.registerActionHandler("blockTemplates:destroy", import_actions.destroy);
|
|
40
|
+
this.app.resourceManager.registerActionHandler("blockTemplates:link", import_actions.link);
|
|
41
|
+
this.app.resourceManager.registerActionHandler("blockTemplates:saveSchema", import_actions.saveSchema);
|
|
42
|
+
this.app.resourceManager.use(import_templateData.templateDataMiddleware);
|
|
43
|
+
}
|
|
44
|
+
async load() {
|
|
45
|
+
}
|
|
46
|
+
async install() {
|
|
47
|
+
}
|
|
48
|
+
async afterEnable() {
|
|
49
|
+
}
|
|
50
|
+
async afterDisable() {
|
|
51
|
+
}
|
|
52
|
+
async remove() {
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
var plugin_default = PluginBlockTemplateServer;
|
|
56
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
57
|
+
0 && (module.exports = {
|
|
58
|
+
PluginBlockTemplateServer
|
|
59
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './template';
|
|
@@ -0,0 +1,30 @@
|
|
|
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 __copyProps = (to, from, except, desc) => {
|
|
15
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
16
|
+
for (let key of __getOwnPropNames(from))
|
|
17
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
18
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
23
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
24
|
+
var utils_exports = {};
|
|
25
|
+
module.exports = __toCommonJS(utils_exports);
|
|
26
|
+
__reExport(utils_exports, require("./template"), module.exports);
|
|
27
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
28
|
+
0 && (module.exports = {
|
|
29
|
+
...require("./template")
|
|
30
|
+
});
|
|
@@ -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 { Database, Transaction } from '@nocobase/database';
|
|
10
|
+
import { Schema } from '@nocobase/utils';
|
|
11
|
+
export declare function getNewFullBlock(db: Database, transaction: Transaction, blockUid: string): Promise<any>;
|
|
12
|
+
export declare function mergeSchema(template: any, schema: any, rootTemplate: any): any;
|
|
13
|
+
export declare function cleanSchema(schema?: Schema, templateId?: string): void;
|