amis-core 2.8.0 → 2.9.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.
- package/esm/Root.d.ts +1 -1
- package/esm/Root.js +1 -1
- package/esm/RootRenderer.d.ts +1 -1
- package/esm/RootRenderer.js +21 -4
- package/esm/SchemaRenderer.d.ts +2 -1
- package/esm/SchemaRenderer.js +1 -1
- package/esm/Scoped.js +30 -2
- package/esm/WithRootStore.d.ts +4 -8
- package/esm/WithRootStore.js +1 -1
- package/esm/WithStore.js +1 -1
- package/esm/actions/Action.d.ts +2 -1
- package/esm/actions/Action.js +33 -11
- package/esm/actions/AjaxAction.js +1 -1
- package/esm/actions/BreakAction.js +1 -1
- package/esm/actions/BroadcastAction.js +1 -1
- package/esm/actions/CmptAction.js +1 -1
- package/esm/actions/ContinueAction.js +1 -1
- package/esm/actions/CopyAction.js +1 -1
- package/esm/actions/CustomAction.js +2 -1
- package/esm/actions/DialogAction.d.ts +1 -1
- package/esm/actions/DialogAction.js +8 -3
- package/esm/actions/DrawerAction.js +1 -1
- package/esm/actions/EmailAction.js +1 -1
- package/esm/actions/LinkAction.js +1 -1
- package/esm/actions/LoopAction.js +1 -1
- package/esm/actions/PageAction.js +1 -1
- package/esm/actions/ParallelAction.js +1 -1
- package/esm/actions/SwitchAction.js +18 -15
- package/esm/actions/ToastAction.js +1 -1
- package/esm/components/LazyComponent.d.ts +3 -3
- package/esm/components/LazyComponent.js +1 -1
- package/esm/components/Overlay.d.ts +1 -1
- package/esm/components/Overlay.js +2 -1
- package/esm/components/PopOver.d.ts +2 -4
- package/esm/components/PopOver.js +2 -1
- package/esm/env.d.ts +3 -7
- package/esm/env.js +1 -1
- package/esm/envOverwrite.js +1 -1
- package/esm/factory.js +3 -1
- package/esm/index.d.ts +2 -3
- package/esm/index.js +7 -5
- package/esm/locale.d.ts +1 -3
- package/esm/locale.js +1 -1
- package/esm/renderers/Form.js +17 -15
- package/esm/renderers/Item.d.ts +9 -15
- package/esm/renderers/Item.js +2 -1
- package/esm/renderers/Options.js +2 -1
- package/esm/renderers/Placeholder.js +1 -1
- package/esm/renderers/builtin.js +1 -1
- package/esm/renderers/register.js +1 -1
- package/esm/renderers/wrapControl.d.ts +4 -8
- package/esm/renderers/wrapControl.js +21 -30
- package/esm/store/app.d.ts +4 -2
- package/esm/store/app.js +1 -1
- package/esm/store/combo.d.ts +12 -6
- package/esm/store/combo.js +1 -1
- package/esm/store/crud.d.ts +5 -2
- package/esm/store/crud.js +32 -12
- package/esm/store/form.d.ts +4 -2
- package/esm/store/form.js +1 -1
- package/esm/store/formItem.js +5 -4
- package/esm/store/iRenderer.d.ts +5 -2
- package/esm/store/iRenderer.js +15 -3
- package/esm/store/index.js +1 -1
- package/esm/store/list.d.ts +4 -2
- package/esm/store/list.js +5 -5
- package/esm/store/manager.js +1 -1
- package/esm/store/modal.d.ts +4 -2
- package/esm/store/modal.js +1 -1
- package/esm/store/node.js +1 -1
- package/esm/store/pagination.d.ts +4 -2
- package/esm/store/pagination.js +1 -1
- package/esm/store/root.d.ts +4 -2
- package/esm/store/root.js +1 -1
- package/esm/store/service.d.ts +4 -2
- package/esm/store/service.js +1 -1
- package/esm/store/table.d.ts +12 -6
- package/esm/store/table.js +12 -2
- package/esm/store/table2.d.ts +4 -2
- package/esm/store/table2.js +1 -1
- package/esm/theme.d.ts +2 -4
- package/esm/theme.js +1 -1
- package/esm/types.d.ts +39 -2
- package/esm/utils/Animation.js +1 -1
- package/esm/utils/ColorScale.js +1 -1
- package/esm/utils/DataSchema.js +1 -1
- package/esm/utils/DataScope.js +1 -1
- package/esm/utils/RootClose.js +1 -1
- package/esm/utils/SimpleMap.js +1 -1
- package/esm/utils/api.js +3 -4
- package/esm/utils/attachmentAdpator.js +1 -1
- package/esm/utils/autobind.js +1 -1
- package/esm/utils/columnsSplit.js +1 -1
- package/esm/utils/dataMapping.js +1 -1
- package/esm/utils/date.js +1 -1
- package/esm/utils/debug.d.ts +1 -0
- package/esm/utils/debug.js +1 -1
- package/esm/utils/decodeEntity.js +1 -1
- package/esm/utils/dom.js +1 -1
- package/esm/utils/errors.js +1 -1
- package/esm/utils/escapeHtml.js +1 -1
- package/esm/utils/filter-schema.js +1 -1
- package/esm/utils/filter.js +1 -1
- package/esm/utils/formatDuration.js +1 -1
- package/esm/utils/formula.d.ts +1 -0
- package/esm/utils/formula.js +6 -2
- package/esm/utils/getVariable.js +1 -1
- package/esm/utils/grammar.js +1 -1
- package/esm/utils/handleAction.js +1 -1
- package/esm/utils/helper.js +1 -1
- package/esm/utils/highlight.js +1 -1
- package/esm/utils/icon.js +1 -1
- package/esm/utils/image.js +1 -1
- package/esm/utils/index.d.ts +2 -0
- package/esm/utils/isPureVariable.js +1 -1
- package/esm/utils/json-schema-2-amis-schema.js +1 -1
- package/esm/utils/keyToPath.js +1 -1
- package/esm/utils/makeSorter.js +1 -1
- package/esm/utils/normalizeLink.js +1 -1
- package/esm/utils/normalizeOptions.js +1 -1
- package/esm/utils/object.js +1 -1
- package/esm/utils/offset.js +1 -1
- package/esm/utils/offsetParent.js +1 -1
- package/esm/utils/optionValueCompare.js +7 -3
- package/esm/utils/position.js +1 -1
- package/esm/utils/prettyBytes.js +1 -1
- package/esm/utils/renderer-event.js +1 -1
- package/esm/utils/replaceText.js +1 -1
- package/esm/utils/resize-sensor.js +1 -1
- package/esm/utils/resolveCondition.d.ts +5 -0
- package/esm/utils/resolveCondition.js +306 -0
- package/esm/utils/resolveVariable.js +1 -1
- package/esm/utils/resolveVariableAndFilter.js +1 -1
- package/esm/utils/resolveVariableAndFilterForAsync.d.ts +1 -0
- package/esm/utils/resolveVariableAndFilterForAsync.js +46 -0
- package/esm/utils/scrollPosition.js +1 -1
- package/esm/utils/string2regExp.js +1 -1
- package/esm/utils/stripNumber.js +1 -1
- package/esm/utils/style-helper.js +1 -1
- package/esm/utils/style.js +1 -1
- package/esm/utils/toNumber.js +1 -1
- package/esm/utils/tokenize.js +1 -1
- package/esm/utils/tpl-builtin.js +1 -1
- package/esm/utils/tpl-lodash.js +1 -1
- package/esm/utils/tpl.d.ts +7 -0
- package/esm/utils/tpl.js +23 -3
- package/esm/utils/uncontrollable.js +1 -1
- package/esm/utils/validations.js +1 -1
- package/lib/Root.d.ts +1 -1
- package/lib/Root.js +1 -1
- package/lib/RootRenderer.d.ts +1 -1
- package/lib/RootRenderer.js +21 -4
- package/lib/SchemaRenderer.d.ts +2 -1
- package/lib/SchemaRenderer.js +1 -1
- package/lib/Scoped.js +30 -2
- package/lib/WithRootStore.d.ts +4 -8
- package/lib/WithRootStore.js +1 -1
- package/lib/WithStore.js +1 -1
- package/lib/actions/Action.d.ts +2 -1
- package/lib/actions/Action.js +32 -10
- package/lib/actions/AjaxAction.js +1 -1
- package/lib/actions/BreakAction.js +1 -1
- package/lib/actions/BroadcastAction.js +1 -1
- package/lib/actions/CmptAction.js +1 -1
- package/lib/actions/ContinueAction.js +1 -1
- package/lib/actions/CopyAction.js +1 -1
- package/lib/actions/CustomAction.js +2 -1
- package/lib/actions/DialogAction.d.ts +1 -1
- package/lib/actions/DialogAction.js +8 -3
- package/lib/actions/DrawerAction.js +1 -1
- package/lib/actions/EmailAction.js +1 -1
- package/lib/actions/LinkAction.js +1 -1
- package/lib/actions/LoopAction.js +1 -1
- package/lib/actions/PageAction.js +1 -1
- package/lib/actions/ParallelAction.js +1 -1
- package/lib/actions/SwitchAction.js +17 -14
- package/lib/actions/ToastAction.js +1 -1
- package/lib/components/LazyComponent.d.ts +3 -3
- package/lib/components/LazyComponent.js +1 -1
- package/lib/components/Overlay.d.ts +1 -1
- package/lib/components/Overlay.js +2 -1
- package/lib/components/PopOver.d.ts +2 -4
- package/lib/components/PopOver.js +2 -1
- package/lib/env.d.ts +3 -7
- package/lib/env.js +1 -1
- package/lib/envOverwrite.js +1 -1
- package/lib/factory.js +3 -1
- package/lib/index.d.ts +2 -3
- package/lib/index.js +18 -2
- package/lib/locale.d.ts +1 -3
- package/lib/locale.js +1 -1
- package/lib/renderers/Form.js +16 -14
- package/lib/renderers/Item.d.ts +9 -15
- package/lib/renderers/Item.js +2 -1
- package/lib/renderers/Options.js +2 -1
- package/lib/renderers/Placeholder.js +1 -1
- package/lib/renderers/builtin.js +1 -1
- package/lib/renderers/register.js +1 -1
- package/lib/renderers/wrapControl.d.ts +4 -8
- package/lib/renderers/wrapControl.js +20 -28
- package/lib/store/app.d.ts +4 -2
- package/lib/store/app.js +1 -1
- package/lib/store/combo.d.ts +12 -6
- package/lib/store/combo.js +1 -1
- package/lib/store/crud.d.ts +5 -2
- package/lib/store/crud.js +31 -11
- package/lib/store/form.d.ts +4 -2
- package/lib/store/form.js +1 -1
- package/lib/store/formItem.js +5 -4
- package/lib/store/iRenderer.d.ts +5 -2
- package/lib/store/iRenderer.js +15 -3
- package/lib/store/index.js +1 -1
- package/lib/store/list.d.ts +4 -2
- package/lib/store/list.js +5 -5
- package/lib/store/manager.js +1 -1
- package/lib/store/modal.d.ts +4 -2
- package/lib/store/modal.js +1 -1
- package/lib/store/node.js +1 -1
- package/lib/store/pagination.d.ts +4 -2
- package/lib/store/pagination.js +1 -1
- package/lib/store/root.d.ts +4 -2
- package/lib/store/root.js +1 -1
- package/lib/store/service.d.ts +4 -2
- package/lib/store/service.js +1 -1
- package/lib/store/table.d.ts +12 -6
- package/lib/store/table.js +12 -2
- package/lib/store/table2.d.ts +4 -2
- package/lib/store/table2.js +1 -1
- package/lib/theme.d.ts +2 -4
- package/lib/theme.js +1 -1
- package/lib/types.d.ts +39 -2
- package/lib/utils/Animation.js +1 -1
- package/lib/utils/ColorScale.js +1 -1
- package/lib/utils/DataSchema.js +1 -1
- package/lib/utils/DataScope.js +1 -1
- package/lib/utils/RootClose.js +1 -1
- package/lib/utils/SimpleMap.js +1 -1
- package/lib/utils/api.js +2 -3
- package/lib/utils/attachmentAdpator.js +1 -1
- package/lib/utils/autobind.js +1 -1
- package/lib/utils/columnsSplit.js +1 -1
- package/lib/utils/dataMapping.js +1 -1
- package/lib/utils/date.js +1 -1
- package/lib/utils/debug.d.ts +1 -0
- package/lib/utils/debug.js +1 -1
- package/lib/utils/decodeEntity.js +1 -1
- package/lib/utils/dom.js +1 -1
- package/lib/utils/errors.js +1 -1
- package/lib/utils/escapeHtml.js +1 -1
- package/lib/utils/filter-schema.js +1 -1
- package/lib/utils/filter.js +1 -1
- package/lib/utils/formatDuration.js +1 -1
- package/lib/utils/formula.d.ts +1 -0
- package/lib/utils/formula.js +6 -1
- package/lib/utils/getVariable.js +1 -1
- package/lib/utils/grammar.js +1 -1
- package/lib/utils/handleAction.js +1 -1
- package/lib/utils/helper.js +1 -1
- package/lib/utils/highlight.js +1 -1
- package/lib/utils/icon.js +1 -1
- package/lib/utils/image.js +1 -1
- package/lib/utils/index.d.ts +2 -0
- package/lib/utils/isPureVariable.js +1 -1
- package/lib/utils/json-schema-2-amis-schema.js +1 -1
- package/lib/utils/keyToPath.js +1 -1
- package/lib/utils/makeSorter.js +1 -1
- package/lib/utils/normalizeLink.js +1 -1
- package/lib/utils/normalizeOptions.js +1 -1
- package/lib/utils/object.js +1 -1
- package/lib/utils/offset.js +1 -1
- package/lib/utils/offsetParent.js +1 -1
- package/lib/utils/optionValueCompare.js +7 -3
- package/lib/utils/position.js +1 -1
- package/lib/utils/prettyBytes.js +1 -1
- package/lib/utils/renderer-event.js +1 -1
- package/lib/utils/replaceText.js +1 -1
- package/lib/utils/resize-sensor.js +1 -1
- package/lib/utils/resolveCondition.d.ts +5 -0
- package/lib/utils/resolveCondition.js +322 -0
- package/lib/utils/resolveVariable.js +1 -1
- package/lib/utils/resolveVariableAndFilter.js +1 -1
- package/lib/utils/resolveVariableAndFilterForAsync.d.ts +1 -0
- package/lib/utils/resolveVariableAndFilterForAsync.js +50 -0
- package/lib/utils/scrollPosition.js +1 -1
- package/lib/utils/string2regExp.js +1 -1
- package/lib/utils/stripNumber.js +1 -1
- package/lib/utils/style-helper.js +1 -1
- package/lib/utils/style.js +1 -1
- package/lib/utils/toNumber.js +1 -1
- package/lib/utils/tokenize.js +1 -1
- package/lib/utils/tpl-builtin.js +1 -1
- package/lib/utils/tpl-lodash.js +1 -1
- package/lib/utils/tpl.d.ts +7 -0
- package/lib/utils/tpl.js +22 -1
- package/lib/utils/uncontrollable.js +1 -1
- package/lib/utils/validations.js +1 -1
- package/package.json +5 -5
package/lib/utils/formula.d.ts
CHANGED
package/lib/utils/formula.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* amis-core v2.
|
|
2
|
+
* amis-core v2.9.0
|
|
3
3
|
* Copyright 2018-2023 fex
|
|
4
4
|
*/
|
|
5
5
|
|
|
@@ -216,6 +216,10 @@ function isNeedFormula(expression, prevData, curData) {
|
|
|
216
216
|
return false;
|
|
217
217
|
}
|
|
218
218
|
}
|
|
219
|
+
function isNowFormula(expression) {
|
|
220
|
+
var block = expression.split(/\${|\||}/).filter(function (item) { return item; });
|
|
221
|
+
return block[1] === 'now';
|
|
222
|
+
}
|
|
219
223
|
// 将 \${xx} 替换成 ${xx}
|
|
220
224
|
function replaceExpression(expression) {
|
|
221
225
|
if (expression &&
|
|
@@ -230,5 +234,6 @@ exports.FormulaExec = FormulaExec;
|
|
|
230
234
|
exports.formulaExec = formulaExec;
|
|
231
235
|
exports.isExpression = isExpression;
|
|
232
236
|
exports.isNeedFormula = isNeedFormula;
|
|
237
|
+
exports.isNowFormula = isNowFormula;
|
|
233
238
|
exports.registerFormulaExec = registerFormulaExec;
|
|
234
239
|
exports.replaceExpression = replaceExpression;
|
package/lib/utils/getVariable.js
CHANGED
package/lib/utils/grammar.js
CHANGED
package/lib/utils/helper.js
CHANGED
package/lib/utils/highlight.js
CHANGED
package/lib/utils/icon.js
CHANGED
package/lib/utils/image.js
CHANGED
package/lib/utils/index.d.ts
CHANGED
|
@@ -39,6 +39,7 @@ export * from './replaceText';
|
|
|
39
39
|
export * from './resize-sensor';
|
|
40
40
|
export * from './resolveVariable';
|
|
41
41
|
export * from './resolveVariableAndFilter';
|
|
42
|
+
export * from './resolveVariableAndFilterForAsync';
|
|
42
43
|
export * from './RootClose';
|
|
43
44
|
export * from './scrollPosition';
|
|
44
45
|
export * from './SimpleMap';
|
|
@@ -52,5 +53,6 @@ export * from './validations';
|
|
|
52
53
|
export * from './toNumber';
|
|
53
54
|
export * from './decodeEntity';
|
|
54
55
|
export * from './style-helper';
|
|
56
|
+
export * from './resolveCondition';
|
|
55
57
|
import animation from './Animation';
|
|
56
58
|
export { animation };
|
package/lib/utils/keyToPath.js
CHANGED
package/lib/utils/makeSorter.js
CHANGED
package/lib/utils/object.js
CHANGED
package/lib/utils/offset.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* amis-core v2.
|
|
2
|
+
* amis-core v2.9.0
|
|
3
3
|
* Copyright 2018-2023 fex
|
|
4
4
|
*/
|
|
5
5
|
|
|
@@ -17,9 +17,13 @@ function matchOptionValue(a, b, valueField) {
|
|
|
17
17
|
var aValue = object.isObject(a) && a && a.hasOwnProperty(valueField)
|
|
18
18
|
? a[valueField]
|
|
19
19
|
: a;
|
|
20
|
+
var bValue = b[valueField || 'value'];
|
|
20
21
|
return object.isObject(aValue)
|
|
21
|
-
? lodash.isEqual(aValue,
|
|
22
|
-
:
|
|
22
|
+
? lodash.isEqual(aValue, bValue)
|
|
23
|
+
: // 当值均为 undefined 时,不应该判定相等
|
|
24
|
+
aValue !== undefined &&
|
|
25
|
+
bValue !== undefined &&
|
|
26
|
+
String(bValue) === String(aValue);
|
|
23
27
|
}
|
|
24
28
|
function optionValueCompare(a, valueField) {
|
|
25
29
|
if (valueField === void 0) { valueField = 'value'; }
|
package/lib/utils/position.js
CHANGED
package/lib/utils/prettyBytes.js
CHANGED
package/lib/utils/replaceText.js
CHANGED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare function resolveCondition(conditions: any, data: any, defaultResult?: boolean): Promise<boolean>;
|
|
2
|
+
export declare function registerConditionComputer(op: string, func: (left: any, right: any, fieldType?: string) => boolean, fieldType?: string): void;
|
|
3
|
+
export declare function getConditionComputers(): {
|
|
4
|
+
[op: string]: (left: any, right: any, fieldType?: string | undefined) => boolean;
|
|
5
|
+
};
|
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* amis-core v2.9.0
|
|
3
|
+
* Copyright 2018-2023 fex
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
'use strict';
|
|
7
|
+
|
|
8
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
9
|
+
|
|
10
|
+
var tslib = require('tslib');
|
|
11
|
+
var get = require('lodash/get');
|
|
12
|
+
var endsWith = require('lodash/endsWith');
|
|
13
|
+
var isEmpty = require('lodash/isEmpty');
|
|
14
|
+
var isEqual = require('lodash/isEqual');
|
|
15
|
+
var startsWith = require('lodash/startsWith');
|
|
16
|
+
var resolveVariableAndFilterForAsync = require('./resolveVariableAndFilterForAsync.js');
|
|
17
|
+
var moment = require('moment');
|
|
18
|
+
var capitalize = require('lodash/capitalize');
|
|
19
|
+
|
|
20
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
21
|
+
|
|
22
|
+
var get__default = /*#__PURE__*/_interopDefaultLegacy(get);
|
|
23
|
+
var endsWith__default = /*#__PURE__*/_interopDefaultLegacy(endsWith);
|
|
24
|
+
var isEmpty__default = /*#__PURE__*/_interopDefaultLegacy(isEmpty);
|
|
25
|
+
var isEqual__default = /*#__PURE__*/_interopDefaultLegacy(isEqual);
|
|
26
|
+
var startsWith__default = /*#__PURE__*/_interopDefaultLegacy(startsWith);
|
|
27
|
+
var moment__default = /*#__PURE__*/_interopDefaultLegacy(moment);
|
|
28
|
+
var capitalize__default = /*#__PURE__*/_interopDefaultLegacy(capitalize);
|
|
29
|
+
|
|
30
|
+
var conditionResolverMap = {};
|
|
31
|
+
var DEFAULT_RESULT = true;
|
|
32
|
+
function resolveCondition(conditions, data, defaultResult) {
|
|
33
|
+
if (defaultResult === void 0) { defaultResult = true; }
|
|
34
|
+
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
35
|
+
return tslib.__generator(this, function (_a) {
|
|
36
|
+
switch (_a.label) {
|
|
37
|
+
case 0:
|
|
38
|
+
if (!conditions ||
|
|
39
|
+
!conditions.conjunction ||
|
|
40
|
+
!Array.isArray(conditions.children) ||
|
|
41
|
+
!conditions.children.length) {
|
|
42
|
+
return [2 /*return*/, defaultResult];
|
|
43
|
+
}
|
|
44
|
+
return [4 /*yield*/, computeConditions(conditions.children, conditions.conjunction, data)];
|
|
45
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
function computeConditions(conditions, conjunction, data) {
|
|
51
|
+
if (conjunction === void 0) { conjunction = 'and'; }
|
|
52
|
+
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
53
|
+
var computeResult, index, len, item, result, _a;
|
|
54
|
+
return tslib.__generator(this, function (_b) {
|
|
55
|
+
switch (_b.label) {
|
|
56
|
+
case 0:
|
|
57
|
+
computeResult = true;
|
|
58
|
+
index = 0, len = conditions.length;
|
|
59
|
+
_b.label = 1;
|
|
60
|
+
case 1:
|
|
61
|
+
if (!(index < len)) return [3 /*break*/, 7];
|
|
62
|
+
item = conditions[index];
|
|
63
|
+
if (!(item.conjunction && Array.isArray(item.children) && item.children.length)) return [3 /*break*/, 3];
|
|
64
|
+
return [4 /*yield*/, computeConditions(item.children, item.conjunction, data)];
|
|
65
|
+
case 2:
|
|
66
|
+
_a = _b.sent();
|
|
67
|
+
return [3 /*break*/, 5];
|
|
68
|
+
case 3: return [4 /*yield*/, computeCondition(item, index, data)];
|
|
69
|
+
case 4:
|
|
70
|
+
_a = _b.sent();
|
|
71
|
+
_b.label = 5;
|
|
72
|
+
case 5:
|
|
73
|
+
result = _a;
|
|
74
|
+
computeResult = !!result;
|
|
75
|
+
if ((result && conjunction === 'or') ||
|
|
76
|
+
(!result && conjunction === 'and')) {
|
|
77
|
+
return [3 /*break*/, 7];
|
|
78
|
+
}
|
|
79
|
+
_b.label = 6;
|
|
80
|
+
case 6:
|
|
81
|
+
index++;
|
|
82
|
+
return [3 /*break*/, 1];
|
|
83
|
+
case 7: return [2 /*return*/, computeResult];
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
function computeCondition(rule, index, data) {
|
|
89
|
+
var _a;
|
|
90
|
+
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
91
|
+
var leftValue, rightValue, func;
|
|
92
|
+
return tslib.__generator(this, function (_b) {
|
|
93
|
+
switch (_b.label) {
|
|
94
|
+
case 0:
|
|
95
|
+
leftValue = get__default["default"](data, rule.left.field);
|
|
96
|
+
return [4 /*yield*/, resolveVariableAndFilterForAsync.resolveVariableAndFilterForAsync(rule.right, data)];
|
|
97
|
+
case 1:
|
|
98
|
+
rightValue = _b.sent();
|
|
99
|
+
func = (_a = conditionResolverMap["".concat(rule.op, "For").concat(capitalize__default["default"](rule.left.type))]) !== null && _a !== void 0 ? _a : conditionResolverMap[rule.op];
|
|
100
|
+
return [2 /*return*/, func ? func(leftValue, rightValue, rule.left.type) : DEFAULT_RESULT];
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
function startsWithFunc(left, right) {
|
|
106
|
+
if (left === undefined || right === undefined) {
|
|
107
|
+
return DEFAULT_RESULT;
|
|
108
|
+
}
|
|
109
|
+
return startsWith__default["default"](left, right);
|
|
110
|
+
}
|
|
111
|
+
function endsWithFunc(left, right) {
|
|
112
|
+
if (left === undefined || right === undefined) {
|
|
113
|
+
return DEFAULT_RESULT;
|
|
114
|
+
}
|
|
115
|
+
return endsWith__default["default"](left, right);
|
|
116
|
+
}
|
|
117
|
+
function equalFunc(left, right) {
|
|
118
|
+
return isEqual__default["default"](left, right);
|
|
119
|
+
}
|
|
120
|
+
function notEqualFunc(left, right) {
|
|
121
|
+
return !isEqual__default["default"](left, right);
|
|
122
|
+
}
|
|
123
|
+
function isEmptyFunc(left) {
|
|
124
|
+
if (typeof left === 'string') {
|
|
125
|
+
return !left;
|
|
126
|
+
}
|
|
127
|
+
else if (typeof left === 'number') {
|
|
128
|
+
return left === undefined;
|
|
129
|
+
}
|
|
130
|
+
else if (Array.isArray(left)) {
|
|
131
|
+
return !left.length;
|
|
132
|
+
}
|
|
133
|
+
else if (typeof left === 'object') {
|
|
134
|
+
return isEmpty__default["default"](left);
|
|
135
|
+
}
|
|
136
|
+
return DEFAULT_RESULT;
|
|
137
|
+
}
|
|
138
|
+
function isNotEmptyFunc(left) {
|
|
139
|
+
if (typeof left === 'string') {
|
|
140
|
+
return !left;
|
|
141
|
+
}
|
|
142
|
+
else if (typeof left === 'number') {
|
|
143
|
+
return left !== undefined;
|
|
144
|
+
}
|
|
145
|
+
else if (Array.isArray(left)) {
|
|
146
|
+
return !!left.length;
|
|
147
|
+
}
|
|
148
|
+
else if (typeof left === 'object') {
|
|
149
|
+
return !isEmpty__default["default"](left);
|
|
150
|
+
}
|
|
151
|
+
return DEFAULT_RESULT;
|
|
152
|
+
}
|
|
153
|
+
function greaterFunc(left, right) {
|
|
154
|
+
if (left === undefined || right === undefined) {
|
|
155
|
+
return DEFAULT_RESULT;
|
|
156
|
+
}
|
|
157
|
+
return parseFloat(left) > parseFloat(right);
|
|
158
|
+
}
|
|
159
|
+
function normalizeDate(raw) {
|
|
160
|
+
if (typeof raw === 'string' || typeof raw === 'number') {
|
|
161
|
+
var formats = ['', 'YYYY-MM-DD HH:mm:ss', 'X'];
|
|
162
|
+
if (/^\d{10}((\.\d+)*)$/.test(raw.toString())) {
|
|
163
|
+
formats = ['X', 'x', 'YYYY-MM-DD HH:mm:ss', ''];
|
|
164
|
+
}
|
|
165
|
+
else if (/^\d{13}((\.\d+)*)$/.test(raw.toString())) {
|
|
166
|
+
formats = ['x', 'X', 'YYYY-MM-DD HH:mm:ss', ''];
|
|
167
|
+
}
|
|
168
|
+
while (formats.length) {
|
|
169
|
+
var format = formats.shift();
|
|
170
|
+
var date = moment__default["default"](raw, format);
|
|
171
|
+
if (date.isValid()) {
|
|
172
|
+
return date.toDate();
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return raw;
|
|
177
|
+
}
|
|
178
|
+
function normalizeDateRange(raw) {
|
|
179
|
+
return (Array.isArray(raw) ? raw : raw.split(',')).map(function (item) {
|
|
180
|
+
return normalizeDate(String(item).trim());
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
function greaterForDateFunc(left, right) {
|
|
184
|
+
left = normalizeDate(left);
|
|
185
|
+
right = normalizeDate(right);
|
|
186
|
+
return moment__default["default"](left).isAfter(moment__default["default"](right), 's');
|
|
187
|
+
}
|
|
188
|
+
function greaterOrEqualForDateFunc(left, right) {
|
|
189
|
+
left = normalizeDate(left);
|
|
190
|
+
right = normalizeDate(right);
|
|
191
|
+
return moment__default["default"](left).isSameOrAfter(moment__default["default"](right), 's');
|
|
192
|
+
}
|
|
193
|
+
function greaterOrEqualFunc(left, right) {
|
|
194
|
+
if (left === undefined || right === undefined) {
|
|
195
|
+
return DEFAULT_RESULT;
|
|
196
|
+
}
|
|
197
|
+
return parseFloat(left) >= parseFloat(right);
|
|
198
|
+
}
|
|
199
|
+
function lessFunc(left, right) {
|
|
200
|
+
if (left === undefined || right === undefined) {
|
|
201
|
+
return DEFAULT_RESULT;
|
|
202
|
+
}
|
|
203
|
+
return parseFloat(left) < parseFloat(right);
|
|
204
|
+
}
|
|
205
|
+
function lessForDateFunc(left, right) {
|
|
206
|
+
left = normalizeDate(left);
|
|
207
|
+
right = normalizeDate(right);
|
|
208
|
+
return moment__default["default"](left).isBefore(moment__default["default"](right), 's');
|
|
209
|
+
}
|
|
210
|
+
function lessOrEqualForDateFunc(left, right) {
|
|
211
|
+
left = normalizeDate(left);
|
|
212
|
+
right = normalizeDate(right);
|
|
213
|
+
return moment__default["default"](left).isSameOrBefore(moment__default["default"](right), 's');
|
|
214
|
+
}
|
|
215
|
+
function lessOrEqualFunc(left, right) {
|
|
216
|
+
if (left === undefined || right === undefined) {
|
|
217
|
+
return DEFAULT_RESULT;
|
|
218
|
+
}
|
|
219
|
+
return parseFloat(left) <= parseFloat(right);
|
|
220
|
+
}
|
|
221
|
+
function likeFunc(left, right) {
|
|
222
|
+
if (left === undefined || right === undefined) {
|
|
223
|
+
return DEFAULT_RESULT;
|
|
224
|
+
}
|
|
225
|
+
return !!~left.indexOf(right);
|
|
226
|
+
}
|
|
227
|
+
function notLikeFunc(left, right) {
|
|
228
|
+
if (left === undefined || right === undefined) {
|
|
229
|
+
return DEFAULT_RESULT;
|
|
230
|
+
}
|
|
231
|
+
return !~left.indexOf(right);
|
|
232
|
+
}
|
|
233
|
+
function betweenFunc(left, right) {
|
|
234
|
+
if (typeof left === 'number' && right !== undefined) {
|
|
235
|
+
var _a = tslib.__read(right.sort(), 2), min = _a[0], max = _a[1];
|
|
236
|
+
return left >= parseFloat(min) && left <= parseFloat(max);
|
|
237
|
+
}
|
|
238
|
+
return DEFAULT_RESULT;
|
|
239
|
+
}
|
|
240
|
+
function betweenForDateFunc(left, right) {
|
|
241
|
+
if (right !== undefined) {
|
|
242
|
+
var _a = tslib.__read(normalizeDateRange(right), 2), min = _a[0], max = _a[1];
|
|
243
|
+
return moment__default["default"](normalizeDate(left)).isBetween(min, max, 's', '[]');
|
|
244
|
+
}
|
|
245
|
+
return DEFAULT_RESULT;
|
|
246
|
+
}
|
|
247
|
+
function notBetweenFunc(left, right) {
|
|
248
|
+
if (typeof left === 'number' && right !== undefined) {
|
|
249
|
+
var _a = tslib.__read(right.sort(), 2), min = _a[0], max = _a[1];
|
|
250
|
+
return left < parseFloat(min) && left > parseFloat(max);
|
|
251
|
+
}
|
|
252
|
+
return DEFAULT_RESULT;
|
|
253
|
+
}
|
|
254
|
+
function notBetweenForDateFunc(left, right) {
|
|
255
|
+
if (right !== undefined) {
|
|
256
|
+
var _a = tslib.__read(normalizeDateRange(right), 2), min = _a[0], max = _a[1];
|
|
257
|
+
return !moment__default["default"](normalizeDate(left)).isBetween(min, max, 's', '[]');
|
|
258
|
+
}
|
|
259
|
+
return DEFAULT_RESULT;
|
|
260
|
+
}
|
|
261
|
+
function selectAnyInFunc(left, right) {
|
|
262
|
+
if (!Array.isArray(right)) {
|
|
263
|
+
return DEFAULT_RESULT;
|
|
264
|
+
}
|
|
265
|
+
if (Array.isArray(left)) {
|
|
266
|
+
return right.every(function (item) { return left.includes(item); });
|
|
267
|
+
}
|
|
268
|
+
return right.includes(left);
|
|
269
|
+
}
|
|
270
|
+
function selectNotAnyInFunc(left, right) {
|
|
271
|
+
if (!Array.isArray(right)) {
|
|
272
|
+
return DEFAULT_RESULT;
|
|
273
|
+
}
|
|
274
|
+
if (Array.isArray(left)) {
|
|
275
|
+
return !right.every(function (item) { return left.includes(item); });
|
|
276
|
+
}
|
|
277
|
+
return !right.includes(left);
|
|
278
|
+
}
|
|
279
|
+
function registerConditionComputer(op, func, fieldType) {
|
|
280
|
+
conditionResolverMap["".concat(op).concat(fieldType ? 'For' + capitalize__default["default"](fieldType) : '')] = func;
|
|
281
|
+
}
|
|
282
|
+
function getConditionComputers() {
|
|
283
|
+
return conditionResolverMap;
|
|
284
|
+
}
|
|
285
|
+
registerConditionComputer('greater', greaterFunc);
|
|
286
|
+
registerConditionComputer('greater', greaterForDateFunc, 'date');
|
|
287
|
+
registerConditionComputer('greater', greaterForDateFunc, 'time');
|
|
288
|
+
registerConditionComputer('greater', greaterForDateFunc, 'datetime');
|
|
289
|
+
registerConditionComputer('greater_or_equal', greaterOrEqualFunc);
|
|
290
|
+
registerConditionComputer('greater_or_equal', greaterOrEqualForDateFunc, 'date');
|
|
291
|
+
registerConditionComputer('greater_or_equal', greaterOrEqualForDateFunc, 'time');
|
|
292
|
+
registerConditionComputer('greater_or_equal', greaterOrEqualForDateFunc, 'datetime');
|
|
293
|
+
registerConditionComputer('less', lessFunc);
|
|
294
|
+
registerConditionComputer('less', lessForDateFunc, 'date');
|
|
295
|
+
registerConditionComputer('less', lessForDateFunc, 'time');
|
|
296
|
+
registerConditionComputer('less', lessForDateFunc, 'datetime');
|
|
297
|
+
registerConditionComputer('less_or_equal', lessOrEqualFunc);
|
|
298
|
+
registerConditionComputer('less_or_equal', lessOrEqualForDateFunc, 'date');
|
|
299
|
+
registerConditionComputer('less_or_equal', lessOrEqualForDateFunc, 'time');
|
|
300
|
+
registerConditionComputer('less_or_equal', lessOrEqualForDateFunc, 'datetime');
|
|
301
|
+
registerConditionComputer('is_empty', isEmptyFunc);
|
|
302
|
+
registerConditionComputer('is_not_empty', isNotEmptyFunc);
|
|
303
|
+
registerConditionComputer('between', betweenFunc);
|
|
304
|
+
registerConditionComputer('between', betweenForDateFunc, 'date');
|
|
305
|
+
registerConditionComputer('between', betweenForDateFunc, 'time');
|
|
306
|
+
registerConditionComputer('between', betweenForDateFunc, 'datetime');
|
|
307
|
+
registerConditionComputer('not_between', notBetweenFunc);
|
|
308
|
+
registerConditionComputer('not_between', notBetweenForDateFunc, 'date');
|
|
309
|
+
registerConditionComputer('not_between', notBetweenForDateFunc, 'time');
|
|
310
|
+
registerConditionComputer('not_between', notBetweenForDateFunc, 'datetime');
|
|
311
|
+
registerConditionComputer('equal', equalFunc);
|
|
312
|
+
registerConditionComputer('not_equal', notEqualFunc);
|
|
313
|
+
registerConditionComputer('like', likeFunc);
|
|
314
|
+
registerConditionComputer('not_like', notLikeFunc);
|
|
315
|
+
registerConditionComputer('select_any_in', selectAnyInFunc);
|
|
316
|
+
registerConditionComputer('select_not_any_in', selectNotAnyInFunc);
|
|
317
|
+
registerConditionComputer('starts_with', startsWithFunc);
|
|
318
|
+
registerConditionComputer('ends_with', endsWithFunc);
|
|
319
|
+
|
|
320
|
+
exports.getConditionComputers = getConditionComputers;
|
|
321
|
+
exports.registerConditionComputer = registerConditionComputer;
|
|
322
|
+
exports.resolveCondition = resolveCondition;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const resolveVariableAndFilterForAsync: (path?: string, data?: object, defaultFilter?: string, fallbackValue?: (value: any) => any) => Promise<any>;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* amis-core v2.9.0
|
|
3
|
+
* Copyright 2018-2023 fex
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
'use strict';
|
|
7
|
+
|
|
8
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
9
|
+
|
|
10
|
+
var tslib = require('tslib');
|
|
11
|
+
var amisFormula = require('amis-formula');
|
|
12
|
+
|
|
13
|
+
var resolveVariableAndFilterForAsync = function (path, data, defaultFilter, fallbackValue) {
|
|
14
|
+
if (data === void 0) { data = {}; }
|
|
15
|
+
if (defaultFilter === void 0) { defaultFilter = '| html'; }
|
|
16
|
+
if (fallbackValue === void 0) { fallbackValue = function (value) { return value; }; }
|
|
17
|
+
return tslib.__awaiter(void 0, void 0, void 0, function () {
|
|
18
|
+
var ast, ret, e_1;
|
|
19
|
+
return tslib.__generator(this, function (_a) {
|
|
20
|
+
switch (_a.label) {
|
|
21
|
+
case 0:
|
|
22
|
+
if (!path || typeof path !== 'string') {
|
|
23
|
+
return [2 /*return*/, undefined];
|
|
24
|
+
}
|
|
25
|
+
_a.label = 1;
|
|
26
|
+
case 1:
|
|
27
|
+
_a.trys.push([1, 3, , 4]);
|
|
28
|
+
ast = amisFormula.parse(path, {
|
|
29
|
+
evalMode: false,
|
|
30
|
+
allowFilter: true
|
|
31
|
+
});
|
|
32
|
+
return [4 /*yield*/, new amisFormula.AsyncEvaluator(data, {
|
|
33
|
+
defaultFilter: defaultFilter
|
|
34
|
+
}).evalute(ast)];
|
|
35
|
+
case 2:
|
|
36
|
+
ret = _a.sent();
|
|
37
|
+
return [2 /*return*/, ret == null && !~path.indexOf('default') && !~path.indexOf('now')
|
|
38
|
+
? fallbackValue(ret)
|
|
39
|
+
: ret];
|
|
40
|
+
case 3:
|
|
41
|
+
e_1 = _a.sent();
|
|
42
|
+
console.warn(e_1);
|
|
43
|
+
return [2 /*return*/, undefined];
|
|
44
|
+
case 4: return [2 /*return*/];
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
exports.resolveVariableAndFilterForAsync = resolveVariableAndFilterForAsync;
|