@nocobase/utils 1.7.0-beta.2 → 1.7.0-beta.20

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/lib/assign.js CHANGED
@@ -53,8 +53,14 @@ function getKeys(target) {
53
53
  }
54
54
  __name(getKeys, "getKeys");
55
55
  const mergeStrategies = /* @__PURE__ */ new Map();
56
- mergeStrategies.set("overwrite", (_, y) => {
57
- if (typeof y === "string") {
56
+ mergeStrategies.set("overwrite", (x, y) => {
57
+ if (y === void 0) {
58
+ if (typeof x === "string" && x.includes(",")) {
59
+ return x.split(",");
60
+ }
61
+ return x;
62
+ }
63
+ if (typeof y === "string" && y.includes(",")) {
58
64
  y = y.split(",");
59
65
  }
60
66
  return y;
@@ -123,15 +129,22 @@ mergeStrategies.set(
123
129
  })().filter(Boolean)
124
130
  );
125
131
  function assign(target, source, strategies = {}) {
126
- getKeys(source).forEach((sourceKey) => {
132
+ const sourceKeys = getKeys(source);
133
+ const targetKeys = getKeys(target);
134
+ import_lodash.default.uniq([...sourceKeys, ...targetKeys]).forEach((sourceKey) => {
127
135
  const strategy = strategies[sourceKey];
128
- let func = mergeStrategies.get("deepMerge");
136
+ let func;
129
137
  if (typeof strategy === "function") {
130
138
  func = strategy;
131
139
  } else if (typeof strategy === "string" && mergeStrategies.has(strategy)) {
132
140
  func = mergeStrategies.get(strategy);
133
141
  }
134
- target[sourceKey] = func(target[sourceKey], source[sourceKey]);
142
+ if (func) {
143
+ target[sourceKey] = func(target[sourceKey], source[sourceKey]);
144
+ } else if (sourceKeys.includes(sourceKey)) {
145
+ const func2 = mergeStrategies.get("deepMerge");
146
+ target[sourceKey] = func2(target[sourceKey], source[sourceKey]);
147
+ }
135
148
  });
136
149
  return target;
137
150
  }
package/lib/client.d.ts CHANGED
@@ -27,4 +27,5 @@ export * from './isPortalInBody';
27
27
  export * from './parseHTML';
28
28
  export * from './uid';
29
29
  export * from './url';
30
+ export * from './transformMultiColumnToSingleColumn';
30
31
  export { dayjs, lodash };
package/lib/client.js CHANGED
@@ -62,6 +62,7 @@ __reExport(client_exports, require("./isPortalInBody"), module.exports);
62
62
  __reExport(client_exports, require("./parseHTML"), module.exports);
63
63
  __reExport(client_exports, require("./uid"), module.exports);
64
64
  __reExport(client_exports, require("./url"), module.exports);
65
+ __reExport(client_exports, require("./transformMultiColumnToSingleColumn"), module.exports);
65
66
  // Annotate the CommonJS export names for ESM import in node:
66
67
  0 && (module.exports = {
67
68
  dayjs,
@@ -84,5 +85,6 @@ __reExport(client_exports, require("./url"), module.exports);
84
85
  ...require("./isPortalInBody"),
85
86
  ...require("./parseHTML"),
86
87
  ...require("./uid"),
87
- ...require("./url")
88
+ ...require("./url"),
89
+ ...require("./transformMultiColumnToSingleColumn")
88
90
  });
@@ -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 declare function md5(input: string): string;
package/lib/crypto.js ADDED
@@ -0,0 +1,41 @@
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 __name = (target, value) => __defProp(target, "name", { value, configurable: true });
15
+ var __export = (target, all) => {
16
+ for (var name in all)
17
+ __defProp(target, name, { get: all[name], enumerable: true });
18
+ };
19
+ var __copyProps = (to, from, except, desc) => {
20
+ if (from && typeof from === "object" || typeof from === "function") {
21
+ for (let key of __getOwnPropNames(from))
22
+ if (!__hasOwnProp.call(to, key) && key !== except)
23
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
24
+ }
25
+ return to;
26
+ };
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+ var crypto_exports = {};
29
+ __export(crypto_exports, {
30
+ md5: () => md5
31
+ });
32
+ module.exports = __toCommonJS(crypto_exports);
33
+ var import_crypto = require("crypto");
34
+ function md5(input) {
35
+ return (0, import_crypto.createHash)("md5").update(input).digest("hex");
36
+ }
37
+ __name(md5, "md5");
38
+ // Annotate the CommonJS export names for ESM import in node:
39
+ 0 && (module.exports = {
40
+ md5
41
+ });
package/lib/dayjs.js CHANGED
@@ -42,6 +42,7 @@ module.exports = __toCommonJS(dayjs_exports);
42
42
  var import_dayjs = __toESM(require("dayjs"));
43
43
  var import_advancedFormat = __toESM(require("dayjs/plugin/advancedFormat"));
44
44
  var import_customParseFormat = __toESM(require("dayjs/plugin/customParseFormat"));
45
+ var import_duration = __toESM(require("dayjs/plugin/duration"));
45
46
  var import_isBetween = __toESM(require("dayjs/plugin/isBetween"));
46
47
  var import_isSameOrAfter = __toESM(require("dayjs/plugin/isSameOrAfter"));
47
48
  var import_isSameOrBefore = __toESM(require("dayjs/plugin/isSameOrBefore"));
@@ -66,6 +67,7 @@ import_dayjs.default.extend(import_weekOfYear.default);
66
67
  import_dayjs.default.extend(import_weekYear.default);
67
68
  import_dayjs.default.extend(import_customParseFormat.default);
68
69
  import_dayjs.default.extend(import_advancedFormat.default);
70
+ import_dayjs.default.extend(import_duration.default);
69
71
  // Annotate the CommonJS export names for ESM import in node:
70
72
  0 && (module.exports = {
71
73
  dayjs
package/lib/index.d.ts CHANGED
@@ -7,10 +7,12 @@
7
7
  * For more information, please refer to: https://www.nocobase.com/agreement.
8
8
  */
9
9
  import lodash from 'lodash';
10
- import { dayjs } from './dayjs';
10
+ export { lodash };
11
+ export { dayjs } from './dayjs';
11
12
  export * from './assign';
12
13
  export * from './collections-graph';
13
14
  export * from './common';
15
+ export * from './crypto';
14
16
  export * from './date';
15
17
  export * from './dayjs';
16
18
  export * from './forEach';
@@ -35,5 +37,4 @@ export * from './url';
35
37
  export * from './i18n';
36
38
  export * from './wrap-middleware';
37
39
  export * from './object-to-cli-args';
38
- export { dayjs, lodash };
39
40
  export { Schema } from '@formily/json-schema';
package/lib/index.js CHANGED
@@ -47,6 +47,7 @@ var import_dayjs = require("./dayjs");
47
47
  __reExport(src_exports, require("./assign"), module.exports);
48
48
  __reExport(src_exports, require("./collections-graph"), module.exports);
49
49
  __reExport(src_exports, require("./common"), module.exports);
50
+ __reExport(src_exports, require("./crypto"), module.exports);
50
51
  __reExport(src_exports, require("./date"), module.exports);
51
52
  __reExport(src_exports, require("./dayjs"), module.exports);
52
53
  __reExport(src_exports, require("./forEach"), module.exports);
@@ -80,6 +81,7 @@ var import_json_schema = require("@formily/json-schema");
80
81
  ...require("./assign"),
81
82
  ...require("./collections-graph"),
82
83
  ...require("./common"),
84
+ ...require("./crypto"),
83
85
  ...require("./date"),
84
86
  ...require("./dayjs"),
85
87
  ...require("./forEach"),
@@ -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
+ /**
10
+ * 将多列布局转换为单列布局
11
+ * @param {Object} schema - 输入的 JSON Schema 对象
12
+ * @param {Function} [ignore] - 可选的忽略函数,用于判断是否忽略某个列
13
+ * @returns {Object} - 转换后的 JSON Schema 对象
14
+ */
15
+ export declare const transformMultiColumnToSingleColumn: (schema: any, ignore?: (colSchema: any) => boolean) => any;
@@ -0,0 +1,127 @@
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 __name = (target, value) => __defProp(target, "name", { value, configurable: true });
17
+ var __export = (target, all) => {
18
+ for (var name in all)
19
+ __defProp(target, name, { get: all[name], enumerable: true });
20
+ };
21
+ var __copyProps = (to, from, except, desc) => {
22
+ if (from && typeof from === "object" || typeof from === "function") {
23
+ for (let key of __getOwnPropNames(from))
24
+ if (!__hasOwnProp.call(to, key) && key !== except)
25
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
26
+ }
27
+ return to;
28
+ };
29
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
30
+ // If the importer is in node compatibility mode or this is not an ESM
31
+ // file that has been converted to a CommonJS file using a Babel-
32
+ // compatible transform (i.e. "__esModule" has not been set), then set
33
+ // "default" to the CommonJS "module.exports" for node compatibility.
34
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
35
+ mod
36
+ ));
37
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
38
+ var transformMultiColumnToSingleColumn_exports = {};
39
+ __export(transformMultiColumnToSingleColumn_exports, {
40
+ transformMultiColumnToSingleColumn: () => transformMultiColumnToSingleColumn
41
+ });
42
+ module.exports = __toCommonJS(transformMultiColumnToSingleColumn_exports);
43
+ var import_json_schema = require("@formily/json-schema");
44
+ var import_lodash = __toESM(require("lodash"));
45
+ var import_uid = require("./uid");
46
+ var import_package = __toESM(require("../package.json"));
47
+ const transformMultiColumnToSingleColumn = /* @__PURE__ */ __name((schema, ignore) => {
48
+ if (!schema) return schema;
49
+ if (schema["x-component"] !== "Grid") {
50
+ Object.keys(schema.properties || {}).forEach((key) => {
51
+ schema.properties[key] = transformMultiColumnToSingleColumn(schema.properties[key], ignore);
52
+ });
53
+ return schema;
54
+ }
55
+ const parent = schema.parent;
56
+ if (schema.toJSON) {
57
+ schema = schema.toJSON();
58
+ } else {
59
+ schema = import_lodash.default.cloneDeep(schema);
60
+ }
61
+ const newProperties = {};
62
+ const { properties = {} } = schema;
63
+ let index = 0;
64
+ Object.keys(properties).forEach((key, rowIndex) => {
65
+ const row = properties[key];
66
+ if (row["x-component"] !== "Grid.Row") {
67
+ row["x-index"] = ++index;
68
+ newProperties[key] = row;
69
+ return;
70
+ }
71
+ if (!row.properties) {
72
+ return;
73
+ }
74
+ if (Object.keys(row.properties).length === 1) {
75
+ row["x-index"] = ++index;
76
+ newProperties[key] = row;
77
+ return;
78
+ }
79
+ Object.keys(row.properties).forEach((columnKey, colIndex) => {
80
+ const column = row.properties[columnKey];
81
+ import_lodash.default.set(column, "x-component-props.width", 100);
82
+ if (colIndex === 0) {
83
+ row["x-index"] = ++index;
84
+ newProperties[key] = row;
85
+ return;
86
+ }
87
+ if (ignore == null ? void 0 : ignore(column)) {
88
+ return;
89
+ }
90
+ delete row.properties[columnKey];
91
+ newProperties[`${(0, import_uid.uid)()}_${columnKey}`] = createRow(column, columnKey, ++index);
92
+ });
93
+ });
94
+ schema.properties = newProperties;
95
+ if (parent) {
96
+ const result = new import_json_schema.Schema(schema, parent);
97
+ if (parent.properties) {
98
+ Object.keys(parent.properties).forEach((key) => {
99
+ if (key === schema.name) {
100
+ parent.properties[key] = result;
101
+ }
102
+ });
103
+ }
104
+ return result;
105
+ }
106
+ return schema;
107
+ }, "transformMultiColumnToSingleColumn");
108
+ function createRow(column, key, index) {
109
+ return {
110
+ type: "void",
111
+ version: "2.0",
112
+ "x-component": "Grid.Row",
113
+ "x-app-version": import_package.default.version,
114
+ "x-uid": (0, import_uid.uid)(),
115
+ "x-async": false,
116
+ "x-index": index,
117
+ _isJSONSchemaObject: true,
118
+ properties: {
119
+ [key]: column
120
+ }
121
+ };
122
+ }
123
+ __name(createRow, "createRow");
124
+ // Annotate the CommonJS export names for ESM import in node:
125
+ 0 && (module.exports = {
126
+ transformMultiColumnToSingleColumn
127
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/utils",
3
- "version": "1.7.0-beta.2",
3
+ "version": "1.7.0-beta.20",
4
4
  "main": "lib/index.js",
5
5
  "types": "./lib/index.d.ts",
6
6
  "license": "AGPL-3.0",
@@ -16,5 +16,5 @@
16
16
  "multer": "^1.4.5-lts.1",
17
17
  "object-path": "^0.11.8"
18
18
  },
19
- "gitHead": "58b206bdfca521e79a69989ca55dd19075dca523"
19
+ "gitHead": "178910a2afe33bd4850e2519507d32b631a380fc"
20
20
  }