amis-core 1.0.0-beta.0

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 (211) hide show
  1. package/dist/Root.js +94 -0
  2. package/dist/RootRenderer.js +288 -0
  3. package/dist/SchemaRenderer.js +323 -0
  4. package/dist/Scoped.js +252 -0
  5. package/dist/WithRootStore.js +44 -0
  6. package/dist/WithStore.js +179 -0
  7. package/dist/__tests__/compat.test.d.ts +1 -0
  8. package/dist/__tests__/factory.test.d.ts +1 -0
  9. package/dist/__tests__/filter.test.d.ts +1 -0
  10. package/dist/__tests__/helper.d.ts +13 -0
  11. package/dist/__tests__/tokenize.test.d.ts +1 -0
  12. package/dist/actions/Action.js +119 -0
  13. package/dist/actions/AjaxAction.js +96 -0
  14. package/dist/actions/BreakAction.js +35 -0
  15. package/dist/actions/BroadcastAction.js +49 -0
  16. package/dist/actions/CmptAction.js +60 -0
  17. package/dist/actions/ContinueAction.js +35 -0
  18. package/dist/actions/CopyAction.js +43 -0
  19. package/dist/actions/CustomAction.js +49 -0
  20. package/dist/actions/DialogAction.js +104 -0
  21. package/dist/actions/DrawerAction.js +66 -0
  22. package/dist/actions/EmailAction.js +48 -0
  23. package/dist/actions/LinkAction.js +52 -0
  24. package/dist/actions/LoopAction.js +107 -0
  25. package/dist/actions/PageAction.js +80 -0
  26. package/dist/actions/ParallelAction.js +40 -0
  27. package/dist/actions/SwitchAction.js +52 -0
  28. package/dist/actions/ToastAction.js +35 -0
  29. package/dist/components/LazyComponent.js +99 -0
  30. package/dist/env.js +20 -0
  31. package/dist/envOverwrite.js +43 -0
  32. package/dist/factory.js +308 -0
  33. package/dist/index.js +218 -0
  34. package/dist/index2.js +255 -0
  35. package/dist/locale.js +114 -0
  36. package/dist/renderers/Form.js +1162 -0
  37. package/dist/renderers/Item.js +636 -0
  38. package/dist/renderers/Options.js +881 -0
  39. package/dist/renderers/Placeholder.js +31 -0
  40. package/dist/renderers/builtin.js +27 -0
  41. package/dist/renderers/wrapControl.js +507 -0
  42. package/dist/src/Root.d.ts +37 -0
  43. package/dist/src/RootRenderer.d.ts +27 -0
  44. package/dist/src/SchemaRenderer.d.ts +37 -0
  45. package/dist/src/Scoped.d.ts +38 -0
  46. package/dist/src/WithRootStore.d.ts +737 -0
  47. package/dist/src/WithStore.d.ts +5 -0
  48. package/dist/src/actions/Action.d.ts +38 -0
  49. package/dist/src/actions/AjaxAction.d.ts +25 -0
  50. package/dist/src/actions/BreakAction.d.ts +15 -0
  51. package/dist/src/actions/BroadcastAction.d.ts +16 -0
  52. package/dist/src/actions/CmptAction.d.ts +20 -0
  53. package/dist/src/actions/ContinueAction.d.ts +15 -0
  54. package/dist/src/actions/CopyAction.d.ts +20 -0
  55. package/dist/src/actions/CustomAction.d.ts +17 -0
  56. package/dist/src/actions/Decorators.d.ts +25 -0
  57. package/dist/src/actions/DialogAction.d.ts +57 -0
  58. package/dist/src/actions/DrawerAction.d.ts +30 -0
  59. package/dist/src/actions/EmailAction.d.ts +23 -0
  60. package/dist/src/actions/LinkAction.d.ts +24 -0
  61. package/dist/src/actions/LoopAction.d.ts +19 -0
  62. package/dist/src/actions/PageAction.d.ts +39 -0
  63. package/dist/src/actions/ParallelAction.d.ts +8 -0
  64. package/dist/src/actions/SwitchAction.d.ts +11 -0
  65. package/dist/src/actions/ToastAction.d.ts +19 -0
  66. package/dist/src/actions/index.d.ts +21 -0
  67. package/dist/src/components/LazyComponent.d.ts +32 -0
  68. package/dist/src/env.d.ts +172 -0
  69. package/dist/src/envOverwrite.d.ts +4 -0
  70. package/dist/src/factory.d.ts +78 -0
  71. package/dist/src/index.d.ts +25 -0
  72. package/dist/src/locale.d.ts +82 -0
  73. package/dist/src/renderers/Form.d.ts +352 -0
  74. package/dist/src/renderers/Item.d.ts +795 -0
  75. package/dist/src/renderers/Options.d.ts +150 -0
  76. package/dist/src/renderers/Placeholder.d.ts +6 -0
  77. package/dist/src/renderers/builtin.d.ts +1 -0
  78. package/dist/src/renderers/wrapControl.d.ts +446 -0
  79. package/dist/src/schema.d.ts +369 -0
  80. package/dist/src/store/app.d.ts +89 -0
  81. package/dist/src/store/combo.d.ts +8504 -0
  82. package/dist/src/store/crud.d.ts +124 -0
  83. package/dist/src/store/form.d.ts +3394 -0
  84. package/dist/src/store/formItem.d.ts +130 -0
  85. package/dist/src/store/iRenderer.d.ts +46 -0
  86. package/dist/src/store/index.d.ts +105 -0
  87. package/dist/src/store/list.d.ts +270 -0
  88. package/dist/src/store/manager.d.ts +115 -0
  89. package/dist/src/store/modal.d.ts +84 -0
  90. package/dist/src/store/node.d.ts +22 -0
  91. package/dist/src/store/pagination.d.ts +58 -0
  92. package/dist/src/store/root.d.ts +79 -0
  93. package/dist/src/store/service.d.ts +71 -0
  94. package/dist/src/store/table-v2.d.ts +309 -0
  95. package/dist/src/store/table.d.ts +8334 -0
  96. package/dist/src/theme.d.ts +83 -0
  97. package/dist/src/types.d.ts +217 -0
  98. package/dist/src/utils/Animation.d.ts +22 -0
  99. package/dist/src/utils/ColorScale.d.ts +19 -0
  100. package/dist/src/utils/DataSchema.d.ts +25 -0
  101. package/dist/src/utils/DataScope.d.ts +23 -0
  102. package/dist/src/utils/RootClose.d.ts +4 -0
  103. package/dist/src/utils/SimpleMap.d.ts +8 -0
  104. package/dist/src/utils/api.d.ts +27 -0
  105. package/dist/src/utils/attachmentAdpator.d.ts +7 -0
  106. package/dist/src/utils/autobind.d.ts +7 -0
  107. package/dist/src/utils/columnsSplit.d.ts +1 -0
  108. package/dist/src/utils/dataMapping.d.ts +3 -0
  109. package/dist/src/utils/date.d.ts +4 -0
  110. package/dist/src/utils/debug.d.ts +26 -0
  111. package/dist/src/utils/dom.d.ts +13 -0
  112. package/dist/src/utils/errors.d.ts +6 -0
  113. package/dist/src/utils/escapeHtml.d.ts +1 -0
  114. package/dist/src/utils/filter-schema.d.ts +12 -0
  115. package/dist/src/utils/filter.d.ts +1 -0
  116. package/dist/src/utils/formatDuration.d.ts +1 -0
  117. package/dist/src/utils/formula.d.ts +16 -0
  118. package/dist/src/utils/getVariable.d.ts +3 -0
  119. package/dist/src/utils/grammar.d.ts +4 -0
  120. package/dist/src/utils/handleAction.d.ts +6 -0
  121. package/dist/src/utils/helper.d.ts +286 -0
  122. package/dist/src/utils/icon.d.ts +12 -0
  123. package/dist/src/utils/image.d.ts +17 -0
  124. package/dist/src/utils/index.d.ts +12 -0
  125. package/dist/src/utils/isPureVariable.d.ts +1 -0
  126. package/dist/src/utils/json-schema-2-amis-schema.d.ts +6 -0
  127. package/dist/src/utils/keyToPath.d.ts +6 -0
  128. package/dist/src/utils/makeSorter.d.ts +1 -0
  129. package/dist/src/utils/markdown.d.ts +5 -0
  130. package/dist/src/utils/normalizeLink.d.ts +1 -0
  131. package/dist/src/utils/normalizeOptions.d.ts +7 -0
  132. package/dist/src/utils/object.d.ts +15 -0
  133. package/dist/src/utils/offset.d.ts +14 -0
  134. package/dist/src/utils/offsetParent.d.ts +4 -0
  135. package/dist/src/utils/optionValueCompare.d.ts +3 -0
  136. package/dist/src/utils/position.d.ts +15 -0
  137. package/dist/src/utils/prettyBytes.d.ts +1 -0
  138. package/dist/src/utils/renderer-event.d.ts +44 -0
  139. package/dist/src/utils/replaceText.d.ts +6 -0
  140. package/dist/src/utils/resize-sensor.d.ts +6 -0
  141. package/dist/src/utils/resolveVariable.d.ts +1 -0
  142. package/dist/src/utils/resolveVariableAndFilter.d.ts +1 -0
  143. package/dist/src/utils/scrollPosition.d.ts +6 -0
  144. package/dist/src/utils/string2regExp.d.ts +1 -0
  145. package/dist/src/utils/stripNumber.d.ts +1 -0
  146. package/dist/src/utils/style.d.ts +10 -0
  147. package/dist/src/utils/tokenize.d.ts +1 -0
  148. package/dist/src/utils/tpl-builtin.d.ts +18 -0
  149. package/dist/src/utils/tpl-lodash.d.ts +4 -0
  150. package/dist/src/utils/tpl.d.ts +11 -0
  151. package/dist/src/utils/validations.d.ts +39 -0
  152. package/dist/store/app.js +190 -0
  153. package/dist/store/combo.js +154 -0
  154. package/dist/store/crud.js +413 -0
  155. package/dist/store/form.js +579 -0
  156. package/dist/store/formItem.js +846 -0
  157. package/dist/store/iRenderer.js +189 -0
  158. package/dist/store/index.js +103 -0
  159. package/dist/store/list.js +248 -0
  160. package/dist/store/manager.js +56 -0
  161. package/dist/store/modal.js +54 -0
  162. package/dist/store/node.js +93 -0
  163. package/dist/store/pagination.js +60 -0
  164. package/dist/store/root.js +45 -0
  165. package/dist/store/service.js +415 -0
  166. package/dist/store/table-v2.js +471 -0
  167. package/dist/store/table.js +1105 -0
  168. package/dist/theme.js +93 -0
  169. package/dist/tsconfig.tsbuildinfo +1 -0
  170. package/dist/utils/Animation.js +290 -0
  171. package/dist/utils/DataSchema.js +120 -0
  172. package/dist/utils/DataScope.js +151 -0
  173. package/dist/utils/SimpleMap.js +46 -0
  174. package/dist/utils/api.js +555 -0
  175. package/dist/utils/autobind.js +94 -0
  176. package/dist/utils/dataMapping.js +136 -0
  177. package/dist/utils/date.js +90 -0
  178. package/dist/utils/debug.js +343 -0
  179. package/dist/utils/errors.js +23 -0
  180. package/dist/utils/escapeHtml.js +24 -0
  181. package/dist/utils/filter-schema.js +75 -0
  182. package/dist/utils/filter.js +481 -0
  183. package/dist/utils/formatDuration.js +27 -0
  184. package/dist/utils/formula.js +165 -0
  185. package/dist/utils/getVariable.js +29 -0
  186. package/dist/utils/grammar.js +54 -0
  187. package/dist/utils/helper.js +1283 -0
  188. package/dist/utils/isPureVariable.js +16 -0
  189. package/dist/utils/keyToPath.js +34 -0
  190. package/dist/utils/makeSorter.js +30 -0
  191. package/dist/utils/normalizeLink.js +47 -0
  192. package/dist/utils/normalizeOptions.js +92 -0
  193. package/dist/utils/object.js +156 -0
  194. package/dist/utils/offset.js +36 -0
  195. package/dist/utils/offsetParent.js +27 -0
  196. package/dist/utils/optionValueCompare.js +25 -0
  197. package/dist/utils/position.js +50 -0
  198. package/dist/utils/prettyBytes.js +28 -0
  199. package/dist/utils/renderer-event.js +131 -0
  200. package/dist/utils/replaceText.js +35 -0
  201. package/dist/utils/resize-sensor.js +177 -0
  202. package/dist/utils/resolveVariable.js +39 -0
  203. package/dist/utils/resolveVariableAndFilter.js +37 -0
  204. package/dist/utils/string2regExp.js +18 -0
  205. package/dist/utils/stripNumber.js +20 -0
  206. package/dist/utils/tokenize.js +33 -0
  207. package/dist/utils/tpl-builtin.js +71 -0
  208. package/dist/utils/tpl-lodash.js +71 -0
  209. package/dist/utils/tpl.js +140 -0
  210. package/dist/utils/validations.js +377 -0
  211. package/package.json +121 -0
@@ -0,0 +1,75 @@
1
+ /**
2
+ * amis-core v1.0.0-beta.0
3
+ * Copyright 2018-2022 fex
4
+ */
5
+
6
+ 'use strict';
7
+
8
+ Object.defineProperty(exports, '__esModule', { value: true });
9
+
10
+ var tpl = require('./tpl.js');
11
+ var helper = require('./helper.js');
12
+ var isPlainObject = require('lodash/isPlainObject');
13
+ var cx = require('classnames');
14
+
15
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
16
+
17
+ var isPlainObject__default = /*#__PURE__*/_interopDefaultLegacy(isPlainObject);
18
+ var cx__default = /*#__PURE__*/_interopDefaultLegacy(cx);
19
+
20
+ /**
21
+ * 处理 Props 数据,所有带 On 结束的做一次
22
+ *
23
+ * xxxOn
24
+ * xxxExpr
25
+ *
26
+ *
27
+ * @param schema
28
+ * @param data
29
+ */
30
+ function getExprProperties(schema, data, blackList, props) {
31
+ if (data === void 0) { data = {}; }
32
+ if (blackList === void 0) { blackList = ['addOn']; }
33
+ var exprProps = {};
34
+ var ctx = null;
35
+ Object.getOwnPropertyNames(schema).forEach(function (key) {
36
+ if (blackList && ~blackList.indexOf(key)) {
37
+ return;
38
+ }
39
+ var parts = /^(.*)(On|Expr|(?:c|C)lassName)(Raw)?$/.exec(key);
40
+ var value = schema[key];
41
+ if (value &&
42
+ typeof value === 'string' &&
43
+ (parts === null || parts === void 0 ? void 0 : parts[1]) &&
44
+ (parts[2] === 'On' || parts[2] === 'Expr')) {
45
+ key = parts[1];
46
+ if (parts[2] === 'On' || parts[2] === 'Expr') {
47
+ if (!ctx &&
48
+ props &&
49
+ typeof value === 'string' &&
50
+ ~value.indexOf('__props')) {
51
+ ctx = helper.injectPropsToObject(data, {
52
+ __props: props
53
+ });
54
+ }
55
+ value =
56
+ parts[2] === 'On'
57
+ ? tpl.evalExpression(value, ctx || data)
58
+ : tpl.filter(value, ctx || data);
59
+ }
60
+ exprProps[key] = value;
61
+ }
62
+ else if (value &&
63
+ isPlainObject__default["default"](value) &&
64
+ ((parts === null || parts === void 0 ? void 0 : parts[2]) === 'className' || (parts === null || parts === void 0 ? void 0 : parts[2]) === 'ClassName')) {
65
+ key = parts[1] + parts[2];
66
+ exprProps["".concat(key, "Raw")] = value;
67
+ exprProps[key] = cx__default["default"](helper.mapObject(value, function (value) {
68
+ return typeof value === 'string' ? tpl.evalExpression(value, data) : value;
69
+ }));
70
+ }
71
+ });
72
+ return exprProps;
73
+ }
74
+
75
+ exports["default"] = getExprProperties;
@@ -0,0 +1,481 @@
1
+ /**
2
+ * amis-core v1.0.0-beta.0
3
+ * Copyright 2018-2022 fex
4
+ */
5
+
6
+ 'use strict';
7
+
8
+ var tslib = require('tslib');
9
+ var amisFormula = require('amis-formula');
10
+ var moment = require('moment');
11
+ var makeSorter = require('./makeSorter.js');
12
+ var transform = require('lodash/transform');
13
+ var groupBy = require('lodash/groupBy');
14
+ var uniqBy = require('lodash/uniqBy');
15
+ var uniq = require('lodash/uniq');
16
+ var object = require('./object.js');
17
+ var string2regExp = require('./string2regExp.js');
18
+ var resolveVariable = require('./resolveVariable.js');
19
+ var escapeHtml = require('./escapeHtml.js');
20
+ var formatDuration = require('./formatDuration.js');
21
+ var prettyBytes = require('./prettyBytes.js');
22
+ var stripNumber = require('./stripNumber.js');
23
+ var date = require('./date.js');
24
+
25
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
26
+
27
+ var moment__default = /*#__PURE__*/_interopDefaultLegacy(moment);
28
+ var transform__default = /*#__PURE__*/_interopDefaultLegacy(transform);
29
+ var groupBy__default = /*#__PURE__*/_interopDefaultLegacy(groupBy);
30
+ var uniqBy__default = /*#__PURE__*/_interopDefaultLegacy(uniqBy);
31
+ var uniq__default = /*#__PURE__*/_interopDefaultLegacy(uniq);
32
+
33
+ function conditionalFilter(input, hasAlternate, filterContext, test, trueValue, falseValue) {
34
+ var _a, _b, _c;
35
+ (hasAlternate || test) && skipRestTest(filterContext.restFilters);
36
+ var result = test ? trueValue : falseValue;
37
+ var ast = test
38
+ ? (_a = filterContext.filter) === null || _a === void 0 ? void 0 : _a.args[1]
39
+ : (_b = filterContext.filter) === null || _b === void 0 ? void 0 : _b.args[2];
40
+ return test || hasAlternate
41
+ ? (_c = getStrOrVariable(result, filterContext.data, ast)) !== null && _c !== void 0 ? _c : result
42
+ : input;
43
+ }
44
+ /**
45
+ * 如果当前传入字符为:'xxx'或者"xxx",则返回字符xxx
46
+ * 否则去数据域中,获取变量xxx
47
+ *
48
+ * @param value 传入字符
49
+ * @param data 数据域
50
+ */
51
+ function getStrOrVariable(value, data, ast) {
52
+ // 通过读取 ast 来判断,只有 literal 才可能是变量,也可能是字符串
53
+ // 其他的直接返回值即可。
54
+ if ((ast === null || ast === void 0 ? void 0 : ast.type) && ast.type !== 'literal') {
55
+ return value;
56
+ }
57
+ return typeof value === 'string' && /,/.test(value)
58
+ ? value.split(/\s*,\s*/).filter(function (item) { return item; })
59
+ : typeof value === 'string'
60
+ ? resolveVariable.resolveVariable(value, data)
61
+ : value;
62
+ }
63
+ function str2array(list) {
64
+ if (list && typeof list === 'string') {
65
+ if (/^\[.*\]$/.test(list)) {
66
+ return list
67
+ .substring(1, list.length - 1)
68
+ .split(/\s*,\s*/)
69
+ .filter(function (item) { return item; });
70
+ }
71
+ else {
72
+ return list.split(/\s*,\s*/).filter(function (item) { return item; });
73
+ }
74
+ }
75
+ return list;
76
+ }
77
+ function skipRestTest(restFilters) {
78
+ var _a;
79
+ while (~[
80
+ 'isTrue',
81
+ 'isFalse',
82
+ 'isMatch',
83
+ 'isEquals',
84
+ 'notMatch',
85
+ 'notEquals'
86
+ ].indexOf((_a = restFilters[0]) === null || _a === void 0 ? void 0 : _a.name)) {
87
+ restFilters.shift();
88
+ }
89
+ }
90
+ amisFormula.extendsFilters({
91
+ map: function (input, fn) {
92
+ var _this = this;
93
+ var arg = [];
94
+ for (var _i = 2; _i < arguments.length; _i++) {
95
+ arg[_i - 2] = arguments[_i];
96
+ }
97
+ return Array.isArray(input) && amisFormula.filters[fn]
98
+ ? input.map(function (item) {
99
+ var _a;
100
+ return (_a = amisFormula.filters[fn]).call.apply(_a, tslib.__spreadArray([_this, item], arg, false));
101
+ })
102
+ : input;
103
+ },
104
+ html: function (input) {
105
+ if (input == null) {
106
+ return input;
107
+ }
108
+ return escapeHtml.escapeHtml(input);
109
+ },
110
+ json: function (input, tabSize) {
111
+ if (tabSize === void 0) { tabSize = 2; }
112
+ return tabSize
113
+ ? JSON.stringify(input, null, parseInt(tabSize, 10))
114
+ : JSON.stringify(input);
115
+ },
116
+ toJson: function (input) {
117
+ var ret;
118
+ try {
119
+ ret = JSON.parse(input);
120
+ }
121
+ catch (e) {
122
+ ret = null;
123
+ }
124
+ return ret;
125
+ },
126
+ toInt: function (input) { return (typeof input === 'string' ? parseInt(input, 10) : input); },
127
+ toFloat: function (input) { return (typeof input === 'string' ? parseFloat(input) : input); },
128
+ raw: function (input) { return input; },
129
+ now: function () { return new Date(); },
130
+ toDate: function (input, inputFormat) {
131
+ if (inputFormat === void 0) { inputFormat = ''; }
132
+ var date = moment__default["default"](input, inputFormat);
133
+ return date.isValid() ? date.toDate() : undefined;
134
+ },
135
+ fromNow: function (input, inputFormat) {
136
+ if (inputFormat === void 0) { inputFormat = ''; }
137
+ return moment__default["default"](input, inputFormat).fromNow();
138
+ },
139
+ dateModify: function (input, modifier, amount, unit) {
140
+ if (modifier === void 0) { modifier = 'add'; }
141
+ if (amount === void 0) { amount = 0; }
142
+ if (unit === void 0) { unit = 'days'; }
143
+ if (!(input instanceof Date)) {
144
+ input = new Date();
145
+ }
146
+ if (modifier === 'endOf' || modifier === 'startOf') {
147
+ return moment__default["default"](input)[modifier === 'endOf' ? 'endOf' : 'startOf'](amount || 'day')
148
+ .toDate();
149
+ }
150
+ return moment__default["default"](input)[modifier === 'add' ? 'add' : 'subtract'](parseInt(amount, 10) || 0, unit)
151
+ .toDate();
152
+ },
153
+ date: function (input, format, inputFormat) {
154
+ if (format === void 0) { format = 'LLL'; }
155
+ if (inputFormat === void 0) { inputFormat = 'X'; }
156
+ return moment__default["default"](input, inputFormat).format(format);
157
+ },
158
+ number: function (input) {
159
+ var parts = String(input).split('.');
160
+ parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ',');
161
+ return parts.join('.');
162
+ },
163
+ trim: function (input) { return (typeof input === 'string' ? input.trim() : input); },
164
+ percent: function (input, decimals) {
165
+ if (decimals === void 0) { decimals = 0; }
166
+ input = parseFloat(input) || 0;
167
+ decimals = parseInt(decimals, 10) || 0;
168
+ var whole = input * 100;
169
+ var multiplier = Math.pow(10, decimals);
170
+ return ((Math.round(whole * multiplier) / multiplier).toFixed(decimals) + '%');
171
+ },
172
+ duration: function (input) { return (input ? formatDuration.formatDuration(input) : input); },
173
+ bytes: function (input) { return (input ? prettyBytes.prettyBytes(parseFloat(input)) : input); },
174
+ round: function (input, decimals) {
175
+ var _a;
176
+ if (decimals === void 0) { decimals = 2; }
177
+ if (isNaN(input)) {
178
+ return 0;
179
+ }
180
+ decimals = (_a = parseInt(decimals, 10)) !== null && _a !== void 0 ? _a : 2;
181
+ var multiplier = Math.pow(10, decimals);
182
+ return (Math.round(input * multiplier) / multiplier).toFixed(decimals);
183
+ },
184
+ truncate: function (input, length, end) {
185
+ if (typeof input !== 'string') {
186
+ return input;
187
+ }
188
+ end = end || '...';
189
+ if (length == null) {
190
+ return input;
191
+ }
192
+ length = parseInt(length, 10) || 200;
193
+ return input.substring(0, length) + (input.length > length ? end : '');
194
+ },
195
+ url_encode: function (input) {
196
+ if (input == null) {
197
+ return '';
198
+ }
199
+ return encodeURIComponent(input);
200
+ },
201
+ url_decode: function (input) { return decodeURIComponent(input); },
202
+ default: function (input, defaultValue, strict) {
203
+ var _a;
204
+ if (strict === void 0) { strict = false; }
205
+ return (_a = (strict ? input : input ? input : undefined)) !== null && _a !== void 0 ? _a : (function () {
206
+ try {
207
+ if (defaultValue === 'undefined') {
208
+ return undefined;
209
+ }
210
+ return JSON.parse(defaultValue);
211
+ }
212
+ catch (e) {
213
+ return defaultValue;
214
+ }
215
+ })();
216
+ },
217
+ join: function (input, glue) { return (input && input.join ? input.join(glue) : input); },
218
+ split: function (input, delimiter) {
219
+ if (delimiter === void 0) { delimiter = ','; }
220
+ return typeof input === 'string' ? input.split(delimiter) : input;
221
+ },
222
+ sortBy: function (input, key, method, order) {
223
+ if (key === void 0) { key = '&'; }
224
+ if (method === void 0) { method = 'alpha'; }
225
+ return Array.isArray(input) ? input.sort(makeSorter.makeSorter(key, method, order)) : input;
226
+ },
227
+ objectToArray: function (input, label, value) {
228
+ if (label === void 0) { label = 'label'; }
229
+ if (value === void 0) { value = 'value'; }
230
+ return transform__default["default"](input, function (result, v, k) {
231
+ var _a;
232
+ (result || (result = [])).push((_a = {},
233
+ _a[label] = v,
234
+ _a[value] = k,
235
+ _a));
236
+ }, []);
237
+ },
238
+ unique: function (input, key) {
239
+ return Array.isArray(input) ? (key ? uniqBy__default["default"](input, key) : uniq__default["default"](input)) : input;
240
+ },
241
+ topAndOther: function (input, len, labelField, restLabel) {
242
+ if (len === void 0) { len = 10; }
243
+ if (labelField === void 0) { labelField = 'name'; }
244
+ if (restLabel === void 0) { restLabel = '其他'; }
245
+ if (Array.isArray(input) && len) {
246
+ var grouped_1 = groupBy__default["default"](input, function (item) {
247
+ var index = input.indexOf(item) + 1;
248
+ return index >= len ? len : index;
249
+ });
250
+ return Object.keys(grouped_1).map(function (key, index) {
251
+ var group = grouped_1[key];
252
+ var obj = group.reduce(function (obj, item) {
253
+ Object.keys(item).forEach(function (key) {
254
+ if (!obj.hasOwnProperty(key) || key === 'labelField') {
255
+ obj[key] = item[key];
256
+ }
257
+ else if (typeof item[key] === 'number' &&
258
+ typeof obj[key] === 'number') {
259
+ obj[key] += item[key];
260
+ }
261
+ else if (typeof item[key] === 'string' &&
262
+ /^(?:\-|\.)\d/.test(item[key]) &&
263
+ typeof obj[key] === 'number') {
264
+ obj[key] += parseFloat(item[key]) || 0;
265
+ }
266
+ else if (typeof item[key] === 'string' &&
267
+ typeof obj[key] === 'string') {
268
+ obj[key] += ", ".concat(item[key]);
269
+ }
270
+ else {
271
+ obj[key] = item[key];
272
+ }
273
+ });
274
+ return obj;
275
+ }, {});
276
+ if (index === len - 1) {
277
+ obj[labelField] = restLabel || '其他';
278
+ }
279
+ return obj;
280
+ });
281
+ }
282
+ return input;
283
+ },
284
+ first: function (input) { return input && input[0]; },
285
+ nth: function (input, nth) {
286
+ if (nth === void 0) { nth = 0; }
287
+ return input && input[nth];
288
+ },
289
+ last: function (input) { return input && (input.length ? input[input.length - 1] : null); },
290
+ minus: function (input, step) {
291
+ var _a;
292
+ if (step === void 0) { step = 1; }
293
+ return stripNumber.stripNumber((Number(input) || 0) -
294
+ Number(getStrOrVariable(step, this.data, (_a = this.filter) === null || _a === void 0 ? void 0 : _a.args[0])));
295
+ },
296
+ plus: function (input, step) {
297
+ var _a;
298
+ if (step === void 0) { step = 1; }
299
+ return stripNumber.stripNumber((Number(input) || 0) +
300
+ Number(getStrOrVariable(step, this.data, (_a = this.filter) === null || _a === void 0 ? void 0 : _a.args[0])));
301
+ },
302
+ times: function (input, step) {
303
+ var _a;
304
+ if (step === void 0) { step = 1; }
305
+ return stripNumber.stripNumber((Number(input) || 0) *
306
+ Number(getStrOrVariable(step, this.data, (_a = this.filter) === null || _a === void 0 ? void 0 : _a.args[0])));
307
+ },
308
+ division: function (input, step) {
309
+ var _a;
310
+ if (step === void 0) { step = 1; }
311
+ return stripNumber.stripNumber((Number(input) || 0) /
312
+ Number(getStrOrVariable(step, this.data, (_a = this.filter) === null || _a === void 0 ? void 0 : _a.args[0])));
313
+ },
314
+ count: function (input) {
315
+ return Array.isArray(input) || typeof input === 'string' ? input.length : 0;
316
+ },
317
+ sum: function (input, field) {
318
+ if (!Array.isArray(input)) {
319
+ return input;
320
+ }
321
+ var restult = input.reduce(function (sum, item) {
322
+ return sum + (parseFloat(field ? object.pickValues(field, item) : item) || 0);
323
+ }, 0);
324
+ return stripNumber.stripNumber(restult);
325
+ },
326
+ abs: function (input) { return (typeof input === 'number' ? Math.abs(input) : input); },
327
+ pick: function (input, path) {
328
+ if (path === void 0) { path = '&'; }
329
+ return Array.isArray(input) && !/^\d+$/.test(path)
330
+ ? input.map(function (item, index) {
331
+ return object.pickValues(path, object.createObject({ index: index }, item));
332
+ })
333
+ : object.pickValues(path, input);
334
+ },
335
+ pick_if_exist: function (input, path) {
336
+ if (path === void 0) { path = '&'; }
337
+ return Array.isArray(input)
338
+ ? input.map(function (item) { return resolveVariable.resolveVariable(path, item) || item; })
339
+ : resolveVariable.resolveVariable(path, input) || input;
340
+ },
341
+ str2date: function (input, inputFormat, outputFormat) {
342
+ if (inputFormat === void 0) { inputFormat = 'X'; }
343
+ if (outputFormat === void 0) { outputFormat = 'X'; }
344
+ return input
345
+ ? date.filterDate(input, this.data, inputFormat).format(outputFormat)
346
+ : '';
347
+ },
348
+ asArray: function (input) { return (Array.isArray(input) ? input : input ? [input] : input); },
349
+ concat: function (input) {
350
+ var _this = this;
351
+ var args = [];
352
+ for (var _i = 1; _i < arguments.length; _i++) {
353
+ args[_i - 1] = arguments[_i];
354
+ }
355
+ return Array.isArray(input)
356
+ ? input.concat.apply(input, args.map(function (arg, index) { var _a; return getStrOrVariable(arg, _this.data, (_a = _this.filter) === null || _a === void 0 ? void 0 : _a.args[index]); })) : input;
357
+ },
358
+ filter: function (input, keys, expOrDirective, arg1) {
359
+ var _a, _b, _c, _d;
360
+ if (!Array.isArray(input) || !keys || !expOrDirective) {
361
+ return input;
362
+ }
363
+ var directive = expOrDirective;
364
+ var fn = function () { return true; };
365
+ if (directive === 'isTrue') {
366
+ fn = function (value) { return !!value; };
367
+ }
368
+ else if (directive === 'isFalse') {
369
+ fn = function (value) { return !value; };
370
+ }
371
+ else if (directive === 'isExists') {
372
+ fn = function (value) { return typeof value !== 'undefined'; };
373
+ }
374
+ else if (directive === 'equals' || directive === 'equal') {
375
+ arg1 = arg1
376
+ ? getStrOrVariable(arg1, this.data, (_a = this.filter) === null || _a === void 0 ? void 0 : _a.args[2])
377
+ : '';
378
+ fn = function (value) { return arg1 == value; };
379
+ }
380
+ else if (directive === 'isIn') {
381
+ var list_1 = arg1
382
+ ? getStrOrVariable(arg1, this.data, (_b = this.filter) === null || _b === void 0 ? void 0 : _b.args[2])
383
+ : [];
384
+ list_1 = str2array(list_1);
385
+ list_1 = Array.isArray(list_1) ? list_1 : list_1 ? [list_1] : [];
386
+ fn = function (value) { return (list_1.length ? !!~list_1.indexOf(value) : true); };
387
+ }
388
+ else if (directive === 'notIn') {
389
+ var list_2 = arg1
390
+ ? getStrOrVariable(arg1, this.data, (_c = this.filter) === null || _c === void 0 ? void 0 : _c.args[2])
391
+ : [];
392
+ list_2 = str2array(list_2);
393
+ list_2 = Array.isArray(list_2) ? list_2 : list_2 ? [list_2] : [];
394
+ fn = function (value) { return !~list_2.indexOf(value); };
395
+ }
396
+ else {
397
+ if (directive !== 'match') {
398
+ directive = 'match';
399
+ arg1 = expOrDirective;
400
+ }
401
+ arg1 = arg1
402
+ ? getStrOrVariable(arg1, this.data, (_d = this.filter) === null || _d === void 0 ? void 0 : _d.args[2])
403
+ : '';
404
+ // 比对的值是空时直接返回。
405
+ if (!arg1) {
406
+ return input;
407
+ }
408
+ var reg_1 = string2regExp.string2regExp("".concat(arg1), false);
409
+ fn = function (value) { return reg_1.test(String(value)); };
410
+ }
411
+ // 判断keys是否为*
412
+ var isAsterisk = /\s*\*\s*/.test(keys);
413
+ keys = keys.split(/\s*,\s*/);
414
+ return input.filter(function (item) {
415
+ // 当keys为*时从item中获取key
416
+ return (isAsterisk ? Object.keys(item) : keys).some(function (key) {
417
+ return fn(resolveVariable.resolveVariable(key, item), key, item);
418
+ });
419
+ });
420
+ },
421
+ base64Encode: function (str) {
422
+ return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, function toSolidBytes(match, p1) {
423
+ return String.fromCharCode(('0x' + p1));
424
+ }));
425
+ },
426
+ base64Decode: function (str) {
427
+ return decodeURIComponent(atob(str)
428
+ .split('')
429
+ .map(function (c) {
430
+ return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
431
+ })
432
+ .join(''));
433
+ },
434
+ substring: function (input, start, end) {
435
+ return input && typeof input === 'string'
436
+ ? input.substring(start, end)
437
+ : input;
438
+ },
439
+ lowerCase: function (input) {
440
+ return input && typeof input === 'string' ? input.toLowerCase() : input;
441
+ },
442
+ upperCase: function (input) {
443
+ return input && typeof input === 'string' ? input.toUpperCase() : input;
444
+ },
445
+ isTrue: function (input, trueValue, falseValue) {
446
+ var hasAlternate = arguments.length > 2;
447
+ return conditionalFilter(input, hasAlternate, this, !!input, trueValue, falseValue);
448
+ },
449
+ isFalse: function (input, trueValue, falseValue) {
450
+ var hasAlternate = arguments.length > 2;
451
+ return conditionalFilter(input, hasAlternate, this, !input, trueValue, falseValue);
452
+ },
453
+ isMatch: function (input, matchArg, trueValue, falseValue) {
454
+ var _a, _b;
455
+ var hasAlternate = arguments.length > 3;
456
+ matchArg =
457
+ (_b = getStrOrVariable(matchArg, this.data, (_a = this.filter) === null || _a === void 0 ? void 0 : _a.args[0])) !== null && _b !== void 0 ? _b : matchArg;
458
+ return conditionalFilter(input, hasAlternate, this, matchArg && string2regExp.string2regExp("".concat(matchArg), false).test(String(input)), trueValue, falseValue);
459
+ },
460
+ notMatch: function (input, matchArg, trueValue, falseValue) {
461
+ var _a, _b;
462
+ var hasAlternate = arguments.length > 3;
463
+ matchArg =
464
+ (_b = getStrOrVariable(matchArg, this.data, (_a = this.filter) === null || _a === void 0 ? void 0 : _a.args[0])) !== null && _b !== void 0 ? _b : matchArg;
465
+ return conditionalFilter(input, hasAlternate, this, matchArg && !string2regExp.string2regExp("".concat(matchArg), false).test(String(input)), trueValue, falseValue);
466
+ },
467
+ isEquals: function (input, equalsValue, trueValue, falseValue) {
468
+ var _a, _b;
469
+ equalsValue =
470
+ (_b = getStrOrVariable(equalsValue, this.data, (_a = this.filter) === null || _a === void 0 ? void 0 : _a.args[0])) !== null && _b !== void 0 ? _b : equalsValue;
471
+ var hasAlternate = arguments.length > 3;
472
+ return conditionalFilter(input, hasAlternate, this, input === equalsValue, trueValue, falseValue);
473
+ },
474
+ notEquals: function (input, equalsValue, trueValue, falseValue) {
475
+ var _a, _b;
476
+ equalsValue =
477
+ (_b = getStrOrVariable(equalsValue, this.data, (_a = this.filter) === null || _a === void 0 ? void 0 : _a.args[0])) !== null && _b !== void 0 ? _b : equalsValue;
478
+ var hasAlternate = arguments.length > 3;
479
+ return conditionalFilter(input, hasAlternate, this, input !== equalsValue, trueValue, falseValue);
480
+ }
481
+ });
@@ -0,0 +1,27 @@
1
+ /**
2
+ * amis-core v1.0.0-beta.0
3
+ * Copyright 2018-2022 fex
4
+ */
5
+
6
+ 'use strict';
7
+
8
+ Object.defineProperty(exports, '__esModule', { value: true });
9
+
10
+ function formatDuration(value) {
11
+ var unit = ['秒', '分', '时', '天', '月', '季', '年'];
12
+ var steps = [1, 60, 3600, 86400, 2592000, 7776000, 31104000];
13
+ var len = steps.length;
14
+ var parts = [];
15
+ while (len--) {
16
+ if (steps[len] && value >= steps[len]) {
17
+ parts.push(Math.floor(value / steps[len]) + unit[len]);
18
+ value %= steps[len];
19
+ }
20
+ else if (len === 0 && value) {
21
+ parts.push((value.toFixed ? value.toFixed(2) : '0') + unit[0]);
22
+ }
23
+ }
24
+ return parts.join('');
25
+ }
26
+
27
+ exports.formatDuration = formatDuration;