@nocobase/plugin-ui-schema-storage 1.7.0-beta.9 → 1.8.0-beta.1

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.
@@ -7,4 +7,4 @@
7
7
  * For more information, please refer to: https://www.nocobase.com/agreement.
8
8
  */
9
9
 
10
- !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("@nocobase/client")):"function"==typeof define&&define.amd?define("@nocobase/plugin-ui-schema-storage",["@nocobase/client"],t):"object"==typeof exports?exports["@nocobase/plugin-ui-schema-storage"]=t(require("@nocobase/client")):e["@nocobase/plugin-ui-schema-storage"]=t(e["@nocobase/client"])}(self,function(e){return function(){"use strict";var t={772:function(t){t.exports=e}},n={};function r(e){var o=n[e];if(void 0!==o)return o.exports;var u=n[e]={exports:{}};return t[e](u,u.exports,r),u.exports}r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,{a:t}),t},r.d=function(e,t){for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var o={};r.r(o);var u=r(772);function i(e,t,n,r,o,u,i){try{var c=e[u](i),a=c.value}catch(e){n(e);return}c.done?t(a):Promise.resolve(a).then(r,o)}function c(e,t,n){return(c=s()?Reflect.construct:function(e,t,n){var r=[null];r.push.apply(r,t);var o=new(Function.bind.apply(e,r));return n&&l(o,n.prototype),o}).apply(null,arguments)}function a(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function f(e){return(f=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function l(e,t){return(l=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function p(e){var t="function"==typeof Map?new Map:void 0;return(p=function(e){var n;if(null===e||(n=e,-1===Function.toString.call(n).indexOf("[native code]")))return e;if("function"!=typeof e)throw TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,r)}function r(){return c(e,arguments,f(this).constructor)}return r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),l(r,e)})(e)}function s(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(s=function(){return!!e})()}var b=function(e){var t,n,r;function o(){var e,t,n;return!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,o),e=this,t=o,n=arguments,t=f(t),function(e,t){return t&&("object"===function(e){return e&&"undefined"!=typeof Symbol&&e.constructor===Symbol?"symbol":typeof e}(t)||"function"==typeof t)?t:function(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(e,s()?Reflect.construct(t,n||[],f(e).constructor):t.apply(e,n))}return!function(e,t){if("function"!=typeof t&&null!==t)throw TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&l(e,t)}(o,e),t=o,n=[{key:"load",value:function(){var e;return(e=function(){return function(e,t){var n,r,o,u,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return u={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(u[Symbol.iterator]=function(){return this}),u;function c(u){return function(c){return function(u){if(n)throw TypeError("Generator is already executing.");for(;i;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return i.label++,{value:u[1],done:!1};case 5:i.label++,r=u[1],u=[0];continue;case 7:u=i.ops.pop(),i.trys.pop();continue;default:if(!(o=(o=i.trys).length>0&&o[o.length-1])&&(6===u[0]||2===u[0])){i=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){i.label=u[1];break}if(6===u[0]&&i.label<o[1]){i.label=o[1],o=u;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(u);break}o[2]&&i.ops.pop(),i.trys.pop();continue}u=t.call(e,i)}catch(e){u=[6,e],r=0}finally{n=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,c])}}}(this,function(e){return[2]})},function(){var t=this,n=arguments;return new Promise(function(r,o){var u=e.apply(t,n);function c(e){i(u,r,o,c,a,"next",e)}function a(e){i(u,r,o,c,a,"throw",e)}c(void 0)})})()}}],a(t.prototype,n),o}(p(u.Plugin));return o.default=b,o}()});
10
+ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("@nocobase/client")):"function"==typeof define&&define.amd?define("@nocobase/plugin-ui-schema-storage",["@nocobase/client"],t):"object"==typeof exports?exports["@nocobase/plugin-ui-schema-storage"]=t(require("@nocobase/client")):e["@nocobase/plugin-ui-schema-storage"]=t(e["@nocobase/client"])}(self,function(e){return function(){"use strict";var t={772:function(t){t.exports=e}},n={};function r(e){var o=n[e];if(void 0!==o)return o.exports;var u=n[e]={exports:{}};return t[e](u,u.exports,r),u.exports}r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,{a:t}),t},r.d=function(e,t){for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var o={};return!function(){r.r(o);var e=r(772);function t(e,t,n,r,o,u,i){try{var c=e[u](i),a=c.value}catch(e){n(e);return}c.done?t(a):Promise.resolve(a).then(r,o)}function n(e,t,r){return(n=a()?Reflect.construct:function(e,t,n){var r=[null];r.push.apply(r,t);var o=new(Function.bind.apply(e,r));return n&&i(o,n.prototype),o}).apply(null,arguments)}function u(e){return(u=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function i(e,t){return(i=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function c(e){var t="function"==typeof Map?new Map:void 0;return(c=function(e){if(null===e||-1===Function.toString.call(e).indexOf("[native code]"))return e;if("function"!=typeof e)throw TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,r)}function r(){return n(e,arguments,u(this).constructor)}return r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),i(r,e)})(e)}function a(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(a=function(){return!!e})()}o.default=function(e){var n;if("function"!=typeof e&&null!==e)throw TypeError("Super expression must either be null or a function");function r(){var e,t;if(!(this instanceof r))throw TypeError("Cannot call a class as a function");return e=r,t=arguments,e=u(e),function(e,t){var n;if(t&&("object"==((n=t)&&"undefined"!=typeof Symbol&&n.constructor===Symbol?"symbol":typeof n)||"function"==typeof t))return t;if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(this,a()?Reflect.construct(e,t||[],u(this).constructor):e.apply(this,t))}return r.prototype=Object.create(e&&e.prototype,{constructor:{value:r,writable:!0,configurable:!0}}),e&&i(r,e),n=[{key:"load",value:function(){var e;return(e=function(){return function(e,t){var n,r,o,u,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return u={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(u[Symbol.iterator]=function(){return this}),u;function c(u){return function(c){var a=[u,c];if(n)throw TypeError("Generator is already executing.");for(;i;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return i.label++,{value:a[1],done:!1};case 5:i.label++,r=a[1],a=[0];continue;case 7:a=i.ops.pop(),i.trys.pop();continue;default:if(!(o=(o=i.trys).length>0&&o[o.length-1])&&(6===a[0]||2===a[0])){i=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){i.label=a[1];break}if(6===a[0]&&i.label<o[1]){i.label=o[1],o=a;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(a);break}o[2]&&i.ops.pop(),i.trys.pop();continue}a=t.call(e,i)}catch(e){a=[6,e],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}}}(this,function(e){return[2]})},function(){var n=this,r=arguments;return new Promise(function(o,u){var i=e.apply(n,r);function c(e){t(i,o,u,c,a,"next",e)}function a(e){t(i,o,u,c,a,"throw",e)}c(void 0)})})()}}],function(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}(r.prototype,n),r}(c(e.Plugin))}(),o}()});
@@ -8,13 +8,14 @@
8
8
  */
9
9
 
10
10
  module.exports = {
11
- "@nocobase/client": "1.7.0-beta.9",
12
- "@nocobase/database": "1.7.0-beta.9",
13
- "@nocobase/cache": "1.7.0-beta.9",
14
- "@nocobase/utils": "1.7.0-beta.9",
11
+ "@nocobase/client": "1.8.0-beta.1",
12
+ "@nocobase/database": "1.8.0-beta.1",
13
+ "@nocobase/cache": "1.8.0-beta.1",
14
+ "@nocobase/utils": "1.8.0-beta.1",
15
15
  "lodash": "4.17.21",
16
- "@nocobase/server": "1.7.0-beta.9",
17
- "@nocobase/actions": "1.7.0-beta.9",
18
- "@nocobase/resourcer": "1.7.0-beta.9",
16
+ "@nocobase/server": "1.8.0-beta.1",
17
+ "@nocobase/plugin-localization": "1.8.0-beta.1",
18
+ "@nocobase/actions": "1.8.0-beta.1",
19
+ "@nocobase/resourcer": "1.8.0-beta.1",
19
20
  "@formily/json-schema": "2.3.0"
20
21
  };
@@ -55,6 +55,7 @@ export declare class UiSchemaRepository extends Repository {
55
55
  "x-async": boolean;
56
56
  };
57
57
  clearAncestor(uid: string, options?: Transactionable): Promise<void>;
58
+ emitAfterSaveEvent(s: any, options: any): Promise<void>;
58
59
  patch(newSchema: any, options?: any): Promise<void>;
59
60
  initializeActionContext(newSchema: any, options?: any): Promise<void>;
60
61
  batchPatch(schemas: any[], options?: any): Promise<void>;
@@ -254,6 +254,22 @@ const _UiSchemaRepository = class _UiSchemaRepository extends import_database.Re
254
254
  }
255
255
  );
256
256
  }
257
+ async emitAfterSaveEvent(s, options) {
258
+ if (!(s == null ? void 0 : s.schema)) {
259
+ return;
260
+ }
261
+ const keys = ["title", "description", "x-component-props.title", "x-decorator-props.title"];
262
+ let r = false;
263
+ for (const key of keys) {
264
+ if (import_lodash.default.get(s == null ? void 0 : s.schema, key)) {
265
+ r = true;
266
+ break;
267
+ }
268
+ }
269
+ if (r) {
270
+ await this.database.emitAsync(`${this.collection.name}.afterSave`, s, options);
271
+ }
272
+ }
257
273
  async patch(newSchema, options) {
258
274
  const { transaction: transaction2 } = options;
259
275
  const rootUid = newSchema["x-uid"];
@@ -262,6 +278,7 @@ const _UiSchemaRepository = class _UiSchemaRepository extends import_database.Re
262
278
  const s = await this.model.findByPk(rootUid, { transaction: transaction2 });
263
279
  s.set("schema", { ...s.toJSON(), ...newSchema });
264
280
  await s.save({ transaction: transaction2, hooks: false });
281
+ await this.emitAfterSaveEvent(s, options);
265
282
  if (newSchema["x-server-hooks"]) {
266
283
  await this.database.emitAsync(`${this.collection.name}.afterSave`, s, options);
267
284
  }
@@ -394,6 +411,8 @@ const _UiSchemaRepository = class _UiSchemaRepository extends import_database.Re
394
411
  }
395
412
  }
396
413
  const result = await this[`insert${import_lodash.default.upperFirst(position)}`](target, schema, options);
414
+ const s = await this.model.findByPk(schema, { transaction: transaction2 });
415
+ await this.emitAfterSaveEvent(s, options);
397
416
  await this.clearXUidPathCache(result["x-uid"], transaction2);
398
417
  return result;
399
418
  }
@@ -699,6 +718,7 @@ WHERE TreeTable.depth = 1 AND TreeTable.ancestor = :ancestor and TreeTable.sort
699
718
  transaction: transaction2
700
719
  }
701
720
  );
721
+ await this.emitAfterSaveEvent(nodeModel, { transaction: transaction2 });
702
722
  if (schema["x-server-hooks"]) {
703
723
  await this.database.emitAsync(`${this.collection.name}.afterSave`, nodeModel, { transaction: transaction2 });
704
724
  }
@@ -8,10 +8,12 @@
8
8
  */
9
9
  import { Plugin } from '@nocobase/server';
10
10
  import { ServerHooks } from './server-hooks';
11
+ export declare const compile: (title: string) => string;
11
12
  export declare class PluginUISchemaStorageServer extends Plugin {
12
13
  serverHooks: ServerHooks;
13
14
  registerRepository(): void;
14
15
  beforeLoad(): Promise<void>;
15
16
  load(): Promise<void>;
17
+ registerLocalizationSource(): void;
16
18
  }
17
19
  export default PluginUISchemaStorageServer;
@@ -37,18 +37,32 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
37
37
  var server_exports = {};
38
38
  __export(server_exports, {
39
39
  PluginUISchemaStorageServer: () => PluginUISchemaStorageServer,
40
+ compile: () => compile,
40
41
  default: () => server_default
41
42
  });
42
43
  module.exports = __toCommonJS(server_exports);
43
44
  var import_database = require("@nocobase/database");
44
45
  var import_server = require("@nocobase/server");
45
46
  var import_utils = require("@nocobase/utils");
47
+ var import_utils2 = require("@nocobase/utils");
46
48
  var import_path = __toESM(require("path"));
47
49
  var import_ui_schema_action = require("./actions/ui-schema-action");
48
50
  var import_model = require("./model");
49
51
  var import_repository = __toESM(require("./repository"));
50
52
  var import_server_hooks = require("./server-hooks");
51
53
  var import_model2 = require("./server-hooks/model");
54
+ const compile = (title) => (title || "").replace(/{{\s*t\(["|'|`](.*)["|'|`]\)\s*}}/g, "$1");
55
+ function extractFields(obj) {
56
+ var _a, _b, _c, _d;
57
+ return [
58
+ obj.title,
59
+ obj.description,
60
+ (_a = obj["x-component-props"]) == null ? void 0 : _a.title,
61
+ (_b = obj["x-component-props"]) == null ? void 0 : _b.description,
62
+ (_c = obj["x-decorator-props"]) == null ? void 0 : _c.title,
63
+ (_d = obj["x-decorator-props"]) == null ? void 0 : _d.description
64
+ ].filter((value) => value !== void 0 && value !== "");
65
+ }
52
66
  class PluginUISchemaStorageServer extends import_server.Plugin {
53
67
  serverHooks;
54
68
  registerRepository() {
@@ -58,6 +72,7 @@ class PluginUISchemaStorageServer extends import_server.Plugin {
58
72
  }
59
73
  async beforeLoad() {
60
74
  const db = this.app.db;
75
+ const pm = this.app.pm;
61
76
  this.serverHooks = new import_server_hooks.ServerHooks(db);
62
77
  this.app.db.registerModels({ MagicAttributeModel: import_database.MagicAttributeModel, UiSchemaModel: import_model.UiSchemaModel, ServerHookModel: import_model2.ServerHookModel });
63
78
  this.registerRepository();
@@ -71,9 +86,22 @@ class PluginUISchemaStorageServer extends import_server.Plugin {
71
86
  });
72
87
  db.on("uiSchemas.beforeCreate", function setUid(model) {
73
88
  if (!model.get("name")) {
74
- model.set("name", (0, import_utils.uid)());
89
+ model.set("name", (0, import_utils2.uid)());
75
90
  }
76
91
  });
92
+ db.on("uiSchemas.afterSave", async function setUid(model, options) {
93
+ var _a;
94
+ const localizationPlugin = pm.get("localization");
95
+ const texts = [];
96
+ const changedFields = extractFields(model.toJSON());
97
+ if (!changedFields.length) {
98
+ return;
99
+ }
100
+ changedFields.forEach((field) => {
101
+ field && texts.push({ text: compile(field), module: `resources.ui-schema-storage` });
102
+ });
103
+ await ((_a = localizationPlugin == null ? void 0 : localizationPlugin.addNewTexts) == null ? void 0 : _a.call(localizationPlugin, texts, options));
104
+ });
77
105
  db.on("uiSchemas.afterCreate", async function insertSchema(model, options) {
78
106
  const { transaction } = options;
79
107
  const uiSchemaRepository = db.getCollection("uiSchemas").repository;
@@ -139,9 +167,36 @@ class PluginUISchemaStorageServer extends import_server.Plugin {
139
167
  ]);
140
168
  await this.importCollections((0, import_path.resolve)(__dirname, "collections"));
141
169
  }
170
+ registerLocalizationSource() {
171
+ const localizationPlugin = this.app.pm.get("localization");
172
+ if (!localizationPlugin) {
173
+ return;
174
+ }
175
+ localizationPlugin.sourceManager.registerSource("ui-schema-storage", {
176
+ title: (0, import_utils.tval)("UiSchema"),
177
+ sync: async (ctx) => {
178
+ const uiSchemas = await ctx.db.getRepository("uiSchemas").find({
179
+ raw: true
180
+ });
181
+ const resources = {};
182
+ uiSchemas.forEach((route) => {
183
+ const changedFields = extractFields(route.schema);
184
+ if (changedFields.length) {
185
+ changedFields.forEach((field) => {
186
+ resources[field] = "";
187
+ });
188
+ }
189
+ });
190
+ return {
191
+ "ui-schema-storage": resources
192
+ };
193
+ }
194
+ });
195
+ }
142
196
  }
143
197
  var server_default = PluginUISchemaStorageServer;
144
198
  // Annotate the CommonJS export names for ESM import in node:
145
199
  0 && (module.exports = {
146
- PluginUISchemaStorageServer
200
+ PluginUISchemaStorageServer,
201
+ compile
147
202
  });
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "displayName.zh-CN": "UI schema 存储服务",
5
5
  "description": "Provides centralized UI schema storage service.",
6
6
  "description.zh-CN": "提供中心化的 UI schema 存储服务。",
7
- "version": "1.7.0-beta.9",
7
+ "version": "1.8.0-beta.1",
8
8
  "license": "AGPL-3.0",
9
9
  "main": "./dist/server/index.js",
10
10
  "homepage": "https://docs.nocobase.com/handbook/ui-schema-storage",
@@ -23,7 +23,7 @@
23
23
  "@nocobase/test": "1.x",
24
24
  "@nocobase/utils": "1.x"
25
25
  },
26
- "gitHead": "7013a5080f3695d7750ab21005c90d2172c16480",
26
+ "gitHead": "103935669123174f2942247202e3d9ff15f0d4ed",
27
27
  "keywords": [
28
28
  "System & security"
29
29
  ]