@nocobase/client 0.8.1-alpha.4 → 0.9.0-alpha.2

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.
Files changed (195) hide show
  1. package/es/acl/ACLProvider.d.ts +16 -2
  2. package/es/acl/ACLProvider.js +271 -100
  3. package/es/acl/Configuration/ConfigureCenter.d.ts +2 -0
  4. package/es/acl/Configuration/ConfigureCenter.js +254 -0
  5. package/es/acl/Configuration/MenuConfigure.js +2 -2
  6. package/es/acl/Configuration/PermisionProvider.d.ts +4 -0
  7. package/es/acl/Configuration/PermisionProvider.js +132 -0
  8. package/es/acl/Configuration/RoleConfigure.js +98 -23
  9. package/es/acl/Configuration/RoleTable.d.ts +1 -1
  10. package/es/acl/Configuration/RoleTable.js +6 -3
  11. package/es/acl/Configuration/RolesResourcesActions.js +2 -2
  12. package/es/acl/Configuration/index.d.ts +1 -0
  13. package/es/acl/Configuration/index.js +2 -1
  14. package/es/acl/Configuration/schemas/roleCollections.js +41 -13
  15. package/es/acl/Configuration/schemas/roles.js +42 -2
  16. package/es/acl/Configuration/schemas/scopes.js +2 -0
  17. package/es/acl/index.d.ts +1 -0
  18. package/es/acl/index.js +2 -1
  19. package/es/acl/style.less +10 -0
  20. package/es/antd-config-provider/index.d.ts +3 -1
  21. package/es/antd-config-provider/index.js +25 -6
  22. package/es/antd-config-provider/loadConstrueLocale.d.ts +1 -0
  23. package/es/antd-config-provider/loadConstrueLocale.js +293 -0
  24. package/es/api-client/APIClient.js +5 -0
  25. package/es/block-provider/FormBlockProvider.js +5 -2
  26. package/es/block-provider/KanbanBlockProvider.js +3 -3
  27. package/es/block-provider/SharedFilterProvider.d.ts +1 -0
  28. package/es/block-provider/SharedFilterProvider.js +22 -6
  29. package/es/collection-manager/CollectionHistoryProvider.js +14 -2
  30. package/es/collection-manager/hooks/useCollection.d.ts +1 -0
  31. package/es/collection-manager/hooks/useCollection.js +10 -0
  32. package/es/collection-manager/interfaces/index.d.ts +0 -1
  33. package/es/collection-manager/interfaces/index.js +0 -1
  34. package/es/collection-manager/interfaces/o2m.js +1 -0
  35. package/es/collection-manager/interfaces/properties/operators.js +7 -0
  36. package/es/collection-manager/interfaces/subTable.js +1 -0
  37. package/es/collection-manager/templates/calendar.js +5 -0
  38. package/es/formula/Expression.d.ts +2 -0
  39. package/es/formula/Expression.js +296 -0
  40. package/es/formula/Result.d.ts +2 -0
  41. package/es/formula/Result.js +91 -0
  42. package/es/formula/index.d.ts +6 -0
  43. package/es/formula/index.js +8 -0
  44. package/es/i18n/i18n.js +7 -12
  45. package/es/index.d.ts +2 -1
  46. package/es/index.js +3 -2
  47. package/es/locale/en_US.d.ts +108 -28
  48. package/es/locale/en_US.js +108 -28
  49. package/es/locale/index.d.ts +201 -4
  50. package/es/locale/index.js +191 -58
  51. package/es/locale/ja_JP.d.ts +4 -0
  52. package/es/locale/ja_JP.js +4 -0
  53. package/es/locale/zh_CN.d.ts +11 -1
  54. package/es/locale/zh_CN.js +12 -2
  55. package/es/plugin-manager/PluginManager.js +19 -13
  56. package/es/pm/PluginManagerLink.js +38 -43
  57. package/es/pm/index.d.ts +1 -0
  58. package/es/pm/index.js +84 -35
  59. package/es/record-provider/index.d.ts +1 -0
  60. package/es/record-provider/index.js +7 -4
  61. package/es/route-switch/antd/admin-layout/index.d.ts +1 -0
  62. package/es/route-switch/antd/admin-layout/index.js +4 -6
  63. package/es/schema-component/antd/action/Action.js +19 -16
  64. package/es/schema-component/antd/association-filter/AssociationFilter.Item.js +24 -23
  65. package/es/schema-component/antd/cron/Cron.d.ts +0 -1
  66. package/es/schema-component/antd/cron/Cron.js +16 -19
  67. package/es/schema-component/antd/cron/locale/index.d.ts +37 -0
  68. package/es/schema-component/antd/cron/locale/index.js +6 -0
  69. package/es/schema-component/antd/filter/useFilterActionProps.js +17 -23
  70. package/es/schema-component/antd/form-item/FormItem.js +5 -4
  71. package/es/schema-component/antd/index.d.ts +1 -2
  72. package/es/schema-component/antd/index.js +1 -2
  73. package/es/schema-component/antd/page/FixedBlock.d.ts +1 -1
  74. package/es/schema-component/antd/page/FixedBlock.js +70 -21
  75. package/es/schema-component/antd/page/Page.js +15 -10
  76. package/es/schema-component/antd/remote-select/RemoteSelect.js +12 -2
  77. package/es/schema-component/antd/table/Table.Array.js +1 -1
  78. package/es/schema-component/antd/table-v2/Table.js +13 -6
  79. package/es/schema-component/antd/table-v2/TableBlockDesigner.js +24 -8
  80. package/es/schema-component/hooks/useDesignable.d.ts +1 -1
  81. package/es/schema-component/hooks/useDesignable.js +45 -16
  82. package/es/schema-component/hooks/useFieldTitle.js +3 -1
  83. package/es/schema-initializer/buttons/ReadPrettyFormActionInitializers.d.ts +3 -0
  84. package/es/schema-initializer/buttons/ReadPrettyFormActionInitializers.js +1 -0
  85. package/es/schema-initializer/buttons/TableActionColumnInitializers.js +1 -0
  86. package/es/schema-initializer/utils.js +6 -9
  87. package/es/schema-templates/BlockTemplate.js +2 -2
  88. package/es/schema-templates/SchemaTemplateManagerProvider.js +1 -1
  89. package/es/system-settings/SystemSettingsShortcut.js +1 -1
  90. package/lib/acl/ACLProvider.d.ts +16 -2
  91. package/lib/acl/ACLProvider.js +283 -102
  92. package/lib/acl/Configuration/ConfigureCenter.d.ts +2 -0
  93. package/lib/acl/Configuration/ConfigureCenter.js +278 -0
  94. package/lib/acl/Configuration/MenuConfigure.js +3 -3
  95. package/lib/acl/Configuration/PermisionProvider.d.ts +4 -0
  96. package/lib/acl/Configuration/PermisionProvider.js +156 -0
  97. package/lib/acl/Configuration/RoleConfigure.js +107 -23
  98. package/lib/acl/Configuration/RoleTable.d.ts +1 -1
  99. package/lib/acl/Configuration/RoleTable.js +8 -4
  100. package/lib/acl/Configuration/RolesResourcesActions.js +2 -2
  101. package/lib/acl/Configuration/index.d.ts +1 -0
  102. package/lib/acl/Configuration/index.js +15 -1
  103. package/lib/acl/Configuration/schemas/roleCollections.js +41 -13
  104. package/lib/acl/Configuration/schemas/roles.js +47 -2
  105. package/lib/acl/Configuration/schemas/scopes.js +2 -0
  106. package/lib/acl/index.d.ts +1 -0
  107. package/lib/acl/index.js +3 -1
  108. package/lib/acl/style.less +10 -0
  109. package/lib/antd-config-provider/index.d.ts +3 -1
  110. package/lib/antd-config-provider/index.js +40 -6
  111. package/lib/antd-config-provider/loadConstrueLocale.d.ts +1 -0
  112. package/lib/antd-config-provider/loadConstrueLocale.js +304 -0
  113. package/lib/api-client/APIClient.js +5 -0
  114. package/lib/block-provider/FormBlockProvider.js +9 -3
  115. package/lib/block-provider/KanbanBlockProvider.js +3 -3
  116. package/lib/block-provider/SharedFilterProvider.d.ts +1 -0
  117. package/lib/block-provider/SharedFilterProvider.js +26 -7
  118. package/lib/collection-manager/CollectionHistoryProvider.js +14 -1
  119. package/lib/collection-manager/hooks/useCollection.d.ts +1 -0
  120. package/lib/collection-manager/hooks/useCollection.js +10 -0
  121. package/lib/collection-manager/interfaces/index.d.ts +0 -1
  122. package/lib/collection-manager/interfaces/index.js +0 -13
  123. package/lib/collection-manager/interfaces/o2m.js +1 -0
  124. package/lib/collection-manager/interfaces/properties/operators.js +7 -0
  125. package/lib/collection-manager/interfaces/subTable.js +1 -0
  126. package/lib/collection-manager/templates/calendar.js +5 -0
  127. package/lib/formula/Expression.d.ts +2 -0
  128. package/lib/formula/Expression.js +319 -0
  129. package/lib/formula/Result.d.ts +2 -0
  130. package/lib/formula/Result.js +114 -0
  131. package/lib/formula/index.d.ts +6 -0
  132. package/lib/formula/index.js +22 -0
  133. package/lib/i18n/i18n.js +7 -14
  134. package/lib/index.d.ts +2 -1
  135. package/lib/index.js +26 -13
  136. package/lib/locale/en_US.d.ts +108 -28
  137. package/lib/locale/en_US.js +108 -28
  138. package/lib/locale/index.d.ts +201 -4
  139. package/lib/locale/index.js +197 -67
  140. package/lib/locale/ja_JP.d.ts +4 -0
  141. package/lib/locale/ja_JP.js +4 -0
  142. package/lib/locale/zh_CN.d.ts +11 -1
  143. package/lib/locale/zh_CN.js +12 -2
  144. package/lib/plugin-manager/PluginManager.js +20 -13
  145. package/lib/pm/PluginManagerLink.js +37 -43
  146. package/lib/pm/index.d.ts +1 -0
  147. package/lib/pm/index.js +90 -35
  148. package/lib/record-provider/index.d.ts +1 -0
  149. package/lib/record-provider/index.js +7 -4
  150. package/lib/route-switch/antd/admin-layout/index.d.ts +1 -0
  151. package/lib/route-switch/antd/admin-layout/index.js +5 -4
  152. package/lib/schema-component/antd/action/Action.js +19 -16
  153. package/lib/schema-component/antd/association-filter/AssociationFilter.Item.js +22 -21
  154. package/lib/schema-component/antd/cron/Cron.d.ts +0 -1
  155. package/lib/schema-component/antd/cron/Cron.js +19 -24
  156. package/lib/schema-component/antd/cron/locale/index.d.ts +37 -0
  157. package/lib/schema-component/antd/cron/locale/index.js +18 -0
  158. package/lib/schema-component/antd/filter/useFilterActionProps.js +16 -23
  159. package/lib/schema-component/antd/form-item/FormItem.js +6 -4
  160. package/lib/schema-component/antd/index.d.ts +1 -2
  161. package/lib/schema-component/antd/index.js +8 -21
  162. package/lib/schema-component/antd/page/FixedBlock.d.ts +1 -1
  163. package/lib/schema-component/antd/page/FixedBlock.js +71 -21
  164. package/lib/schema-component/antd/page/Page.js +14 -9
  165. package/lib/schema-component/antd/remote-select/RemoteSelect.js +18 -3
  166. package/lib/schema-component/antd/table/Table.Array.js +1 -1
  167. package/lib/schema-component/antd/table-v2/Table.js +14 -6
  168. package/lib/schema-component/antd/table-v2/TableBlockDesigner.js +25 -8
  169. package/lib/schema-component/hooks/useDesignable.d.ts +1 -1
  170. package/lib/schema-component/hooks/useDesignable.js +47 -18
  171. package/lib/schema-component/hooks/useFieldTitle.js +4 -1
  172. package/lib/schema-initializer/buttons/ReadPrettyFormActionInitializers.d.ts +3 -0
  173. package/lib/schema-initializer/buttons/ReadPrettyFormActionInitializers.js +1 -0
  174. package/lib/schema-initializer/buttons/TableActionColumnInitializers.js +1 -0
  175. package/lib/schema-initializer/utils.js +6 -9
  176. package/lib/schema-templates/BlockTemplate.js +2 -2
  177. package/lib/schema-templates/SchemaTemplateManagerProvider.js +1 -1
  178. package/lib/system-settings/SystemSettingsShortcut.js +1 -1
  179. package/package.json +6 -11
  180. package/es/collection-manager/interfaces/formula.d.ts +0 -2
  181. package/es/collection-manager/interfaces/formula.js +0 -74
  182. package/es/schema-component/antd/formula-input/Compute.d.ts +0 -3
  183. package/es/schema-component/antd/formula-input/Compute.js +0 -55
  184. package/es/schema-component/antd/formula-input/FormulaInput.d.ts +0 -3
  185. package/es/schema-component/antd/formula-input/FormulaInput.js +0 -167
  186. package/es/schema-component/antd/formula-input/index.d.ts +0 -1
  187. package/es/schema-component/antd/formula-input/index.js +0 -7
  188. package/lib/collection-manager/interfaces/formula.d.ts +0 -2
  189. package/lib/collection-manager/interfaces/formula.js +0 -83
  190. package/lib/schema-component/antd/formula-input/Compute.d.ts +0 -3
  191. package/lib/schema-component/antd/formula-input/Compute.js +0 -79
  192. package/lib/schema-component/antd/formula-input/FormulaInput.d.ts +0 -3
  193. package/lib/schema-component/antd/formula-input/FormulaInput.js +0 -191
  194. package/lib/schema-component/antd/formula-input/index.d.ts +0 -1
  195. package/lib/schema-component/antd/formula-input/index.js +0 -18
@@ -10,6 +10,8 @@ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Sy
10
10
 
11
11
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
12
12
 
13
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
14
+
13
15
  import React, { createContext, useState } from 'react';
14
16
  export var SHARED_FILTER_CONDITION;
15
17
 
@@ -18,11 +20,25 @@ export var SHARED_FILTER_CONDITION;
18
20
  SHARED_FILTER_CONDITION["OR"] = "$or";
19
21
  })(SHARED_FILTER_CONDITION || (SHARED_FILTER_CONDITION = {}));
20
22
 
23
+ export var mergeFilter = function mergeFilter(filters) {
24
+ var op = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '$and';
25
+ var items = filters.filter(Boolean);
26
+
27
+ if (items.length === 0) {
28
+ return {};
29
+ }
30
+
31
+ if (items.length === 1) {
32
+ return items[0];
33
+ }
34
+
35
+ return _defineProperty({}, op, items);
36
+ };
21
37
  export var getFilterParams = function getFilterParams(filterStore) {
22
- var newAssociationFilterList = Object.entries(filterStore).map(function (_ref) {
23
- var _ref2 = _slicedToArray(_ref, 2),
24
- key = _ref2[0],
25
- filter = _ref2[1];
38
+ var newAssociationFilterList = Object.entries(filterStore).map(function (_ref2) {
39
+ var _ref3 = _slicedToArray(_ref2, 2),
40
+ key = _ref3[0],
41
+ filter = _ref3[1];
26
42
 
27
43
  return filter;
28
44
  });
@@ -37,12 +53,12 @@ export var SharedFilterContext = /*#__PURE__*/createContext({
37
53
  getFilterParams: getFilterParams
38
54
  });
39
55
  export var concatFilter = function concatFilter(f1, f2) {
40
- var newAnd = [f1.$and, f2.$and].filter(function (i) {
56
+ var newAnd = [f1 === null || f1 === void 0 ? void 0 : f1.$and, f2 === null || f2 === void 0 ? void 0 : f2.$and].filter(function (i) {
41
57
  return i;
42
58
  }).reduce(function (pre, cur) {
43
59
  return pre.concat(cur);
44
60
  }, []);
45
- var newOr = [f1.$or, f2.$or].filter(function (i) {
61
+ var newOr = [f1 === null || f1 === void 0 ? void 0 : f1.$or, f2 === null || f2 === void 0 ? void 0 : f2.$or].filter(function (i) {
46
62
  return i;
47
63
  }).reduce(function (pre, cur) {
48
64
  return pre.concat(cur);
@@ -3,7 +3,8 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try
3
3
  function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
4
4
 
5
5
  import { Spin } from 'antd';
6
- import React, { createContext, useContext } from 'react';
6
+ import React, { createContext, useContext, useEffect } from 'react';
7
+ import { useLocation } from 'react-router-dom';
7
8
  import { APIClientContext, useRequest } from '../api-client';
8
9
  var CollectionHistoryContext = /*#__PURE__*/createContext({
9
10
  historyCollections: [],
@@ -26,7 +27,18 @@ export var CollectionHistoryProvider = function CollectionHistoryProvider(props)
26
27
  sort: ['sort']
27
28
  }
28
29
  };
29
- var service = useRequest(options); // 刷新 collecionHistory
30
+ var location = useLocation(); // console.log('location', location);
31
+
32
+ var service = useRequest(options, {
33
+ manual: true
34
+ });
35
+ var isAdminPage = location.pathname.startsWith('/admin');
36
+ var token = api.auth.getToken() || '';
37
+ useEffect(function () {
38
+ if (isAdminPage && token) {
39
+ service.run();
40
+ }
41
+ }, [isAdminPage, token]); // 刷新 collecionHistory
30
42
 
31
43
  var refreshCH = /*#__PURE__*/function () {
32
44
  var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
@@ -4,6 +4,7 @@ export declare const useCollection: () => {
4
4
  resource: import("@nocobase/sdk").IResource;
5
5
  getField(name: SchemaKey): CollectionFieldOptions;
6
6
  fields: import("../types").FieldOptions[];
7
+ getPrimaryKey: () => any;
7
8
  currentFields: import("../types").FieldOptions[];
8
9
  inheritedFields: any[];
9
10
  name?: string;
@@ -36,6 +36,16 @@ export var useCollection = function useCollection() {
36
36
  });
37
37
  },
38
38
  fields: totalFields,
39
+ getPrimaryKey: function getPrimaryKey() {
40
+ if (collection.targetKey || collection.filterTargetKey) {
41
+ return collection.targetKey || collection.filterTargetKey;
42
+ }
43
+
44
+ var field = currentFields.find(function (field) {
45
+ return field.primaryKey;
46
+ });
47
+ return field ? field.name : 'id';
48
+ },
39
49
  currentFields: currentFields,
40
50
  inheritedFields: inheritedFields
41
51
  });
@@ -6,7 +6,6 @@ export * from './createdAt';
6
6
  export * from './createdBy';
7
7
  export * from './datetime';
8
8
  export * from './email';
9
- export * from './formula';
10
9
  export * from './icon';
11
10
  export * from './id';
12
11
  export * from './input';
@@ -6,7 +6,6 @@ export * from './createdAt';
6
6
  export * from './createdBy';
7
7
  export * from './datetime';
8
8
  export * from './email';
9
- export * from './formula';
10
9
  export * from './icon';
11
10
  export * from './id';
12
11
  export * from './input';
@@ -60,6 +60,7 @@ export var o2m = {
60
60
  block: {
61
61
  type: 'void',
62
62
  'x-decorator': 'TableFieldProvider',
63
+ 'x-acl-action': "".concat(association, ":list"),
63
64
  'x-decorator-props': {
64
65
  collection: field.target,
65
66
  association: association,
@@ -143,6 +143,13 @@ export var id = [{
143
143
  visible: function visible(field) {
144
144
  return field.collectionName === 'users';
145
145
  }
146
+ }, {
147
+ label: '{{t("is not current logged-in user")}}',
148
+ value: '$isNotCurrentUser',
149
+ noValue: true,
150
+ visible: function visible(field) {
151
+ return field.collectionName === 'users';
152
+ }
146
153
  }, {
147
154
  label: '{{t("exists")}}',
148
155
  value: '$exists',
@@ -33,6 +33,7 @@ export var subTable = {
33
33
  block: {
34
34
  type: 'void',
35
35
  'x-decorator': 'TableFieldProvider',
36
+ 'x-acl-action': "".concat(field.target, ":list"),
36
37
  'x-decorator-props': {
37
38
  collection: field.target,
38
39
  association: association,
@@ -5,6 +5,11 @@ export var calendar = {
5
5
  order: 2,
6
6
  color: 'orange',
7
7
  default: {
8
+ createdBy: true,
9
+ updatedBy: true,
10
+ createdAt: true,
11
+ updatedAt: true,
12
+ sortable: true,
8
13
  fields: [{
9
14
  name: 'cron',
10
15
  type: 'string',
@@ -0,0 +1,2 @@
1
+ export declare const Expression: (props: any) => JSX.Element;
2
+ export default Expression;
@@ -0,0 +1,296 @@
1
+ var _templateObject;
2
+
3
+ function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
4
+
5
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
6
+
7
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
8
+
9
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
10
+
11
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
12
+
13
+ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
14
+
15
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
16
+
17
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
18
+
19
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
20
+
21
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
22
+
23
+ import { css } from '@emotion/css';
24
+ import { onFormSubmitValidateStart } from '@formily/core';
25
+ import { useField, useFormEffects } from '@formily/react';
26
+ import { Dropdown, Menu } from 'antd';
27
+ import React, { useEffect, useRef, useState } from 'react';
28
+ import { useTranslation } from 'react-i18next';
29
+
30
+ function pasteHtml(html) {
31
+ var selectPastedContent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
32
+ var sel, range;
33
+
34
+ if (window.getSelection) {
35
+ // IE9 and non-IE
36
+ sel = window.getSelection();
37
+
38
+ if (sel.getRangeAt && sel.rangeCount) {
39
+ range = sel.getRangeAt(0);
40
+ range.deleteContents(); // Range.createContextualFragment() would be useful here but is
41
+ // only relatively recently standardized and is not supported in
42
+ // some browsers (IE9, for one)
43
+
44
+ var el = document.createElement('div');
45
+ el.innerHTML = html;
46
+ var frag = document.createDocumentFragment(),
47
+ node,
48
+ lastNode;
49
+
50
+ while (node = el.firstChild) {
51
+ lastNode = frag.appendChild(node);
52
+ }
53
+
54
+ var firstNode = frag.firstChild;
55
+ range.insertNode(frag); // Preserve the selection
56
+
57
+ if (lastNode) {
58
+ range = range.cloneRange();
59
+ range.setStartAfter(lastNode);
60
+
61
+ if (selectPastedContent) {
62
+ range.setStartBefore(firstNode);
63
+ } else {
64
+ range.collapse(true);
65
+ }
66
+
67
+ sel.removeAllRanges();
68
+ sel.addRange(range);
69
+ }
70
+ }
71
+ }
72
+ }
73
+
74
+ var getValue = function getValue(el) {
75
+ var _values$join;
76
+
77
+ var values = [];
78
+
79
+ var _iterator = _createForOfIteratorHelper(el.childNodes),
80
+ _step;
81
+
82
+ try {
83
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
84
+ var node = _step.value;
85
+
86
+ if (node.nodeName === 'SPAN') {
87
+ values.push("{{".concat(node['dataset']['key'], "}}"));
88
+ } else {
89
+ var _node$textContent, _node$textContent$tri;
90
+
91
+ values.push((_node$textContent = node.textContent) === null || _node$textContent === void 0 ? void 0 : (_node$textContent$tri = _node$textContent.trim) === null || _node$textContent$tri === void 0 ? void 0 : _node$textContent$tri.call(_node$textContent));
92
+ }
93
+ }
94
+ } catch (err) {
95
+ _iterator.e(err);
96
+ } finally {
97
+ _iterator.f();
98
+ }
99
+
100
+ var text = (_values$join = values.join(' ')) === null || _values$join === void 0 ? void 0 : _values$join.replace(/\s+/g, ' ').trim();
101
+ return " ".concat(text, " ");
102
+ };
103
+
104
+ var renderExp = function renderExp(exp) {
105
+ var scope = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
106
+ return exp.replace(/{{([^}]+)}}/g, function (_, i) {
107
+ return scope[i.trim()] || '';
108
+ });
109
+ };
110
+
111
+ export var Expression = function Expression(props) {
112
+ var evaluate = props.evaluate,
113
+ value = props.value,
114
+ supports = props.supports,
115
+ useCurrentFields = props.useCurrentFields;
116
+ var field = useField();
117
+
118
+ var _useTranslation = useTranslation(),
119
+ t = _useTranslation.t;
120
+
121
+ var fields = useCurrentFields();
122
+ var inputRef = useRef();
123
+
124
+ var _useState = useState(false),
125
+ _useState2 = _slicedToArray(_useState, 2),
126
+ changed = _useState2[0],
127
+ setChanged = _useState2[1];
128
+
129
+ var onChange = function onChange(value) {
130
+ setChanged(true);
131
+ props.onChange(value);
132
+ };
133
+
134
+ var numColumns = new Map();
135
+ var scope = {};
136
+ fields.filter(function (field) {
137
+ return supports.includes(field.interface);
138
+ }).forEach(function (field) {
139
+ numColumns.set(field.name, field.uiSchema.title);
140
+ scope[field.name] = 1;
141
+ });
142
+ var keys = Array.from(numColumns.keys());
143
+
144
+ var _useState3 = useState(function () {
145
+ var scope = {};
146
+
147
+ var _iterator2 = _createForOfIteratorHelper(keys),
148
+ _step2;
149
+
150
+ try {
151
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
152
+ var key = _step2.value;
153
+ var val = numColumns.get(key);
154
+ scope[key] = " <span class=\"ant-tag\" style=\"margin: 0 3px;\" contentEditable=\"false\" data-key=\"".concat(key, "\">").concat(val, "</span> ");
155
+ }
156
+ } catch (err) {
157
+ _iterator2.e(err);
158
+ } finally {
159
+ _iterator2.f();
160
+ }
161
+
162
+ return renderExp(value || '', scope);
163
+ }),
164
+ _useState4 = _slicedToArray(_useState3, 2),
165
+ html = _useState4[0],
166
+ setHtml = _useState4[1];
167
+
168
+ useEffect(function () {
169
+ if (changed) {
170
+ return;
171
+ }
172
+
173
+ var scope = {};
174
+
175
+ var _iterator3 = _createForOfIteratorHelper(keys),
176
+ _step3;
177
+
178
+ try {
179
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
180
+ var key = _step3.value;
181
+
182
+ var _val = numColumns.get(key);
183
+
184
+ scope[key] = " <span class=\"ant-tag\" style=\"margin: 0 3px;\" contentEditable=\"false\" data-key=\"".concat(key, "\">").concat(_val, "</span> ");
185
+ }
186
+ } catch (err) {
187
+ _iterator3.e(err);
188
+ } finally {
189
+ _iterator3.f();
190
+ }
191
+
192
+ var val = renderExp(value || '', scope);
193
+ setHtml(val);
194
+ }, [value]);
195
+ var menu = /*#__PURE__*/React.createElement(Menu, null, keys.length > 0 ? keys.map(function (key) {
196
+ return /*#__PURE__*/React.createElement(Menu.Item, {
197
+ disabled: true,
198
+ key: key
199
+ }, /*#__PURE__*/React.createElement("button", {
200
+ onClick: function () {
201
+ var _onClick = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(args) {
202
+ var val, text;
203
+ return regeneratorRuntime.wrap(function _callee$(_context) {
204
+ while (1) {
205
+ switch (_context.prev = _context.next) {
206
+ case 0:
207
+ inputRef.current.focus();
208
+ val = numColumns.get(key);
209
+ pasteHtml(" <span class=\"ant-tag\" style=\"margin: 0 3px;\" contentEditable=\"false\" data-key=\"".concat(key, "\">").concat(val, "</span> "));
210
+ text = getValue(inputRef.current);
211
+ onChange(text);
212
+ console.log('onChange', text);
213
+
214
+ case 6:
215
+ case "end":
216
+ return _context.stop();
217
+ }
218
+ }
219
+ }, _callee);
220
+ }));
221
+
222
+ function onClick(_x) {
223
+ return _onClick.apply(this, arguments);
224
+ }
225
+
226
+ return onClick;
227
+ }()
228
+ }, numColumns.get(key)));
229
+ }) : /*#__PURE__*/React.createElement(Menu.Item, {
230
+ disabled: true,
231
+ key: 0
232
+ }, t('No available fields')));
233
+ useFormEffects(function () {
234
+ onFormSubmitValidateStart(function () {
235
+ try {
236
+ evaluate(field.value, scope);
237
+ field.feedbacks = [];
238
+ } catch (e) {
239
+ console.error(field.value, scope, e.message);
240
+ field.setFeedback({
241
+ type: 'error',
242
+ code: 'FormulaError',
243
+ messages: [t('Formula error.')]
244
+ });
245
+ }
246
+ });
247
+ });
248
+ return /*#__PURE__*/React.createElement(Dropdown, {
249
+ trigger: ['click'],
250
+ overlay: menu,
251
+ overlayClassName: css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n .ant-dropdown-menu-item {\n padding: 0;\n }\n button {\n cursor: pointer;\n padding: 5px 12px;\n text-align: left;\n color: rgba(0, 0, 0, 0.85);\n width: 100%;\n line-height: inherit;\n height: auto;\n border: 0px;\n background-color: transparent;\n &:hover {\n background-color: #f5f5f5;\n }\n }\n "])))
252
+ }, /*#__PURE__*/React.createElement("div", {
253
+ onKeyDown: function onKeyDown(e) {
254
+ var text = getValue(e.currentTarget);
255
+
256
+ if (e.key === 'Backspace') {
257
+ if (text && keys.map(function (k) {
258
+ return "{{".concat(k, "}}");
259
+ }).includes(text)) {
260
+ inputRef.current.innerHTML = ' ';
261
+ }
262
+ }
263
+ },
264
+ onKeyUp: function onKeyUp(e) {
265
+ var text = getValue(e.currentTarget);
266
+
267
+ if (e.key === 'Backspace') {// pasteHtml(' ');
268
+ }
269
+
270
+ onChange(text);
271
+ },
272
+ // onClick={(e) => {
273
+ // const text = getValue(e.currentTarget);
274
+ // onChange(text);
275
+ // console.log('onChange', text);
276
+ // }}
277
+ onBlur: function onBlur(e) {
278
+ var text = getValue(e.currentTarget);
279
+ onChange(text);
280
+ },
281
+ onInput: function onInput(e) {
282
+ var text = getValue(e.currentTarget);
283
+ onChange(text);
284
+ },
285
+ className: 'ant-input',
286
+ style: {
287
+ display: 'block'
288
+ },
289
+ ref: inputRef,
290
+ contentEditable: true,
291
+ dangerouslySetInnerHTML: {
292
+ __html: html
293
+ }
294
+ }));
295
+ };
296
+ export default Expression;
@@ -0,0 +1,2 @@
1
+ export declare const Result: (props: any) => JSX.Element;
2
+ export default Result;
@@ -0,0 +1,91 @@
1
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
2
+
3
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
4
+
5
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
+
7
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
8
+
9
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
10
+
11
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
12
+
13
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
14
+
15
+ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
16
+
17
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
18
+
19
+ import { onFormValuesChange } from '@formily/core';
20
+ import { useField, useFieldSchema, useForm, useFormEffects } from '@formily/react';
21
+ import { toFixedByStep } from '@nocobase/utils/client';
22
+ import cloneDeep from 'lodash/cloneDeep';
23
+ import * as math from 'mathjs';
24
+ import { isNumber } from 'mathjs';
25
+ import React, { useState } from 'react';
26
+ import { useCollection } from '../collection-manager';
27
+
28
+ var ReadPretty = function ReadPretty(props) {
29
+ var _props$options;
30
+
31
+ if ((props === null || props === void 0 ? void 0 : (_props$options = props.options) === null || _props$options === void 0 ? void 0 : _props$options.dataType) !== 'string') {
32
+ return /*#__PURE__*/React.createElement("div", null, toFixedByStep(props.value, props.step));
33
+ }
34
+
35
+ return /*#__PURE__*/React.createElement("div", null, props.value);
36
+ };
37
+
38
+ var Input = function Input(props) {
39
+ var evaluate = props.evaluate,
40
+ options = props.options;
41
+ var dataType = options.dataType,
42
+ expression = options.expression;
43
+ var form = useForm();
44
+
45
+ var val = function val() {
46
+ var scope = cloneDeep(form.values);
47
+
48
+ try {
49
+ var result = evaluate(expression, scope);
50
+ result = isNumber(result) && Number.isFinite(result) ? math.round(result, 9) : result;
51
+ return result;
52
+ } catch (error) {
53
+ return null;
54
+ }
55
+ };
56
+
57
+ var _useState = useState(function () {
58
+ return val();
59
+ }),
60
+ _useState2 = _slicedToArray(_useState, 2),
61
+ value = _useState2[0],
62
+ setVal = _useState2[1];
63
+
64
+ useFormEffects(function () {
65
+ onFormValuesChange(function () {
66
+ setVal(val());
67
+ });
68
+ });
69
+
70
+ if (dataType !== 'string') {
71
+ return /*#__PURE__*/React.createElement("div", null, toFixedByStep(value, props.step));
72
+ }
73
+
74
+ return /*#__PURE__*/React.createElement("div", null, value);
75
+ };
76
+
77
+ export var Result = function Result(props) {
78
+ var field = useField();
79
+
80
+ var _useCollection = useCollection(),
81
+ getField = _useCollection.getField;
82
+
83
+ var fieldSchema = useFieldSchema();
84
+ var options = getField(fieldSchema.name);
85
+ return field.readPretty ? /*#__PURE__*/React.createElement(ReadPretty, _objectSpread(_objectSpread({}, props), {}, {
86
+ options: options
87
+ })) : /*#__PURE__*/React.createElement(Input, _objectSpread(_objectSpread({}, props), {}, {
88
+ options: options
89
+ }));
90
+ };
91
+ export default Result;
@@ -0,0 +1,6 @@
1
+ export declare const Formula: {
2
+ (): any;
3
+ Result: (props: any) => JSX.Element;
4
+ Expression: (props: any) => JSX.Element;
5
+ };
6
+ export default Formula;
@@ -0,0 +1,8 @@
1
+ import Expression from './Expression';
2
+ import Result from './Result';
3
+ export var Formula = function Formula() {
4
+ return null;
5
+ };
6
+ Formula.Result = Result;
7
+ Formula.Expression = Expression;
8
+ export default Formula;
package/es/i18n/i18n.js CHANGED
@@ -1,5 +1,4 @@
1
1
  import i18next from 'i18next';
2
- import moment from 'moment';
3
2
  import { initReactI18next } from 'react-i18next';
4
3
  import locale from '../locale';
5
4
 
@@ -10,26 +9,22 @@ var resources = {};
10
9
  Object.keys(locale).forEach(function (lang) {
11
10
  resources[lang] = locale[lang].resources;
12
11
  });
13
- i18n.use(initReactI18next).init({
12
+ i18n // .use(Backend)
13
+ .use(initReactI18next).init({
14
14
  lng: localStorage.getItem('NOCOBASE_LOCALE') || 'en-US',
15
15
  // debug: true,
16
16
  defaultNS: 'client',
17
+ // backend: {
18
+ // // for all available options read the backend's repository readme file
19
+ // loadPath: '/api/locales/{{lng}}/{{ns}}.json',
20
+ // },
17
21
  // parseMissingKeyHandler: (key) => {
18
22
  // console.log('parseMissingKeyHandler', `'${key}': '${key}',`);
19
23
  // return key;
20
24
  // },
21
25
  // ns: ['client'],
22
- resources: resources
26
+ resources: {}
23
27
  });
24
-
25
- function setMomentLng(language) {
26
- var lng = locale[language || 'en-US'].moment || 'en';
27
- log(lng);
28
- moment.locale(lng);
29
- }
30
-
31
- setMomentLng(localStorage.getItem('NOCOBASE_LOCALE'));
32
28
  i18n.on('languageChanged', function (lng) {
33
29
  localStorage.setItem('NOCOBASE_LOCALE', lng);
34
- setMomentLng(lng);
35
30
  });
package/es/index.d.ts CHANGED
@@ -3,6 +3,7 @@ import './global.less';
3
3
  export * from './acl';
4
4
  export * from './antd-config-provider';
5
5
  export * from './api-client';
6
+ export * from './appInfo';
6
7
  export * from './application';
7
8
  export * from './async-data-provider';
8
9
  export * from './block-provider';
@@ -10,6 +11,7 @@ export * from './board';
10
11
  export * from './china-region';
11
12
  export * from './collection-manager';
12
13
  export * from './document-title';
14
+ export * from './formula';
13
15
  export * from './i18n';
14
16
  export * from './icon';
15
17
  export * from './plugin-manager';
@@ -24,4 +26,3 @@ export * from './schema-templates';
24
26
  export * from './settings-form';
25
27
  export * from './system-settings';
26
28
  export * from './user';
27
- export * from './appInfo';
package/es/index.js CHANGED
@@ -3,6 +3,7 @@ import './global.less';
3
3
  export * from './acl';
4
4
  export * from './antd-config-provider';
5
5
  export * from './api-client';
6
+ export * from './appInfo';
6
7
  export * from './application';
7
8
  export * from './async-data-provider';
8
9
  export * from './block-provider';
@@ -10,6 +11,7 @@ export * from './board';
10
11
  export * from './china-region';
11
12
  export * from './collection-manager';
12
13
  export * from './document-title';
14
+ export * from './formula';
13
15
  export * from './i18n';
14
16
  export * from './icon';
15
17
  export * from './plugin-manager';
@@ -23,5 +25,4 @@ export * from './schema-settings';
23
25
  export * from './schema-templates';
24
26
  export * from './settings-form';
25
27
  export * from './system-settings';
26
- export * from './user';
27
- export * from './appInfo';
28
+ export * from './user';