amis-core 2.9.0 → 3.0.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.js +1 -1
- package/esm/RootRenderer.js +1 -1
- package/esm/SchemaRenderer.d.ts +1 -0
- package/esm/SchemaRenderer.js +7 -5
- package/esm/Scoped.js +1 -1
- package/esm/WithRootStore.js +1 -1
- package/esm/WithStore.js +1 -1
- package/esm/actions/Action.js +8 -2
- 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 +1 -1
- package/esm/actions/DialogAction.js +5 -1
- 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 +1 -1
- package/esm/actions/ToastAction.js +1 -1
- package/esm/components/LazyComponent.js +1 -1
- package/esm/components/Overlay.d.ts +2 -2
- package/esm/components/Overlay.js +1 -1
- package/esm/components/PopOver.js +1 -1
- package/esm/env.js +1 -1
- package/esm/envOverwrite.js +1 -1
- package/esm/factory.d.ts +2 -1
- package/esm/factory.js +3 -3
- package/esm/index.d.ts +8 -3
- package/esm/index.js +10 -9
- package/esm/locale.js +1 -1
- package/esm/renderers/Form.d.ts +1 -1
- package/esm/renderers/Form.js +1 -1
- package/esm/renderers/Item.js +10 -7
- package/esm/renderers/Options.js +3 -3
- 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.js +1 -1
- package/esm/store/app.js +1 -1
- package/esm/store/combo.js +1 -1
- package/esm/store/crud.js +22 -8
- package/esm/store/form.js +1 -1
- package/esm/store/formItem.js +2 -2
- package/esm/store/iRenderer.js +1 -1
- package/esm/store/index.js +1 -1
- package/esm/store/list.js +1 -1
- package/esm/store/manager.js +1 -1
- package/esm/store/modal.js +1 -1
- package/esm/store/node.js +1 -1
- package/esm/store/pagination.js +2 -2
- package/esm/store/root.js +1 -1
- package/esm/store/service.js +1 -1
- package/esm/store/table.d.ts +24 -23
- package/esm/store/table.js +17 -4
- package/esm/store/table2.d.ts +5 -5
- package/esm/store/table2.js +23 -19
- package/esm/theme.js +1 -1
- package/esm/types.d.ts +6 -0
- 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 +9 -2
- 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.js +4 -4
- package/esm/utils/decodeEntity.js +1 -1
- package/esm/utils/dom.d.ts +2 -0
- package/esm/utils/dom.js +47 -10
- 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.js +2 -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.d.ts +7 -0
- package/esm/utils/helper.js +28 -3
- package/esm/utils/highlight.js +1 -1
- package/esm/utils/icon.d.ts +6 -1
- package/esm/utils/icon.js +6 -1
- package/esm/utils/image.js +1 -1
- 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 +1 -1
- package/esm/utils/position.js +1 -1
- package/esm/utils/prettyBytes.js +1 -1
- package/esm/utils/renderer-event.js +35 -32
- package/esm/utils/replaceText.js +1 -1
- package/esm/utils/resize-sensor.js +1 -1
- package/esm/utils/resolveCondition.d.ts +1 -0
- package/esm/utils/resolveCondition.js +19 -4
- package/esm/utils/resolveVariable.js +1 -1
- package/esm/utils/resolveVariableAndFilter.js +1 -1
- package/esm/utils/resolveVariableAndFilterForAsync.d.ts +6 -1
- package/esm/utils/resolveVariableAndFilterForAsync.js +20 -3
- 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.d.ts +9 -4
- package/esm/utils/style-helper.js +81 -16
- package/esm/utils/style.js +2 -2
- package/esm/utils/toNumber.js +1 -1
- package/esm/utils/tokenize.d.ts +1 -0
- package/esm/utils/tokenize.js +34 -3
- package/esm/utils/tpl-builtin.d.ts +2 -1
- package/esm/utils/tpl-builtin.js +18 -3
- package/esm/utils/tpl-lodash.js +3 -2
- package/esm/utils/tpl.d.ts +2 -0
- package/esm/utils/tpl.js +24 -2
- package/esm/utils/uncontrollable.js +1 -1
- package/esm/utils/validations.d.ts +4 -1
- package/esm/utils/validations.js +27 -12
- package/lib/Root.js +1 -1
- package/lib/RootRenderer.js +1 -1
- package/lib/SchemaRenderer.d.ts +1 -0
- package/lib/SchemaRenderer.js +7 -4
- package/lib/Scoped.js +1 -1
- package/lib/WithRootStore.js +1 -1
- package/lib/WithStore.js +1 -1
- package/lib/actions/Action.js +8 -2
- 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 +1 -1
- package/lib/actions/DialogAction.js +5 -1
- 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 +1 -1
- package/lib/actions/ToastAction.js +1 -1
- package/lib/components/LazyComponent.js +1 -1
- package/lib/components/Overlay.d.ts +2 -2
- package/lib/components/Overlay.js +1 -1
- package/lib/components/PopOver.js +1 -1
- package/lib/env.js +1 -1
- package/lib/envOverwrite.js +1 -1
- package/lib/factory.d.ts +2 -1
- package/lib/factory.js +3 -3
- package/lib/index.d.ts +8 -3
- package/lib/index.js +14 -2
- package/lib/locale.js +1 -1
- package/lib/renderers/Form.d.ts +1 -1
- package/lib/renderers/Form.js +1 -1
- package/lib/renderers/Item.js +10 -7
- package/lib/renderers/Options.js +3 -3
- 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.js +1 -1
- package/lib/store/app.js +1 -1
- package/lib/store/combo.js +1 -1
- package/lib/store/crud.js +22 -8
- package/lib/store/form.js +1 -1
- package/lib/store/formItem.js +2 -2
- package/lib/store/iRenderer.js +1 -1
- package/lib/store/index.js +1 -1
- package/lib/store/list.js +1 -1
- package/lib/store/manager.js +1 -1
- package/lib/store/modal.js +1 -1
- package/lib/store/node.js +1 -1
- package/lib/store/pagination.js +2 -2
- package/lib/store/root.js +1 -1
- package/lib/store/service.js +1 -1
- package/lib/store/table.d.ts +24 -23
- package/lib/store/table.js +17 -4
- package/lib/store/table2.d.ts +5 -5
- package/lib/store/table2.js +23 -19
- package/lib/theme.js +1 -1
- package/lib/types.d.ts +6 -0
- 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 +9 -2
- 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.js +4 -4
- package/lib/utils/decodeEntity.js +1 -1
- package/lib/utils/dom.d.ts +2 -0
- package/lib/utils/dom.js +48 -9
- 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.js +2 -2
- 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.d.ts +7 -0
- package/lib/utils/helper.js +29 -2
- package/lib/utils/highlight.js +1 -1
- package/lib/utils/icon.d.ts +6 -1
- package/lib/utils/icon.js +6 -1
- package/lib/utils/image.js +1 -1
- 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 +1 -1
- package/lib/utils/position.js +1 -1
- package/lib/utils/prettyBytes.js +1 -1
- package/lib/utils/renderer-event.js +35 -32
- package/lib/utils/replaceText.js +1 -1
- package/lib/utils/resize-sensor.js +1 -1
- package/lib/utils/resolveCondition.d.ts +1 -0
- package/lib/utils/resolveCondition.js +19 -3
- package/lib/utils/resolveVariable.js +1 -1
- package/lib/utils/resolveVariableAndFilter.js +1 -1
- package/lib/utils/resolveVariableAndFilterForAsync.d.ts +6 -1
- package/lib/utils/resolveVariableAndFilterForAsync.js +20 -2
- 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.d.ts +9 -4
- package/lib/utils/style-helper.js +86 -15
- package/lib/utils/style.js +2 -2
- package/lib/utils/toNumber.js +1 -1
- package/lib/utils/tokenize.d.ts +1 -0
- package/lib/utils/tokenize.js +33 -1
- package/lib/utils/tpl-builtin.d.ts +2 -1
- package/lib/utils/tpl-builtin.js +17 -2
- package/lib/utils/tpl-lodash.js +3 -2
- package/lib/utils/tpl.d.ts +2 -0
- package/lib/utils/tpl.js +24 -1
- package/lib/utils/uncontrollable.js +1 -1
- package/lib/utils/validations.d.ts +4 -1
- package/lib/utils/validations.js +27 -12
- package/package.json +3 -3
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* amis-core
|
|
2
|
+
* amis-core v3.0.0
|
|
3
3
|
* Copyright 2018-2023 fex
|
|
4
4
|
*/
|
|
5
5
|
|
|
@@ -34,7 +34,7 @@ function createRendererEvent(type, context) {
|
|
|
34
34
|
// 绑定事件
|
|
35
35
|
var bindEvent = function (renderer) {
|
|
36
36
|
var e_1, _a;
|
|
37
|
-
var _b, _c;
|
|
37
|
+
var _b, _c, _d;
|
|
38
38
|
if (!renderer) {
|
|
39
39
|
return undefined;
|
|
40
40
|
}
|
|
@@ -49,15 +49,16 @@ var bindEvent = function (renderer) {
|
|
|
49
49
|
rendererEventListeners = rendererEventListeners.filter(function (item) {
|
|
50
50
|
return !(item.renderer === listener.renderer && item.type === listener.type);
|
|
51
51
|
});
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
52
|
+
listener.actions.length &&
|
|
53
|
+
rendererEventListeners.push({
|
|
54
|
+
renderer: renderer,
|
|
55
|
+
type: key,
|
|
56
|
+
debounce: listener.debounce || null,
|
|
57
|
+
weight: listener.weight || 0,
|
|
58
|
+
actions: listener.actions
|
|
59
|
+
});
|
|
59
60
|
}
|
|
60
|
-
if (!listener) {
|
|
61
|
+
if (!listener && ((_d = listeners[key].actions) === null || _d === void 0 ? void 0 : _d.length)) {
|
|
61
62
|
rendererEventListeners.push({
|
|
62
63
|
renderer: renderer,
|
|
63
64
|
type: key,
|
|
@@ -69,15 +70,15 @@ var bindEvent = function (renderer) {
|
|
|
69
70
|
};
|
|
70
71
|
try {
|
|
71
72
|
// 暂存
|
|
72
|
-
for (var
|
|
73
|
-
var key =
|
|
73
|
+
for (var _e = __values(Object.keys(listeners)), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
74
|
+
var key = _f.value;
|
|
74
75
|
_loop_1(key);
|
|
75
76
|
}
|
|
76
77
|
}
|
|
77
78
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
78
79
|
finally {
|
|
79
80
|
try {
|
|
80
|
-
if (
|
|
81
|
+
if (_f && !_f.done && (_a = _e.return)) _a.call(_e);
|
|
81
82
|
}
|
|
82
83
|
finally { if (e_1) throw e_1.error; }
|
|
83
84
|
}
|
|
@@ -89,19 +90,20 @@ var bindEvent = function (renderer) {
|
|
|
89
90
|
};
|
|
90
91
|
// 触发事件
|
|
91
92
|
function dispatchEvent(e, renderer, scoped, data, broadcast) {
|
|
92
|
-
var _a, _b, _c, _d, _e, _f;
|
|
93
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
93
94
|
return __awaiter(this, void 0, void 0, function () {
|
|
94
95
|
var unbindEvent, eventName, eventConfig, rendererEvent, listeners, executedCount, checkExecuted, _loop_2, listeners_1, listeners_1_1, listener, state_1, e_2_1;
|
|
95
|
-
var e_2,
|
|
96
|
+
var e_2, _j;
|
|
96
97
|
var _this = this;
|
|
97
|
-
return __generator(this, function (
|
|
98
|
-
switch (
|
|
98
|
+
return __generator(this, function (_k) {
|
|
99
|
+
switch (_k.label) {
|
|
99
100
|
case 0:
|
|
100
101
|
unbindEvent = null;
|
|
101
102
|
eventName = typeof e === 'string' ? e : e.type;
|
|
102
103
|
(_c = (_b = (_a = renderer === null || renderer === void 0 ? void 0 : renderer.props) === null || _a === void 0 ? void 0 : _a.env) === null || _b === void 0 ? void 0 : _b.beforeDispatchEvent) === null || _c === void 0 ? void 0 : _c.call(_b, e, renderer, scoped, data, broadcast);
|
|
104
|
+
broadcast && ((_e = (_d = renderer.props).onBroadcast) === null || _e === void 0 ? void 0 : _e.call(_d, e, broadcast, data));
|
|
103
105
|
if (!broadcast) {
|
|
104
|
-
eventConfig = (
|
|
106
|
+
eventConfig = (_g = (_f = renderer === null || renderer === void 0 ? void 0 : renderer.props) === null || _f === void 0 ? void 0 : _f.onEvent) === null || _g === void 0 ? void 0 : _g[eventName];
|
|
105
107
|
if (!eventConfig) {
|
|
106
108
|
// 没命中也没关系
|
|
107
109
|
return [2 /*return*/, Promise.resolve()];
|
|
@@ -114,7 +116,7 @@ function dispatchEvent(e, renderer, scoped, data, broadcast) {
|
|
|
114
116
|
}
|
|
115
117
|
rendererEvent = broadcast ||
|
|
116
118
|
createRendererEvent(eventName, {
|
|
117
|
-
env: (
|
|
119
|
+
env: (_h = renderer === null || renderer === void 0 ? void 0 : renderer.props) === null || _h === void 0 ? void 0 : _h.env,
|
|
118
120
|
nativeEvent: e,
|
|
119
121
|
data: data,
|
|
120
122
|
scoped: scoped
|
|
@@ -135,11 +137,11 @@ function dispatchEvent(e, renderer, scoped, data, broadcast) {
|
|
|
135
137
|
}
|
|
136
138
|
};
|
|
137
139
|
_loop_2 = function (listener) {
|
|
138
|
-
var
|
|
139
|
-
return __generator(this, function (
|
|
140
|
-
switch (
|
|
140
|
+
var _l, _m, wait, _o, trailing, _p, leading, _q, maxWait, debounced_1;
|
|
141
|
+
return __generator(this, function (_r) {
|
|
142
|
+
switch (_r.label) {
|
|
141
143
|
case 0:
|
|
142
|
-
|
|
144
|
+
_l = (listener === null || listener === void 0 ? void 0 : listener.debounce) || {}, _m = _l.wait, wait = _m === void 0 ? 100 : _m, _o = _l.trailing, trailing = _o === void 0 ? true : _o, _p = _l.leading, leading = _p === void 0 ? false : _p, _q = _l.maxWait, maxWait = _q === void 0 ? 10000 : _q;
|
|
143
145
|
if (!(listener === null || listener === void 0 ? void 0 : listener.debounce)) return [3 /*break*/, 1];
|
|
144
146
|
debounced_1 = debounce(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
145
147
|
return __generator(this, function (_a) {
|
|
@@ -168,9 +170,9 @@ function dispatchEvent(e, renderer, scoped, data, broadcast) {
|
|
|
168
170
|
return [3 /*break*/, 3];
|
|
169
171
|
case 1: return [4 /*yield*/, runActions(listener.actions, listener.renderer, rendererEvent)];
|
|
170
172
|
case 2:
|
|
171
|
-
|
|
173
|
+
_r.sent();
|
|
172
174
|
checkExecuted();
|
|
173
|
-
|
|
175
|
+
_r.label = 3;
|
|
174
176
|
case 3:
|
|
175
177
|
// 停止后续监听器执行
|
|
176
178
|
if (rendererEvent.stoped) {
|
|
@@ -180,31 +182,31 @@ function dispatchEvent(e, renderer, scoped, data, broadcast) {
|
|
|
180
182
|
}
|
|
181
183
|
});
|
|
182
184
|
};
|
|
183
|
-
|
|
185
|
+
_k.label = 1;
|
|
184
186
|
case 1:
|
|
185
|
-
|
|
187
|
+
_k.trys.push([1, 6, 7, 8]);
|
|
186
188
|
listeners_1 = __values(listeners), listeners_1_1 = listeners_1.next();
|
|
187
|
-
|
|
189
|
+
_k.label = 2;
|
|
188
190
|
case 2:
|
|
189
191
|
if (!!listeners_1_1.done) return [3 /*break*/, 5];
|
|
190
192
|
listener = listeners_1_1.value;
|
|
191
193
|
return [5 /*yield**/, _loop_2(listener)];
|
|
192
194
|
case 3:
|
|
193
|
-
state_1 =
|
|
195
|
+
state_1 = _k.sent();
|
|
194
196
|
if (state_1 === "break")
|
|
195
197
|
return [3 /*break*/, 5];
|
|
196
|
-
|
|
198
|
+
_k.label = 4;
|
|
197
199
|
case 4:
|
|
198
200
|
listeners_1_1 = listeners_1.next();
|
|
199
201
|
return [3 /*break*/, 2];
|
|
200
202
|
case 5: return [3 /*break*/, 8];
|
|
201
203
|
case 6:
|
|
202
|
-
e_2_1 =
|
|
204
|
+
e_2_1 = _k.sent();
|
|
203
205
|
e_2 = { error: e_2_1 };
|
|
204
206
|
return [3 /*break*/, 8];
|
|
205
207
|
case 7:
|
|
206
208
|
try {
|
|
207
|
-
if (listeners_1_1 && !listeners_1_1.done && (
|
|
209
|
+
if (listeners_1_1 && !listeners_1_1.done && (_j = listeners_1.return)) _j.call(listeners_1);
|
|
208
210
|
}
|
|
209
211
|
finally { if (e_2) throw e_2.error; }
|
|
210
212
|
return [7 /*endfinally*/];
|
|
@@ -224,6 +226,7 @@ var getRendererEventListeners = function () {
|
|
|
224
226
|
*/
|
|
225
227
|
var resolveEventData = function (props, data, valueKey) {
|
|
226
228
|
var _a, _b;
|
|
229
|
+
if (valueKey === void 0) { valueKey = 'value'; }
|
|
227
230
|
return createObject(props.data, props.name && valueKey
|
|
228
231
|
? __assign(__assign({}, data), (_a = {}, _a[props.name] = data[valueKey], _a.__rendererData = __assign(__assign({}, props.data), (_b = {}, _b[props.name] = data[valueKey], _b)), _a)) : data);
|
|
229
232
|
};
|
package/esm/utils/replaceText.js
CHANGED
|
@@ -3,3 +3,4 @@ export declare function registerConditionComputer(op: string, func: (left: any,
|
|
|
3
3
|
export declare function getConditionComputers(): {
|
|
4
4
|
[op: string]: (left: any, right: any, fieldType?: string | undefined) => boolean;
|
|
5
5
|
};
|
|
6
|
+
export declare function setConditionComputeErrorHandler(fn: (conditions: any, data: any, defaultResult: boolean) => boolean | Promise<boolean>): void;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* amis-core
|
|
2
|
+
* amis-core v3.0.0
|
|
3
3
|
* Copyright 2018-2023 fex
|
|
4
4
|
*/
|
|
5
5
|
|
|
@@ -15,9 +15,11 @@ import capitalize from 'lodash/capitalize';
|
|
|
15
15
|
|
|
16
16
|
var conditionResolverMap = {};
|
|
17
17
|
var DEFAULT_RESULT = true;
|
|
18
|
+
var conditionComputeErrorHandler;
|
|
18
19
|
function resolveCondition(conditions, data, defaultResult) {
|
|
19
20
|
if (defaultResult === void 0) { defaultResult = true; }
|
|
20
21
|
return __awaiter(this, void 0, void 0, function () {
|
|
22
|
+
var e_1;
|
|
21
23
|
return __generator(this, function (_a) {
|
|
22
24
|
switch (_a.label) {
|
|
23
25
|
case 0:
|
|
@@ -27,8 +29,18 @@ function resolveCondition(conditions, data, defaultResult) {
|
|
|
27
29
|
!conditions.children.length) {
|
|
28
30
|
return [2 /*return*/, defaultResult];
|
|
29
31
|
}
|
|
32
|
+
_a.label = 1;
|
|
33
|
+
case 1:
|
|
34
|
+
_a.trys.push([1, 3, , 6]);
|
|
30
35
|
return [4 /*yield*/, computeConditions(conditions.children, conditions.conjunction, data)];
|
|
31
|
-
case
|
|
36
|
+
case 2: return [2 /*return*/, _a.sent()];
|
|
37
|
+
case 3:
|
|
38
|
+
e_1 = _a.sent();
|
|
39
|
+
if (!(e_1.name === 'FormulaEvalError')) return [3 /*break*/, 5];
|
|
40
|
+
return [4 /*yield*/, (conditionComputeErrorHandler === null || conditionComputeErrorHandler === void 0 ? void 0 : conditionComputeErrorHandler(conditions.children, conditions.conjunction, data))];
|
|
41
|
+
case 4: return [2 /*return*/, _a.sent()];
|
|
42
|
+
case 5: return [2 /*return*/, defaultResult];
|
|
43
|
+
case 6: return [2 /*return*/];
|
|
32
44
|
}
|
|
33
45
|
});
|
|
34
46
|
});
|
|
@@ -79,7 +91,7 @@ function computeCondition(rule, index, data) {
|
|
|
79
91
|
switch (_b.label) {
|
|
80
92
|
case 0:
|
|
81
93
|
leftValue = get(data, rule.left.field);
|
|
82
|
-
return [4 /*yield*/, resolveVariableAndFilterForAsync(rule.right, data)];
|
|
94
|
+
return [4 /*yield*/, resolveVariableAndFilterForAsync(rule.right, data, undefined, undefined, true)];
|
|
83
95
|
case 1:
|
|
84
96
|
rightValue = _b.sent();
|
|
85
97
|
func = (_a = conditionResolverMap["".concat(rule.op, "For").concat(capitalize(rule.left.type))]) !== null && _a !== void 0 ? _a : conditionResolverMap[rule.op];
|
|
@@ -268,6 +280,9 @@ function registerConditionComputer(op, func, fieldType) {
|
|
|
268
280
|
function getConditionComputers() {
|
|
269
281
|
return conditionResolverMap;
|
|
270
282
|
}
|
|
283
|
+
function setConditionComputeErrorHandler(fn) {
|
|
284
|
+
conditionComputeErrorHandler = fn;
|
|
285
|
+
}
|
|
271
286
|
registerConditionComputer('greater', greaterFunc);
|
|
272
287
|
registerConditionComputer('greater', greaterForDateFunc, 'date');
|
|
273
288
|
registerConditionComputer('greater', greaterForDateFunc, 'time');
|
|
@@ -303,4 +318,4 @@ registerConditionComputer('select_not_any_in', selectNotAnyInFunc);
|
|
|
303
318
|
registerConditionComputer('starts_with', startsWithFunc);
|
|
304
319
|
registerConditionComputer('ends_with', endsWithFunc);
|
|
305
320
|
|
|
306
|
-
export { getConditionComputers, registerConditionComputer, resolveCondition };
|
|
321
|
+
export { getConditionComputers, registerConditionComputer, resolveCondition, setConditionComputeErrorHandler };
|
|
@@ -1 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* 设置自定义函数,functions中找不到处理的函数时执行
|
|
3
|
+
* @param fn
|
|
4
|
+
*/
|
|
5
|
+
export declare function setFormulaEvalErrorHandler(fn: (path: string, data?: object, ...args: any[]) => any): void;
|
|
6
|
+
export declare const resolveVariableAndFilterForAsync: (path?: string, data?: object, defaultFilter?: string, fallbackValue?: (value: any) => any, skipFormulaEvalErrorHandler?: boolean) => Promise<any>;
|
|
@@ -1,15 +1,24 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* amis-core
|
|
2
|
+
* amis-core v3.0.0
|
|
3
3
|
* Copyright 2018-2023 fex
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import { __awaiter, __generator } from 'tslib';
|
|
7
7
|
import { parse, AsyncEvaluator } from 'amis-formula';
|
|
8
8
|
|
|
9
|
-
var
|
|
9
|
+
var formulaEvalErrorHandler;
|
|
10
|
+
/**
|
|
11
|
+
* 设置自定义函数,functions中找不到处理的函数时执行
|
|
12
|
+
* @param fn
|
|
13
|
+
*/
|
|
14
|
+
function setFormulaEvalErrorHandler(fn) {
|
|
15
|
+
formulaEvalErrorHandler = fn;
|
|
16
|
+
}
|
|
17
|
+
var resolveVariableAndFilterForAsync = function (path, data, defaultFilter, fallbackValue, skipFormulaEvalErrorHandler) {
|
|
10
18
|
if (data === void 0) { data = {}; }
|
|
11
19
|
if (defaultFilter === void 0) { defaultFilter = '| html'; }
|
|
12
20
|
if (fallbackValue === void 0) { fallbackValue = function (value) { return value; }; }
|
|
21
|
+
if (skipFormulaEvalErrorHandler === void 0) { skipFormulaEvalErrorHandler = false; }
|
|
13
22
|
return __awaiter(void 0, void 0, void 0, function () {
|
|
14
23
|
var ast, ret, e_1;
|
|
15
24
|
return __generator(this, function (_a) {
|
|
@@ -36,6 +45,14 @@ var resolveVariableAndFilterForAsync = function (path, data, defaultFilter, fall
|
|
|
36
45
|
case 3:
|
|
37
46
|
e_1 = _a.sent();
|
|
38
47
|
console.warn(e_1);
|
|
48
|
+
if (e_1.name === 'FormulaEvalError') {
|
|
49
|
+
if (!skipFormulaEvalErrorHandler) {
|
|
50
|
+
// 无法解析时,执行handler自定义解析逻辑
|
|
51
|
+
return [2 /*return*/, formulaEvalErrorHandler === null || formulaEvalErrorHandler === void 0 ? void 0 : formulaEvalErrorHandler(path, data, defaultFilter, fallbackValue)];
|
|
52
|
+
}
|
|
53
|
+
// 跳过自定义解析逻辑,则直接抛异常
|
|
54
|
+
throw e_1;
|
|
55
|
+
}
|
|
39
56
|
return [2 /*return*/, undefined];
|
|
40
57
|
case 4: return [2 /*return*/];
|
|
41
58
|
}
|
|
@@ -43,4 +60,4 @@ var resolveVariableAndFilterForAsync = function (path, data, defaultFilter, fall
|
|
|
43
60
|
});
|
|
44
61
|
};
|
|
45
62
|
|
|
46
|
-
export { resolveVariableAndFilterForAsync };
|
|
63
|
+
export { resolveVariableAndFilterForAsync, setFormulaEvalErrorHandler };
|
package/esm/utils/stripNumber.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { PlainObject } from '../types';
|
|
2
2
|
export declare const valueMap: PlainObject;
|
|
3
|
+
export declare const inheritValueMap: PlainObject;
|
|
3
4
|
interface extra {
|
|
4
5
|
pre?: string;
|
|
5
6
|
suf?: string;
|
|
@@ -7,7 +8,7 @@ interface extra {
|
|
|
7
8
|
export declare function findOrCreactStyle(id: string): HTMLElement;
|
|
8
9
|
export declare function insertStyle(style: string, id: string): void;
|
|
9
10
|
export declare function addStyle(style: string, id: string): void;
|
|
10
|
-
export declare function formatStyle(
|
|
11
|
+
export declare function formatStyle(themeCss: any, classNames: {
|
|
11
12
|
key: string;
|
|
12
13
|
value?: string;
|
|
13
14
|
weights?: {
|
|
@@ -16,14 +17,14 @@ export declare function formatStyle(css: any, classNames: {
|
|
|
16
17
|
active?: extra;
|
|
17
18
|
disabled?: extra;
|
|
18
19
|
};
|
|
19
|
-
}[], id?: string): {
|
|
20
|
+
}[], id?: string, defaultData?: any): {
|
|
20
21
|
value: string;
|
|
21
22
|
origin: {
|
|
22
23
|
className: string;
|
|
23
24
|
content: string;
|
|
24
25
|
}[];
|
|
25
26
|
};
|
|
26
|
-
export declare function insertCustomStyle(
|
|
27
|
+
export declare function insertCustomStyle(themeCss: any, classNames: {
|
|
27
28
|
key: string;
|
|
28
29
|
value?: string;
|
|
29
30
|
weights?: {
|
|
@@ -32,5 +33,9 @@ export declare function insertCustomStyle(css: any, classNames: {
|
|
|
32
33
|
active?: extra;
|
|
33
34
|
disabled?: extra;
|
|
34
35
|
};
|
|
35
|
-
}[], id?: string): void;
|
|
36
|
+
}[], id?: string, defaultData?: any): void;
|
|
37
|
+
/**
|
|
38
|
+
* 根据路径获取默认值
|
|
39
|
+
*/
|
|
40
|
+
export declare function getValueByPath(path: string, data: any): any;
|
|
36
41
|
export {};
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* amis-core
|
|
2
|
+
* amis-core v3.0.0
|
|
3
3
|
* Copyright 2018-2023 fex
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import { __values } from 'tslib';
|
|
7
7
|
import { uuid } from './helper.js';
|
|
8
|
+
import cloneDeep from 'lodash/cloneDeep';
|
|
8
9
|
|
|
9
10
|
var valueMap = {
|
|
10
11
|
'marginTop': 'margin-top',
|
|
@@ -31,6 +32,10 @@ var valueMap = {
|
|
|
31
32
|
'fontWeight': 'font-weight',
|
|
32
33
|
'lineHeight': 'line-height'
|
|
33
34
|
};
|
|
35
|
+
var inheritValueMap = {
|
|
36
|
+
background: 'bg-color',
|
|
37
|
+
radius: 'border'
|
|
38
|
+
};
|
|
34
39
|
function findOrCreactStyle(id) {
|
|
35
40
|
var varStyleTag = document.getElementById(id);
|
|
36
41
|
if (!varStyleTag) {
|
|
@@ -50,10 +55,47 @@ function addStyle(style, id) {
|
|
|
50
55
|
// bca-disable-line
|
|
51
56
|
varStyleTag.innerHTML += style;
|
|
52
57
|
}
|
|
53
|
-
|
|
58
|
+
// 继承数据处理
|
|
59
|
+
function handleInheritData(statusMap, data) {
|
|
60
|
+
if (!data) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
// 检查是否存在inherit
|
|
64
|
+
['hover', 'active'].forEach(function (status) {
|
|
65
|
+
for (var key in statusMap[status]) {
|
|
66
|
+
if (typeof statusMap[status][key] === 'object') {
|
|
67
|
+
for (var style in statusMap[status][key]) {
|
|
68
|
+
if (statusMap[status][key][style] === 'inherit') {
|
|
69
|
+
// 值为inherit时设置为default的值或者主题中的default值
|
|
70
|
+
if (statusMap['default'][key] && statusMap['default'][key][style]) {
|
|
71
|
+
statusMap[status][key][style] = statusMap.default[key][style];
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
var value = inheritValueMap[key] || key;
|
|
75
|
+
statusMap[status][key][style] =
|
|
76
|
+
data['default'].body[value][style];
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
if (statusMap[status][key] === 'inherit') {
|
|
83
|
+
if (statusMap['default'][key] && statusMap['default'][key]) {
|
|
84
|
+
statusMap[status][key] = statusMap.default[key];
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
var value = inheritValueMap[key] || key;
|
|
88
|
+
statusMap[status][key] = data['default'].body[value];
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
function formatStyle(themeCss, classNames, id, defaultData) {
|
|
54
96
|
var e_1, _a;
|
|
55
97
|
var _b;
|
|
56
|
-
if (!
|
|
98
|
+
if (!themeCss) {
|
|
57
99
|
return { value: '', origin: [] };
|
|
58
100
|
}
|
|
59
101
|
var res = [];
|
|
@@ -65,7 +107,7 @@ function formatStyle(css, classNames, id) {
|
|
|
65
107
|
};
|
|
66
108
|
var _loop_1 = function (item) {
|
|
67
109
|
var e_2, _c;
|
|
68
|
-
var body =
|
|
110
|
+
var body = themeCss[item.key];
|
|
69
111
|
var list = (_b = item.value) === null || _b === void 0 ? void 0 : _b.split(' ');
|
|
70
112
|
var classNameList = [];
|
|
71
113
|
if (!body) {
|
|
@@ -73,7 +115,7 @@ function formatStyle(css, classNames, id) {
|
|
|
73
115
|
}
|
|
74
116
|
list === null || list === void 0 ? void 0 : list.forEach(function (n) {
|
|
75
117
|
if (/(\S*[C|c]lassName-\S*)/.test(n) &&
|
|
76
|
-
!!~n.indexOf((id === null || id === void 0 ? void 0 : id.replace('u:', '').replace('-label', '').replace('-description', '').replace('-addOn', '')) || '')) {
|
|
118
|
+
!!~n.indexOf((id === null || id === void 0 ? void 0 : id.replace('u:', '').replace('-label', '').replace('-description', '').replace('-addOn', '').replace('-icon', '')) || '')) {
|
|
77
119
|
classNameList.push(n);
|
|
78
120
|
}
|
|
79
121
|
});
|
|
@@ -108,6 +150,7 @@ function formatStyle(css, classNames, id) {
|
|
|
108
150
|
statusMap.default[key] = body[key];
|
|
109
151
|
}
|
|
110
152
|
}
|
|
153
|
+
handleInheritData(statusMap, defaultData);
|
|
111
154
|
var _loop_2 = function (status_1) {
|
|
112
155
|
var weights = weightsList[status_1];
|
|
113
156
|
var styles = [];
|
|
@@ -151,12 +194,13 @@ function formatStyle(css, classNames, id) {
|
|
|
151
194
|
className: cx + status2string[status_1],
|
|
152
195
|
content: ".".concat(cx + status2string[status_1], " {\n ").concat(styles.join('\n '), "\n}")
|
|
153
196
|
});
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
}
|
|
197
|
+
// TODO:切换状态暂时先不改变组件的样式
|
|
198
|
+
// if (['hover', 'active', 'disabled'].includes(status)) {
|
|
199
|
+
// res.push({
|
|
200
|
+
// className: cx + '.' + status,
|
|
201
|
+
// content: `.${cx}.${status} {\n ${styles.join('\n ')}\n}`
|
|
202
|
+
// });
|
|
203
|
+
// }
|
|
160
204
|
}
|
|
161
205
|
};
|
|
162
206
|
for (var status_1 in statusMap) {
|
|
@@ -190,12 +234,33 @@ function formatStyle(css, classNames, id) {
|
|
|
190
234
|
origin: res
|
|
191
235
|
};
|
|
192
236
|
}
|
|
193
|
-
function insertCustomStyle(
|
|
194
|
-
if (!
|
|
237
|
+
function insertCustomStyle(themeCss, classNames, id, defaultData) {
|
|
238
|
+
if (!themeCss) {
|
|
195
239
|
return;
|
|
196
240
|
}
|
|
197
|
-
var value = formatStyle(
|
|
198
|
-
|
|
241
|
+
var value = formatStyle(themeCss, classNames, id, defaultData).value;
|
|
242
|
+
if (value) {
|
|
243
|
+
insertStyle(value, (id === null || id === void 0 ? void 0 : id.replace('u:', '')) || uuid());
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* 根据路径获取默认值
|
|
248
|
+
*/
|
|
249
|
+
function getValueByPath(path, data) {
|
|
250
|
+
try {
|
|
251
|
+
if (!path || !data) {
|
|
252
|
+
return null;
|
|
253
|
+
}
|
|
254
|
+
var keys = path.split('.');
|
|
255
|
+
var value = cloneDeep(data.component);
|
|
256
|
+
for (var i = 0; i < keys.length; i++) {
|
|
257
|
+
value = value[keys[i]];
|
|
258
|
+
}
|
|
259
|
+
return value;
|
|
260
|
+
}
|
|
261
|
+
catch (e) {
|
|
262
|
+
return null;
|
|
263
|
+
}
|
|
199
264
|
}
|
|
200
265
|
|
|
201
|
-
export { addStyle, findOrCreactStyle, formatStyle, insertCustomStyle, insertStyle, valueMap };
|
|
266
|
+
export { addStyle, findOrCreactStyle, formatStyle, getValueByPath, inheritValueMap, insertCustomStyle, insertStyle, valueMap };
|
package/esm/utils/style.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* amis-core
|
|
2
|
+
* amis-core v3.0.0
|
|
3
3
|
* Copyright 2018-2023 fex
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
+
import 'tslib';
|
|
6
7
|
import 'amis-formula';
|
|
7
8
|
import 'moment';
|
|
8
|
-
import 'tslib';
|
|
9
9
|
import 'lodash/isPlainObject';
|
|
10
10
|
import { resolveVariableAndFilter } from './resolveVariableAndFilter.js';
|
|
11
11
|
import './filter.js';
|
package/esm/utils/toNumber.js
CHANGED
package/esm/utils/tokenize.d.ts
CHANGED
package/esm/utils/tokenize.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* amis-core
|
|
2
|
+
* amis-core v3.0.0
|
|
3
3
|
* Copyright 2018-2023 fex
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import {
|
|
6
|
+
import { __awaiter, __generator } from 'tslib';
|
|
7
|
+
import { parse, Evaluator, evaluateForAsync } from 'amis-formula';
|
|
7
8
|
|
|
8
9
|
var tokenize = function (str, data, defaultFilter) {
|
|
9
10
|
if (defaultFilter === void 0) { defaultFilter = '| html'; }
|
|
@@ -25,5 +26,35 @@ var tokenize = function (str, data, defaultFilter) {
|
|
|
25
26
|
return str;
|
|
26
27
|
}
|
|
27
28
|
};
|
|
29
|
+
var asyncTokenize = function (str, data, defaultFilter) {
|
|
30
|
+
if (defaultFilter === void 0) { defaultFilter = '| html'; }
|
|
31
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
32
|
+
var ast, result, e_1;
|
|
33
|
+
return __generator(this, function (_a) {
|
|
34
|
+
switch (_a.label) {
|
|
35
|
+
case 0:
|
|
36
|
+
if (!str || typeof str !== 'string') {
|
|
37
|
+
return [2 /*return*/, str];
|
|
38
|
+
}
|
|
39
|
+
_a.label = 1;
|
|
40
|
+
case 1:
|
|
41
|
+
_a.trys.push([1, 3, , 4]);
|
|
42
|
+
ast = parse(str, {
|
|
43
|
+
evalMode: false,
|
|
44
|
+
allowFilter: true
|
|
45
|
+
});
|
|
46
|
+
return [4 /*yield*/, evaluateForAsync(ast, data, { defaultFilter: defaultFilter })];
|
|
47
|
+
case 2:
|
|
48
|
+
result = _a.sent();
|
|
49
|
+
return [2 /*return*/, "".concat(result == null ? '' : result)];
|
|
50
|
+
case 3:
|
|
51
|
+
e_1 = _a.sent();
|
|
52
|
+
console.warn(e_1);
|
|
53
|
+
return [2 /*return*/, str];
|
|
54
|
+
case 4: return [2 /*return*/];
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
};
|
|
28
59
|
|
|
29
|
-
export { tokenize };
|
|
60
|
+
export { asyncTokenize, tokenize };
|
|
@@ -10,9 +10,10 @@ import { stripNumber } from './stripNumber';
|
|
|
10
10
|
import { tokenize } from './tokenize';
|
|
11
11
|
import { resolveVariable } from './resolveVariable';
|
|
12
12
|
import { resolveVariableAndFilter } from './resolveVariableAndFilter';
|
|
13
|
+
import { resolveVariableAndFilterForAsync } from './resolveVariableAndFilterForAsync';
|
|
13
14
|
import { dataMapping, resolveMapping, resolveMappingObject } from './dataMapping';
|
|
14
15
|
import './filter';
|
|
15
|
-
export { prettyBytes, escapeHtml, formatDuration, filterDate, relativeValueRe, parseDuration, getFilters, registerFilter, registerFunction, pickValues, isPureVariable, stripNumber, tokenize, resolveVariable, resolveVariableAndFilter, resolveMapping, resolveMappingObject, dataMapping };
|
|
16
|
+
export { prettyBytes, escapeHtml, formatDuration, filterDate, relativeValueRe, parseDuration, getFilters, registerFilter, registerFunction, pickValues, isPureVariable, stripNumber, tokenize, resolveVariable, resolveVariableAndFilter, resolveVariableAndFilterForAsync, resolveMapping, resolveMappingObject, dataMapping };
|
|
16
17
|
export declare function register(): Enginer & {
|
|
17
18
|
name: string;
|
|
18
19
|
};
|