@nocobase/utils 0.14.0-alpha.5 → 0.14.0-alpha.7

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/client.d.ts CHANGED
@@ -12,6 +12,7 @@ export * from './notification';
12
12
  export * from './number';
13
13
  export * from './parse-filter';
14
14
  export * from './registry';
15
+ export * from './isPortalInBody';
15
16
  export * from './uid';
16
- export { dayjs, lodash };
17
17
  export * from './url';
18
+ export { dayjs, lodash };
package/lib/client.js CHANGED
@@ -46,6 +46,7 @@ __reExport(client_exports, require("./notification"), module.exports);
46
46
  __reExport(client_exports, require("./number"), module.exports);
47
47
  __reExport(client_exports, require("./parse-filter"), module.exports);
48
48
  __reExport(client_exports, require("./registry"), module.exports);
49
+ __reExport(client_exports, require("./isPortalInBody"), module.exports);
49
50
  __reExport(client_exports, require("./uid"), module.exports);
50
51
  __reExport(client_exports, require("./url"), module.exports);
51
52
  // Annotate the CommonJS export names for ESM import in node:
@@ -64,6 +65,7 @@ __reExport(client_exports, require("./url"), module.exports);
64
65
  ...require("./number"),
65
66
  ...require("./parse-filter"),
66
67
  ...require("./registry"),
68
+ ...require("./isPortalInBody"),
67
69
  ...require("./uid"),
68
70
  ...require("./url")
69
71
  });
@@ -28,9 +28,11 @@ const getValuesByPath = /* @__PURE__ */ __name((obj, path, defaultValue) => {
28
28
  const keys = path.split(".");
29
29
  let result = [];
30
30
  let currentValue = obj;
31
+ let shouldReturnArray = false;
31
32
  for (let i = 0; i < keys.length; i++) {
32
33
  const key = keys[i];
33
34
  if (Array.isArray(currentValue)) {
35
+ shouldReturnArray = true;
34
36
  for (const element of currentValue) {
35
37
  const value = getValuesByPath(element, keys.slice(i).join("."), defaultValue);
36
38
  result = result.concat(value);
@@ -49,6 +51,9 @@ const getValuesByPath = /* @__PURE__ */ __name((obj, path, defaultValue) => {
49
51
  if (result.length === 0) {
50
52
  return defaultValue;
51
53
  }
54
+ if (shouldReturnArray) {
55
+ return result;
56
+ }
52
57
  return result.length === 1 ? result[0] : result;
53
58
  }, "getValuesByPath");
54
59
  // Annotate the CommonJS export names for ESM import in node:
@@ -0,0 +1,5 @@
1
+ /**
2
+ * 判断一个 DOM 对象是否是由 createPortal 挂在到了 body 上
3
+ * @param domNode DOM 对象
4
+ */
5
+ export declare const isPortalInBody: (dom: Element) => boolean;
@@ -0,0 +1,45 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var isPortalInBody_exports = {};
20
+ __export(isPortalInBody_exports, {
21
+ isPortalInBody: () => isPortalInBody
22
+ });
23
+ module.exports = __toCommonJS(isPortalInBody_exports);
24
+ const isPortalInBody = /* @__PURE__ */ __name((dom) => {
25
+ var _a;
26
+ while (dom) {
27
+ if (dom.id === "root" || ((_a = dom.classList) == null ? void 0 : _a.contains("nb-action"))) {
28
+ return false;
29
+ }
30
+ dom = dom.parentNode;
31
+ }
32
+ if (process.env.__TEST__) {
33
+ return false;
34
+ }
35
+ if (process.env.NODE_ENV !== "production") {
36
+ if (!document.querySelector("#root")) {
37
+ throw new Error(`isPortalInBody: can not find element with id 'root'`);
38
+ }
39
+ }
40
+ return true;
41
+ }, "isPortalInBody");
42
+ // Annotate the CommonJS export names for ESM import in node:
43
+ 0 && (module.exports = {
44
+ isPortalInBody
45
+ });
@@ -1,4 +1,5 @@
1
1
  export declare function flatten(target: any, opts?: any): {};
2
+ export declare function unflatten(obj: any, opts?: any): {};
2
3
  export type ParseFilterOptions = {
3
4
  vars?: Record<string, any>;
4
5
  now?: any;
@@ -33,9 +33,11 @@ __export(parse_filter_exports, {
33
33
  getDayRange: () => getDayRange,
34
34
  parseFilter: () => parseFilter,
35
35
  splitPathToTwoParts: () => splitPathToTwoParts,
36
+ unflatten: () => unflatten,
36
37
  utc2unit: () => utc2unit
37
38
  });
38
39
  module.exports = __toCommonJS(parse_filter_exports);
40
+ var import_lodash = __toESM(require("lodash"));
39
41
  var import_set = __toESM(require("lodash/set"));
40
42
  var import_date = require("./date");
41
43
  var import_dayjs = require("./dayjs");
@@ -58,23 +60,25 @@ function flatten(target, opts) {
58
60
  const output = {};
59
61
  function step(object, prev, currentDepth) {
60
62
  currentDepth = currentDepth || 1;
61
- Object.keys(object).forEach(function(key) {
62
- var _a;
63
- const value = object[key];
64
- const isarray = opts.safe && Array.isArray(value);
65
- const type = Object.prototype.toString.call(value);
66
- const isbuffer = isBuffer(value);
67
- const isobject = type === "[object Object]" || type === "[object Array]";
68
- const newKey = prev ? prev + delimiter + transformKey(key) : transformKey(key);
69
- if ((_a = opts.breakOn) == null ? void 0 : _a.call(opts, { key, value, path: newKey })) {
63
+ if (import_lodash.default.isObjectLike(object)) {
64
+ Object.keys(object).forEach(function(key) {
65
+ var _a;
66
+ const value = object[key];
67
+ const isarray = opts.safe && Array.isArray(value);
68
+ const type = Object.prototype.toString.call(value);
69
+ const isbuffer = isBuffer(value);
70
+ const isobject = type === "[object Object]" || type === "[object Array]";
71
+ const newKey = prev ? prev + delimiter + transformKey(key) : transformKey(key);
72
+ if ((_a = opts.breakOn) == null ? void 0 : _a.call(opts, { key, value, path: newKey })) {
73
+ output[newKey] = transformValue(value, newKey);
74
+ return;
75
+ }
76
+ if (!isarray && !isbuffer && isobject && Object.keys(value).length && (!opts.maxDepth || currentDepth < maxDepth)) {
77
+ return step(value, newKey, currentDepth + 1);
78
+ }
70
79
  output[newKey] = transformValue(value, newKey);
71
- return;
72
- }
73
- if (!isarray && !isbuffer && isobject && Object.keys(value).length && (!opts.maxDepth || currentDepth < maxDepth)) {
74
- return step(value, newKey, currentDepth + 1);
75
- }
76
- output[newKey] = transformValue(value, newKey);
77
- });
80
+ });
81
+ }
78
82
  }
79
83
  __name(step, "step");
80
84
  step(target);
@@ -125,7 +129,7 @@ const dateValueWrapper = /* @__PURE__ */ __name((value, timezone) => {
125
129
  return value;
126
130
  }
127
131
  if (typeof value === "string") {
128
- if (!timezone || /(\+|\-)\d\d\:\d\d$/.test(value)) {
132
+ if (!timezone || /(\+|-)\d\d:\d\d$/.test(value)) {
129
133
  return value;
130
134
  }
131
135
  return value + timezone;
@@ -296,5 +300,6 @@ __name(splitPathToTwoParts, "splitPathToTwoParts");
296
300
  getDayRange,
297
301
  parseFilter,
298
302
  splitPathToTwoParts,
303
+ unflatten,
299
304
  utc2unit
300
305
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/utils",
3
- "version": "0.14.0-alpha.5",
3
+ "version": "0.14.0-alpha.7",
4
4
  "main": "lib/index.js",
5
5
  "types": "./lib/index.d.ts",
6
6
  "license": "Apache-2.0",
@@ -15,5 +15,5 @@
15
15
  "multer": "^1.4.5-lts.1",
16
16
  "object-path": "^0.11.8"
17
17
  },
18
- "gitHead": "8e0ee4a1e5b682161e5dc9d27a309b68c5f1aa8b"
18
+ "gitHead": "dc958417d27ed0753439bcef192be91a03dfc30f"
19
19
  }