@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,392 @@
|
|
|
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 template_exports = {};
|
|
38
|
+
__export(template_exports, {
|
|
39
|
+
cleanSchema: () => cleanSchema,
|
|
40
|
+
getNewFullBlock: () => getNewFullBlock,
|
|
41
|
+
mergeSchema: () => mergeSchema
|
|
42
|
+
});
|
|
43
|
+
module.exports = __toCommonJS(template_exports);
|
|
44
|
+
var import_utils = require("@nocobase/utils");
|
|
45
|
+
var import_lodash = __toESM(require("lodash"));
|
|
46
|
+
async function getNewFullBlock(db, transaction, blockUid) {
|
|
47
|
+
const repository = db.getRepository("uiSchemas");
|
|
48
|
+
const block = await repository.getJsonSchema(blockUid, {
|
|
49
|
+
includeAsyncNode: true,
|
|
50
|
+
readFromCache: true,
|
|
51
|
+
transaction
|
|
52
|
+
});
|
|
53
|
+
const templateId = block["x-template-root-uid"];
|
|
54
|
+
if (!templateId) {
|
|
55
|
+
return block;
|
|
56
|
+
}
|
|
57
|
+
const template = await repository.getJsonSchema(templateId, {
|
|
58
|
+
includeAsyncNode: true,
|
|
59
|
+
readFromCache: true,
|
|
60
|
+
transaction
|
|
61
|
+
});
|
|
62
|
+
const newSchema = mergeSchema(template, block, import_lodash.default.cloneDeep(template));
|
|
63
|
+
cleanSchema(newSchema, templateId);
|
|
64
|
+
return newSchema;
|
|
65
|
+
}
|
|
66
|
+
function getNewObjectValue(itemsMap) {
|
|
67
|
+
const remainingTemplateItems = { properties: {} };
|
|
68
|
+
for (const [_uid, item] of itemsMap.entries()) {
|
|
69
|
+
let current = remainingTemplateItems;
|
|
70
|
+
for (const pathItem of item.path.slice(1)) {
|
|
71
|
+
if (!current.properties) {
|
|
72
|
+
current.properties = {};
|
|
73
|
+
}
|
|
74
|
+
if (!current.properties[pathItem.key]) {
|
|
75
|
+
current.properties[pathItem.key] = {
|
|
76
|
+
...pathItem.schema,
|
|
77
|
+
properties: {}
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
current = current.properties[pathItem.key];
|
|
81
|
+
}
|
|
82
|
+
current.properties = current.properties || {};
|
|
83
|
+
current.properties[item.key] = item.schema;
|
|
84
|
+
}
|
|
85
|
+
return remainingTemplateItems.properties;
|
|
86
|
+
}
|
|
87
|
+
const NestedGridComponents = ["Grid", "Grid.Row", "Grid.Col"];
|
|
88
|
+
function collectGridItems(schema, itemsMap, parentPath = [], schemaKey) {
|
|
89
|
+
const properties = schema.properties || {};
|
|
90
|
+
const component = schema["x-component"];
|
|
91
|
+
if (NestedGridComponents.includes(component)) {
|
|
92
|
+
parentPath = [
|
|
93
|
+
...parentPath,
|
|
94
|
+
{
|
|
95
|
+
schema,
|
|
96
|
+
type: component,
|
|
97
|
+
key: schemaKey || ""
|
|
98
|
+
}
|
|
99
|
+
];
|
|
100
|
+
}
|
|
101
|
+
for (const [key, property] of Object.entries(properties)) {
|
|
102
|
+
if (!property) continue;
|
|
103
|
+
const propertyComponent = property["x-component"];
|
|
104
|
+
if (NestedGridComponents.includes(propertyComponent)) {
|
|
105
|
+
collectGridItems(property, itemsMap, parentPath, key);
|
|
106
|
+
} else if (property["x-uid"]) {
|
|
107
|
+
itemsMap.set(property["x-uid"], {
|
|
108
|
+
schema: property,
|
|
109
|
+
path: parentPath,
|
|
110
|
+
key
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
function mergeSchema(template, schema, rootTemplate) {
|
|
116
|
+
if (template["properties"] && !schema["properties"]) {
|
|
117
|
+
schema["properties"] = {};
|
|
118
|
+
}
|
|
119
|
+
return import_lodash.default.mergeWith(
|
|
120
|
+
template,
|
|
121
|
+
schema,
|
|
122
|
+
(objectValue, sourceValue, keyName, object, source) => {
|
|
123
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
124
|
+
if (sourceValue == null) {
|
|
125
|
+
return objectValue;
|
|
126
|
+
}
|
|
127
|
+
if (keyName === "default" && object["x-settings"] === "actionSettings:filter") {
|
|
128
|
+
return sourceValue || objectValue;
|
|
129
|
+
}
|
|
130
|
+
if (import_lodash.default.isObject(sourceValue)) {
|
|
131
|
+
if (import_lodash.default.isArray(sourceValue)) {
|
|
132
|
+
return sourceValue || objectValue;
|
|
133
|
+
}
|
|
134
|
+
if (keyName === "properties") {
|
|
135
|
+
const sourceKeys = Object.keys(sourceValue);
|
|
136
|
+
let targetKeys = Object.keys(objectValue || {});
|
|
137
|
+
if (NestedGridComponents.includes(source["x-component"]) && NestedGridComponents.includes(object["x-component"])) {
|
|
138
|
+
const tItemsMap = /* @__PURE__ */ new Map();
|
|
139
|
+
const sItemsMap = /* @__PURE__ */ new Map();
|
|
140
|
+
collectGridItems(object, tItemsMap);
|
|
141
|
+
collectGridItems(source, sItemsMap);
|
|
142
|
+
for (const [uid2, sourceItem] of sItemsMap.entries()) {
|
|
143
|
+
if (!sourceItem.schema["x-template-uid"]) continue;
|
|
144
|
+
const templateItem = tItemsMap.get(sourceItem.schema["x-template-uid"]);
|
|
145
|
+
if (templateItem) {
|
|
146
|
+
const mergedSchema = mergeSchema(templateItem.schema || {}, sourceItem.schema, rootTemplate);
|
|
147
|
+
sourceItem.path[sourceItem.path.length - 1].schema.properties[sourceItem.key] = mergedSchema;
|
|
148
|
+
sourceItem.schema = mergedSchema;
|
|
149
|
+
tItemsMap.delete(sourceItem.schema["x-template-uid"]);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
objectValue = getNewObjectValue(tItemsMap);
|
|
153
|
+
object["properties"] = objectValue;
|
|
154
|
+
targetKeys = Object.keys(objectValue);
|
|
155
|
+
}
|
|
156
|
+
if (object["x-component"] === "CollectionField") {
|
|
157
|
+
for (const skey of sourceKeys) {
|
|
158
|
+
const assFieldCom = (_a = sourceValue[skey]) == null ? void 0 : _a["x-component"];
|
|
159
|
+
if ([
|
|
160
|
+
"Action.Container",
|
|
161
|
+
"AssociationField.Viewer",
|
|
162
|
+
"AssociationField.Selector",
|
|
163
|
+
"AssociationField.Nester",
|
|
164
|
+
"AssociationField.SubTable"
|
|
165
|
+
].includes(assFieldCom)) {
|
|
166
|
+
const tkey = targetKeys.find((k) => objectValue[k]["x-component"] === assFieldCom);
|
|
167
|
+
if (tkey) {
|
|
168
|
+
sourceValue[skey]["x-template-uid"] = objectValue[tkey]["x-uid"];
|
|
169
|
+
sourceValue[skey] = mergeSchema(objectValue[tkey] || {}, sourceValue[skey], rootTemplate);
|
|
170
|
+
targetKeys = targetKeys.filter((k) => k !== tkey);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
if (/:configure.*Actions/.test(object["x-initializer"])) {
|
|
176
|
+
for (const skey of sourceKeys) {
|
|
177
|
+
if (object["x-initializer"] === "filterForm:configureActions") {
|
|
178
|
+
const sourceUseComponentProps = (_b = sourceValue[skey]) == null ? void 0 : _b["x-use-component-props"];
|
|
179
|
+
if (sourceUseComponentProps && ["useFilterBlockActionProps", "useResetBlockActionProps"].includes(sourceUseComponentProps)) {
|
|
180
|
+
const removedTargetKeys = import_lodash.default.remove(targetKeys, (key) => {
|
|
181
|
+
var _a2;
|
|
182
|
+
const targetUseComponentProps = (_a2 = objectValue[key]) == null ? void 0 : _a2["x-use-component-props"];
|
|
183
|
+
return sourceUseComponentProps === targetUseComponentProps;
|
|
184
|
+
});
|
|
185
|
+
if (removedTargetKeys.length > 0) {
|
|
186
|
+
sourceValue[skey]["x-template-uid"] = objectValue[removedTargetKeys[0]]["x-uid"];
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
if (((_c = sourceValue[skey]) == null ? void 0 : _c["x-component"]) && ((_e = (_d = sourceValue[skey]) == null ? void 0 : _d["x-settings"]) == null ? void 0 : _e.includes("actionSettings"))) {
|
|
191
|
+
const actionName = sourceValue[skey]["x-settings"].split(":")[1];
|
|
192
|
+
const targetActionName = [
|
|
193
|
+
"bulkDelete",
|
|
194
|
+
"filter",
|
|
195
|
+
"refresh",
|
|
196
|
+
"delete",
|
|
197
|
+
"print",
|
|
198
|
+
"stepsFormNext",
|
|
199
|
+
"stepsFormPrevious",
|
|
200
|
+
"disassociate",
|
|
201
|
+
"MailSend",
|
|
202
|
+
"MailRefresh",
|
|
203
|
+
"MailAccountSetting",
|
|
204
|
+
"MailMarkAsRead",
|
|
205
|
+
"MailMarkAsUnRead"
|
|
206
|
+
].find((name) => name === actionName);
|
|
207
|
+
if (targetActionName) {
|
|
208
|
+
const removedTargetKeys = import_lodash.default.remove(
|
|
209
|
+
targetKeys,
|
|
210
|
+
(key) => {
|
|
211
|
+
var _a2;
|
|
212
|
+
return ((_a2 = objectValue[key]) == null ? void 0 : _a2["x-settings"]) === `actionSettings:${targetActionName}`;
|
|
213
|
+
}
|
|
214
|
+
);
|
|
215
|
+
if (removedTargetKeys.length > 0) {
|
|
216
|
+
sourceValue[skey]["x-template-uid"] = objectValue[removedTargetKeys[0]]["x-uid"];
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
for (const skey of sourceKeys) {
|
|
223
|
+
if ((_f = object["x-initializer"]) == null ? void 0 : _f.includes(":configureColumns")) {
|
|
224
|
+
if (sourceValue[skey]["x-component"] && sourceValue[skey]["x-settings"] === "fieldSettings:TableColumn") {
|
|
225
|
+
const sourceColFieldSchema = Object.values(((_g = sourceValue[skey]) == null ? void 0 : _g["properties"]) || {})[0];
|
|
226
|
+
const xColField = import_lodash.default.get(sourceColFieldSchema, "x-collection-field");
|
|
227
|
+
if (xColField) {
|
|
228
|
+
let targetColFieldSchema = null;
|
|
229
|
+
const removedTargetKeys = import_lodash.default.remove(targetKeys, (key) => {
|
|
230
|
+
var _a2;
|
|
231
|
+
targetColFieldSchema = Object.values(((_a2 = objectValue[key]) == null ? void 0 : _a2["properties"]) || {})[0];
|
|
232
|
+
const targetColField = import_lodash.default.get(targetColFieldSchema, "x-collection-field");
|
|
233
|
+
return xColField === targetColField;
|
|
234
|
+
});
|
|
235
|
+
if (removedTargetKeys.length > 0) {
|
|
236
|
+
sourceValue[skey]["x-template-uid"] = objectValue[removedTargetKeys[0]]["x-uid"];
|
|
237
|
+
sourceColFieldSchema["x-template-uid"] = targetColFieldSchema == null ? void 0 : targetColFieldSchema["x-uid"];
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
if ((_h = sourceValue[skey]["x-initializer"]) == null ? void 0 : _h.includes(":configureItemActions")) {
|
|
242
|
+
const removedTargetKeys = import_lodash.default.remove(targetKeys, (key) => {
|
|
243
|
+
var _a2, _b2;
|
|
244
|
+
return (_b2 = (_a2 = objectValue[key]) == null ? void 0 : _a2["x-initializer"]) == null ? void 0 : _b2.includes(":configureItemActions");
|
|
245
|
+
});
|
|
246
|
+
if (removedTargetKeys.length > 0) {
|
|
247
|
+
sourceValue[skey]["x-template-uid"] = objectValue[removedTargetKeys[0]]["x-uid"];
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
if (/:configureFields/.test(source["x-initializer"])) {
|
|
253
|
+
const targetFieldsMap = /* @__PURE__ */ new Map();
|
|
254
|
+
collectGridItems(object, targetFieldsMap);
|
|
255
|
+
const targetFields = Array.from(targetFieldsMap.values());
|
|
256
|
+
for (const skey of sourceKeys) {
|
|
257
|
+
const sourceFieldsMap = /* @__PURE__ */ new Map();
|
|
258
|
+
collectGridItems(sourceValue[skey], sourceFieldsMap);
|
|
259
|
+
for (const [uid2, sourceItem] of sourceFieldsMap.entries()) {
|
|
260
|
+
const xColField = import_lodash.default.get(sourceItem.schema, "x-collection-field");
|
|
261
|
+
if (!xColField) continue;
|
|
262
|
+
const targetItem = import_lodash.default.find(targetFields, (field) => field.schema["x-collection-field"] === xColField);
|
|
263
|
+
if (targetItem) {
|
|
264
|
+
targetFieldsMap.delete(targetItem.schema["x-uid"]);
|
|
265
|
+
sourceItem.schema["x-template-uid"] = targetItem.schema["x-uid"];
|
|
266
|
+
sourceItem.schema = mergeSchema(targetItem.schema || {}, sourceItem.schema, rootTemplate);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
objectValue = getNewObjectValue(targetFieldsMap);
|
|
270
|
+
object["properties"] = objectValue;
|
|
271
|
+
targetKeys = Object.keys(objectValue);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
if (object["x-decorator"] === "DndContext") {
|
|
275
|
+
for (const skey of sourceKeys) {
|
|
276
|
+
const actionSettings = sourceValue[skey]["x-settings"];
|
|
277
|
+
if (sourceValue[skey]["x-component"] && ["actionSettings:disassociate", "actionSettings:delete"].includes(actionSettings)) {
|
|
278
|
+
const removedTargetKeys = import_lodash.default.remove(targetKeys, (key) => {
|
|
279
|
+
var _a2;
|
|
280
|
+
return ((_a2 = objectValue[key]) == null ? void 0 : _a2["x-settings"]) === actionSettings;
|
|
281
|
+
});
|
|
282
|
+
if (removedTargetKeys.length > 0) {
|
|
283
|
+
sourceValue[skey]["x-template-uid"] = objectValue[removedTargetKeys[0]]["x-uid"];
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
const keys = import_lodash.default.union(targetKeys, sourceKeys);
|
|
289
|
+
const newKeys = import_lodash.default.difference(targetKeys, sourceKeys);
|
|
290
|
+
if (newKeys.length > 0) {
|
|
291
|
+
const newProperties = import_lodash.default.cloneDeep(import_lodash.default.pick(objectValue, newKeys));
|
|
292
|
+
const newSchemas = [];
|
|
293
|
+
for (const key of newKeys) {
|
|
294
|
+
const newSchema = convertTplBlock(newProperties[key]);
|
|
295
|
+
newSchema["name"] = key;
|
|
296
|
+
newSchemas.push(newSchema);
|
|
297
|
+
source["properties"][key] = newSchema;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
const properties = {};
|
|
301
|
+
for (let i = 0; i < keys.length; i++) {
|
|
302
|
+
const k = keys[i];
|
|
303
|
+
const sourceProperty = (sourceValue == null ? void 0 : sourceValue[k]) || {};
|
|
304
|
+
if (import_lodash.default.get(objectValue, [k, "properties"])) {
|
|
305
|
+
sourceProperty["properties"] = sourceProperty["properties"] || {};
|
|
306
|
+
}
|
|
307
|
+
properties[k] = mergeSchema((objectValue == null ? void 0 : objectValue[k]) || {}, sourceValue == null ? void 0 : sourceValue[k], rootTemplate);
|
|
308
|
+
if (properties[k]["x-template-root-uid"] && properties[k]["x-template-root-uid"] === rootTemplate["x-uid"]) {
|
|
309
|
+
properties[k] = mergeSchema(import_lodash.default.cloneDeep(rootTemplate), properties[k], rootTemplate);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
const parentIndexs = [];
|
|
313
|
+
for (const key in properties) {
|
|
314
|
+
if (properties[key]["x-index"]) {
|
|
315
|
+
const xIndex = properties[key]["x-index"];
|
|
316
|
+
if (parentIndexs.includes(xIndex)) {
|
|
317
|
+
properties[key]["x-index"] = Math.max(...parentIndexs) + 1;
|
|
318
|
+
}
|
|
319
|
+
parentIndexs.push(properties[key]["x-index"]);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
return properties;
|
|
323
|
+
}
|
|
324
|
+
return mergeSchema(objectValue || {}, sourceValue || {}, rootTemplate);
|
|
325
|
+
}
|
|
326
|
+
return sourceValue;
|
|
327
|
+
}
|
|
328
|
+
);
|
|
329
|
+
}
|
|
330
|
+
function shouldDeleteNoComponentSchema(schema) {
|
|
331
|
+
if (!schema["x-no-component"]) {
|
|
332
|
+
return true;
|
|
333
|
+
}
|
|
334
|
+
const properties = schema == null ? void 0 : schema.properties;
|
|
335
|
+
return properties && Object.values(properties).some((s) => s["x-component"] === void 0);
|
|
336
|
+
}
|
|
337
|
+
function cleanSchema(schema, templateId) {
|
|
338
|
+
var _a, _b;
|
|
339
|
+
const properties = (schema == null ? void 0 : schema.properties) || {};
|
|
340
|
+
if (schema) {
|
|
341
|
+
delete schema["x-template-root-uid"];
|
|
342
|
+
delete schema["x-template-uid"];
|
|
343
|
+
delete schema["x-block-template-key"];
|
|
344
|
+
delete schema["x-virtual"];
|
|
345
|
+
delete schema["x-template-version"];
|
|
346
|
+
}
|
|
347
|
+
for (const key of Object.keys(properties)) {
|
|
348
|
+
if (schema.properties[key]["x-component"] === void 0 && !schema.properties[key]["x-template-root-uid"] && shouldDeleteNoComponentSchema(schema.properties[key])) {
|
|
349
|
+
delete schema.properties[key];
|
|
350
|
+
continue;
|
|
351
|
+
}
|
|
352
|
+
if (schema.properties[key]["x-template-root-uid"] && schema.properties[key]["x-template-root-uid"] !== templateId) {
|
|
353
|
+
continue;
|
|
354
|
+
}
|
|
355
|
+
if (((_a = properties[key]) == null ? void 0 : _a["x-component"]) === "Grid.Row") {
|
|
356
|
+
let hasProperties = false;
|
|
357
|
+
const cols = Object.values(((_b = properties[key]) == null ? void 0 : _b["properties"]) || {});
|
|
358
|
+
for (const col of cols) {
|
|
359
|
+
if (col["x-component"] === "Grid.Col") {
|
|
360
|
+
if (!import_lodash.default.isEmpty(col["properties"])) {
|
|
361
|
+
hasProperties = true;
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
if (!hasProperties) {
|
|
366
|
+
delete properties[key];
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
cleanSchema(properties[key], templateId);
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
function convertTplBlock(tpl) {
|
|
373
|
+
const newSchema = import_lodash.default.cloneDeep(tpl);
|
|
374
|
+
const regeneratedUid = (schema) => {
|
|
375
|
+
if (schema["x-uid"]) {
|
|
376
|
+
schema["x-uid"] = (0, import_utils.uid)();
|
|
377
|
+
}
|
|
378
|
+
if (schema["properties"]) {
|
|
379
|
+
for (const key in schema["properties"]) {
|
|
380
|
+
regeneratedUid(schema["properties"][key]);
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
};
|
|
384
|
+
regeneratedUid(newSchema);
|
|
385
|
+
return newSchema;
|
|
386
|
+
}
|
|
387
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
388
|
+
0 && (module.exports = {
|
|
389
|
+
cleanSchema,
|
|
390
|
+
getNewFullBlock,
|
|
391
|
+
mergeSchema
|
|
392
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nocobase/plugin-block-template",
|
|
3
|
+
"displayName": "Block: template",
|
|
4
|
+
"displayName.zh-CN": "区块:模板",
|
|
5
|
+
"description": "Create and manage block templates for reuse on pages.",
|
|
6
|
+
"description.zh-CN": "创建和管理区块模板,用于在页面中重复使用。",
|
|
7
|
+
"version": "1.6.0-alpha.29",
|
|
8
|
+
"license": "AGPL-3.0",
|
|
9
|
+
"main": "dist/server/index.js",
|
|
10
|
+
"homepage": "https://docs.nocobase.com/handbook/block-template",
|
|
11
|
+
"homepage.zh-CN": "https://docs-cn.nocobase.com/handbook/block-template",
|
|
12
|
+
"peerDependencies": {
|
|
13
|
+
"@nocobase/client": "1.x",
|
|
14
|
+
"@nocobase/plugin-ui-schema-storage": "1.x",
|
|
15
|
+
"@nocobase/server": "1.x",
|
|
16
|
+
"@nocobase/test": "1.x"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"Block",
|
|
20
|
+
"Template"
|
|
21
|
+
],
|
|
22
|
+
"gitHead": "cf6045d1691f62f308607d6682ffd37c430f8f19"
|
|
23
|
+
}
|
package/server.d.ts
ADDED
package/server.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('./dist/server/index.js');
|