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,179 @@
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 tslib = require('tslib');
11
+ var hoistNonReactStatic = require('hoist-non-react-statics');
12
+ var mobxReact = require('mobx-react');
13
+ var mobxStateTree = require('mobx-state-tree');
14
+ var React = require('react');
15
+ var filterSchema = require('./utils/filter-schema.js');
16
+ var helper = require('./utils/helper.js');
17
+ require('amis-formula');
18
+ require('moment');
19
+ var object = require('./utils/object.js');
20
+ var dataMapping = require('./utils/dataMapping.js');
21
+ require('./utils/filter.js');
22
+ var WithRootStore = require('./WithRootStore.js');
23
+
24
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
25
+
26
+ var hoistNonReactStatic__default = /*#__PURE__*/_interopDefaultLegacy(hoistNonReactStatic);
27
+ var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
28
+
29
+ function HocStoreFactory(renderer) {
30
+ return function (Component) {
31
+ var StoreFactory = /** @class */ (function (_super) {
32
+ tslib.__extends(StoreFactory, _super);
33
+ function StoreFactory(props, context) {
34
+ var _this = _super.call(this, props) || this;
35
+ var rootStore = context;
36
+ _this.renderChild = _this.renderChild.bind(_this);
37
+ _this.refFn = _this.refFn.bind(_this);
38
+ var store = rootStore.addStore({
39
+ id: helper.guid(),
40
+ path: _this.props.$path,
41
+ storeType: renderer.storeType,
42
+ parentId: _this.props.store ? _this.props.store.id : ''
43
+ });
44
+ _this.store = store;
45
+ var extendsData = typeof renderer.extendsData === 'function'
46
+ ? renderer.extendsData(props)
47
+ : renderer.extendsData;
48
+ if (extendsData === false) {
49
+ store.initData(object.createObject(_this.props.data
50
+ ? _this.props.data.__super
51
+ : null, tslib.__assign(tslib.__assign({}, _this.formatData(dataMapping.dataMapping(_this.props.defaultData, _this.props.data))), _this.formatData(_this.props.data))));
52
+ }
53
+ else if (_this.props.scope ||
54
+ (_this.props.data && _this.props.data.__super)) {
55
+ if (_this.props.store && _this.props.data === _this.props.store.data) {
56
+ store.initData(object.createObject(_this.props.store.data, tslib.__assign({}, _this.formatData(dataMapping.dataMapping(_this.props.defaultData, _this.props.data)))));
57
+ }
58
+ else {
59
+ store.initData(object.createObject(_this.props.data.__super || _this.props.scope, tslib.__assign(tslib.__assign({}, _this.formatData(dataMapping.dataMapping(_this.props.defaultData, _this.props.data))), _this.formatData(_this.props.data))));
60
+ }
61
+ }
62
+ else {
63
+ store.initData(tslib.__assign(tslib.__assign({}, _this.formatData(dataMapping.dataMapping(_this.props.defaultData, _this.props.data))), _this.formatData(_this.props.data)));
64
+ }
65
+ return _this;
66
+ }
67
+ StoreFactory.prototype.getWrappedInstance = function () {
68
+ return this.ref;
69
+ };
70
+ StoreFactory.prototype.refFn = function (ref) {
71
+ this.ref = ref;
72
+ };
73
+ StoreFactory.prototype.formatData = function (data) {
74
+ if (Array.isArray(data)) {
75
+ return {
76
+ items: data
77
+ };
78
+ }
79
+ return data;
80
+ };
81
+ StoreFactory.prototype.componentDidUpdate = function (prevProps) {
82
+ var _a, _b;
83
+ var props = this.props;
84
+ var store = this.store;
85
+ var shouldSync = (_a = renderer.shouldSyncSuperStore) === null || _a === void 0 ? void 0 : _a.call(renderer, store, props, prevProps);
86
+ if (shouldSync === false) {
87
+ return;
88
+ }
89
+ var extendsData = typeof renderer.extendsData === 'function'
90
+ ? renderer.extendsData(props)
91
+ : renderer.extendsData;
92
+ if (extendsData === false) {
93
+ if (shouldSync === true ||
94
+ prevProps.defaultData !== props.defaultData ||
95
+ helper.isObjectShallowModified(prevProps.data, props.data) ||
96
+ //
97
+ // 特殊处理 CRUD。
98
+ // CRUD 中 toolbar 里面的 data 是空对象,但是 __super 会不一样
99
+ (props.data &&
100
+ prevProps.data &&
101
+ props.data.__super !== prevProps.data.__super)) {
102
+ store.initData(object.extendObject(props.data, tslib.__assign(tslib.__assign(tslib.__assign({}, (store.hasRemoteData ? store.data : null)), this.formatData(props.defaultData)), this.formatData(props.data))));
103
+ }
104
+ }
105
+ else if (shouldSync === true ||
106
+ helper.isObjectShallowModified(prevProps.data, props.data) ||
107
+ (props.syncSuperStore !== false &&
108
+ helper.isSuperDataModified(props.data, prevProps.data, store))) {
109
+ if (props.store && props.store.data === props.data) {
110
+ store.initData(object.createObject(props.store.data, props.syncSuperStore === false
111
+ ? tslib.__assign({}, store.data) : helper.syncDataFromSuper(store.data, props.store.data, prevProps.scope, store, props.syncSuperStore === true)));
112
+ }
113
+ else if (props.data && props.data.__super) {
114
+ store.initData(object.extendObject(props.data, store.hasRemoteData || store.path === 'page'
115
+ ? tslib.__assign(tslib.__assign({}, store.data), props.data) : undefined));
116
+ }
117
+ else {
118
+ store.initData(object.createObject(props.scope, props.data));
119
+ }
120
+ }
121
+ else if ((shouldSync === true ||
122
+ !props.store ||
123
+ props.data !== props.store.data) &&
124
+ props.data &&
125
+ props.data.__super) {
126
+ // 这个用法很少,当 data.__super 值发生变化时,更新 store.data
127
+ if (!prevProps.data ||
128
+ helper.isObjectShallowModified(props.data.__super, prevProps.data.__super, false)) {
129
+ store.initData(object.createObject(props.data.__super, tslib.__assign(tslib.__assign({}, props.data), store.data)), store.storeType === 'FormStore' &&
130
+ ((_b = prevProps.store) === null || _b === void 0 ? void 0 : _b.storeType) === 'CRUDStore');
131
+ }
132
+ // nextProps.data.__super !== props.data.__super) &&
133
+ }
134
+ else if (props.scope &&
135
+ props.data === props.store.data &&
136
+ (shouldSync === true || prevProps.data !== props.data)) {
137
+ // 只有父级数据变动的时候才应该进来,
138
+ // 目前看来这个 case 很少有情况下能进来
139
+ store.initData(object.createObject(props.scope, tslib.__assign({}, store.data)));
140
+ }
141
+ };
142
+ StoreFactory.prototype.componentWillUnmount = function () {
143
+ var rootStore = this.context;
144
+ var store = this.store;
145
+ mobxStateTree.isAlive(store) && rootStore.removeStore(store);
146
+ // @ts-ignore
147
+ delete this.store;
148
+ };
149
+ StoreFactory.prototype.renderChild = function (region, node, subProps) {
150
+ if (subProps === void 0) { subProps = {}; }
151
+ var render = this.props.render;
152
+ return render(region, node, tslib.__assign(tslib.__assign({ data: this.store.data, dataUpdatedAt: this.store.updatedAt }, subProps), { scope: this.store.data, store: this.store }));
153
+ };
154
+ StoreFactory.prototype.render = function () {
155
+ var _a = this.props, detectField = _a.detectField, rest = tslib.__rest(_a, ["detectField"]);
156
+ var exprProps = {};
157
+ if (!detectField || detectField === 'data') {
158
+ exprProps = filterSchema["default"](rest, this.store.data, undefined, rest);
159
+ if (exprProps.hidden || exprProps.visible === false) {
160
+ return null;
161
+ }
162
+ }
163
+ return (React__default["default"].createElement(Component, tslib.__assign({}, rest /* todo */, exprProps, { ref: this.refFn, data: this.store.data, dataUpdatedAt: this.store.updatedAt, store: this.store, scope: this.store.data, render: this.renderChild })));
164
+ };
165
+ StoreFactory.displayName = "WithStore(".concat(Component.displayName || Component.name, ")");
166
+ StoreFactory.ComposedComponent = Component;
167
+ StoreFactory.contextType = WithRootStore.RootStoreContext;
168
+ StoreFactory = tslib.__decorate([
169
+ mobxReact.observer,
170
+ tslib.__metadata("design:paramtypes", [Object, void 0])
171
+ ], StoreFactory);
172
+ return StoreFactory;
173
+ }(React__default["default"].Component));
174
+ hoistNonReactStatic__default["default"](StoreFactory, Component);
175
+ return StoreFactory;
176
+ };
177
+ }
178
+
179
+ exports.HocStoreFactory = HocStoreFactory;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,13 @@
1
+ import { RenderOptions } from '../src/factory';
2
+ export declare function wait(duration: number, fnOrUseWaitFor?: Function | boolean): Promise<void>;
3
+ export declare function makeEnv(env?: Partial<RenderOptions>): RenderOptions;
4
+ export declare const createMockMediaMatcher: (matchesOrMapOfMatches: any) => (qs: any) => {
5
+ matches: any;
6
+ media: string;
7
+ addListener: () => void;
8
+ addEventListener: () => void;
9
+ removeEventListener: () => void;
10
+ onchange: () => void;
11
+ removeListener: () => void;
12
+ dispatchEvent: () => boolean;
13
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,119 @@
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 tslib = require('tslib');
11
+ require('../utils/helper.js');
12
+ var tpl = require('../utils/tpl.js');
13
+ require('amis-formula');
14
+ require('moment');
15
+ var object = require('../utils/object.js');
16
+ var dataMapping = require('../utils/dataMapping.js');
17
+ require('../utils/filter.js');
18
+
19
+ // 循环动作执行状态
20
+ exports.LoopStatus = void 0;
21
+ (function (LoopStatus) {
22
+ LoopStatus[LoopStatus["NORMAL"] = 0] = "NORMAL";
23
+ LoopStatus[LoopStatus["BREAK"] = 1] = "BREAK";
24
+ LoopStatus[LoopStatus["CONTINUE"] = 2] = "CONTINUE";
25
+ })(exports.LoopStatus || (exports.LoopStatus = {}));
26
+ // 存储 Action 和类型的映射关系,用于后续查找
27
+ var ActionTypeMap = {};
28
+ // 注册 Action
29
+ var registerAction = function (type, action) {
30
+ ActionTypeMap[type] = action;
31
+ };
32
+ // 通过类型获取 Action 实例
33
+ var getActionByType = function (type) {
34
+ return ActionTypeMap[type];
35
+ };
36
+ var runActions = function (actions, renderer, event) { return tslib.__awaiter(void 0, void 0, void 0, function () {
37
+ var _i, actions_1, actionConfig, actionInstrance;
38
+ return tslib.__generator(this, function (_a) {
39
+ switch (_a.label) {
40
+ case 0:
41
+ if (!Array.isArray(actions)) {
42
+ actions = [actions];
43
+ }
44
+ _i = 0, actions_1 = actions;
45
+ _a.label = 1;
46
+ case 1:
47
+ if (!(_i < actions_1.length)) return [3 /*break*/, 4];
48
+ actionConfig = actions_1[_i];
49
+ actionInstrance = getActionByType(actionConfig.actionType);
50
+ // 如果存在指定组件ID,说明是组件专有动作
51
+ if (!actionInstrance && actionConfig.componentId) {
52
+ actionInstrance = getActionByType('component');
53
+ }
54
+ else if (actionConfig.actionType === 'url' ||
55
+ actionConfig.actionType === 'link' ||
56
+ actionConfig.actionType === 'jump') {
57
+ // 打开页面动作
58
+ actionInstrance = getActionByType('openlink');
59
+ }
60
+ // 找不到就通过组件专有动作完成
61
+ if (!actionInstrance) {
62
+ actionInstrance = getActionByType('component');
63
+ }
64
+ // 这些节点的子节点运行逻辑由节点内部实现
65
+ return [4 /*yield*/, runAction(actionInstrance, actionConfig, renderer, event)];
66
+ case 2:
67
+ // 这些节点的子节点运行逻辑由节点内部实现
68
+ _a.sent();
69
+ if (event.stoped) {
70
+ return [3 /*break*/, 4];
71
+ }
72
+ _a.label = 3;
73
+ case 3:
74
+ _i++;
75
+ return [3 /*break*/, 1];
76
+ case 4: return [2 /*return*/];
77
+ }
78
+ });
79
+ }); };
80
+ // 执行动作,与原有动作处理打通
81
+ var runAction = function (actionInstrance, actionConfig, renderer, event) { return tslib.__awaiter(void 0, void 0, void 0, function () {
82
+ var mergeData, expression, preventDefault, stopPropagation, args;
83
+ var _a;
84
+ return tslib.__generator(this, function (_b) {
85
+ switch (_b.label) {
86
+ case 0:
87
+ mergeData = object.extendObject(renderer.props.data, {
88
+ event: event
89
+ });
90
+ expression = (_a = actionConfig.expression) !== null && _a !== void 0 ? _a : actionConfig.execOn;
91
+ if (expression && !tpl.evalExpression(expression, mergeData)) {
92
+ return [2 /*return*/];
93
+ }
94
+ preventDefault = actionConfig.preventDefault &&
95
+ tpl.evalExpression(String(actionConfig.preventDefault), mergeData);
96
+ stopPropagation = actionConfig.stopPropagation &&
97
+ tpl.evalExpression(String(actionConfig.stopPropagation), mergeData);
98
+ args = event.data;
99
+ if (actionConfig.args) {
100
+ args = dataMapping.dataMapping(actionConfig.args, mergeData, function (key) {
101
+ return ['adaptor', 'responseAdaptor', 'requestAdaptor'].includes(key);
102
+ });
103
+ }
104
+ return [4 /*yield*/, actionInstrance.run(tslib.__assign(tslib.__assign({}, actionConfig), { args: args }), renderer, event, mergeData)];
105
+ case 1:
106
+ _b.sent();
107
+ // 阻止原有动作执行
108
+ preventDefault && event.preventDefault();
109
+ // 阻止后续动作执行
110
+ stopPropagation && event.stopPropagation();
111
+ return [2 /*return*/];
112
+ }
113
+ });
114
+ }); };
115
+
116
+ exports.getActionByType = getActionByType;
117
+ exports.registerAction = registerAction;
118
+ exports.runAction = runAction;
119
+ exports.runActions = runActions;
@@ -0,0 +1,96 @@
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 tslib = require('tslib');
11
+ var omit = require('lodash/omit');
12
+ var api = require('../utils/api.js');
13
+ var errors = require('../utils/errors.js');
14
+ var helper = require('../utils/helper.js');
15
+ var Action = require('./Action.js');
16
+ var object = require('../utils/object.js');
17
+
18
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
19
+
20
+ var omit__default = /*#__PURE__*/_interopDefaultLegacy(omit);
21
+
22
+ /**
23
+ * 发送请求动作
24
+ *
25
+ * @export
26
+ * @class AjaxAction
27
+ * @implements {Action}
28
+ */
29
+ var AjaxAction = /** @class */ (function () {
30
+ function AjaxAction() {
31
+ }
32
+ AjaxAction.prototype.run = function (action, renderer, event) {
33
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
34
+ return tslib.__awaiter(this, void 0, void 0, function () {
35
+ var env, result, responseData, msg, e_1, result;
36
+ var _m;
37
+ return tslib.__generator(this, function (_o) {
38
+ switch (_o.label) {
39
+ case 0:
40
+ if (!((_a = renderer.props.env) === null || _a === void 0 ? void 0 : _a.fetcher)) {
41
+ throw new Error('env.fetcher is required!');
42
+ }
43
+ env = event.context.env;
44
+ _o.label = 1;
45
+ case 1:
46
+ _o.trys.push([1, 3, , 4]);
47
+ return [4 /*yield*/, env.fetcher((_b = action.args) === null || _b === void 0 ? void 0 : _b.api, omit__default["default"]((_c = action.args) !== null && _c !== void 0 ? _c : {}, ['api', 'options', 'messages']), (_e = (_d = action.args) === null || _d === void 0 ? void 0 : _d.options) !== null && _e !== void 0 ? _e : {})];
48
+ case 2:
49
+ result = _o.sent();
50
+ if (!helper.isEmpty(result.data) || result.ok) {
51
+ responseData = api.normalizeApiResponseData(result.data);
52
+ // 记录请求返回的数据
53
+ event.setData(object.createObject(event.data, action.outputVar
54
+ ? (_m = {},
55
+ _m["".concat(action.outputVar)] = responseData,
56
+ _m) : responseData));
57
+ }
58
+ if (!result.ok) {
59
+ throw new errors.ServerError((_h = (_g = (_f = action.args) === null || _f === void 0 ? void 0 : _f.messages) === null || _g === void 0 ? void 0 : _g.failed) !== null && _h !== void 0 ? _h : result.msg, result);
60
+ }
61
+ else {
62
+ msg = (_l = (_k = (_j = action.args) === null || _j === void 0 ? void 0 : _j.messages) === null || _k === void 0 ? void 0 : _k.success) !== null && _l !== void 0 ? _l : result.msg;
63
+ msg &&
64
+ env.notify('success', msg, result.msgTimeout !== undefined
65
+ ? {
66
+ closeButton: true,
67
+ timeout: result.msgTimeout
68
+ }
69
+ : undefined);
70
+ }
71
+ return [2 /*return*/, result.data];
72
+ case 3:
73
+ e_1 = _o.sent();
74
+ if (e_1.type === 'ServerError') {
75
+ result = e_1.response;
76
+ env.notify('error', e_1.message, result.msgTimeout !== undefined
77
+ ? {
78
+ closeButton: true,
79
+ timeout: result.msgTimeout
80
+ }
81
+ : undefined);
82
+ }
83
+ else {
84
+ env.notify('error', e_1.message);
85
+ }
86
+ return [3 /*break*/, 4];
87
+ case 4: return [2 /*return*/];
88
+ }
89
+ });
90
+ });
91
+ };
92
+ return AjaxAction;
93
+ }());
94
+ Action.registerAction('ajax', new AjaxAction());
95
+
96
+ exports.AjaxAction = AjaxAction;
@@ -0,0 +1,35 @@
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 tslib = require('tslib');
11
+ var Action = require('./Action.js');
12
+
13
+ /**
14
+ * breach
15
+ *
16
+ * @export
17
+ * @class BreakAction
18
+ * @implements {Action}
19
+ */
20
+ var BreakAction = /** @class */ (function () {
21
+ function BreakAction() {
22
+ }
23
+ BreakAction.prototype.run = function (action, renderer, event) {
24
+ return tslib.__awaiter(this, void 0, void 0, function () {
25
+ return tslib.__generator(this, function (_a) {
26
+ renderer.loopStatus = Action.LoopStatus.BREAK;
27
+ return [2 /*return*/];
28
+ });
29
+ });
30
+ };
31
+ return BreakAction;
32
+ }());
33
+ Action.registerAction('break', new BreakAction());
34
+
35
+ exports.BreakAction = BreakAction;
@@ -0,0 +1,49 @@
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 tslib = require('tslib');
11
+ require('../utils/helper.js');
12
+ var rendererEvent = require('../utils/renderer-event.js');
13
+ var Action = require('./Action.js');
14
+ var object = require('../utils/object.js');
15
+
16
+ /**
17
+ * broadcast
18
+ *
19
+ * @export
20
+ * @class BroadcastAction
21
+ * @implements {Action}
22
+ */
23
+ var BroadcastAction = /** @class */ (function () {
24
+ function BroadcastAction() {
25
+ }
26
+ BroadcastAction.prototype.run = function (action, renderer, event) {
27
+ return tslib.__awaiter(this, void 0, void 0, function () {
28
+ return tslib.__generator(this, function (_a) {
29
+ switch (_a.label) {
30
+ case 0:
31
+ if (!action.eventName) {
32
+ console.error('eventName 未定义,请定义事件名称');
33
+ return [2 /*return*/];
34
+ }
35
+ // 作为一个新的事件,需要把广播动作的args参数追加到事件数据中
36
+ event.setData(object.createObject(event.data, action.args));
37
+ return [4 /*yield*/, rendererEvent.dispatchEvent(action.eventName, renderer, event.context.scoped, action.args, event)];
38
+ case 1:
39
+ // 直接触发对应的动作
40
+ return [2 /*return*/, _a.sent()];
41
+ }
42
+ });
43
+ });
44
+ };
45
+ return BroadcastAction;
46
+ }());
47
+ Action.registerAction('broadcast', new BroadcastAction());
48
+
49
+ exports.BroadcastAction = BroadcastAction;
@@ -0,0 +1,60 @@
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 tslib = require('tslib');
11
+ var Action = require('./Action.js');
12
+
13
+ /**
14
+ * 组件动作
15
+ *
16
+ * @export
17
+ * @class CmptAction
18
+ * @implements {Action}
19
+ */
20
+ var CmptAction = /** @class */ (function () {
21
+ function CmptAction() {
22
+ }
23
+ CmptAction.prototype.run = function (action, renderer, event) {
24
+ var _a, _b, _c, _d, _e, _f, _g;
25
+ return tslib.__awaiter(this, void 0, void 0, function () {
26
+ var component;
27
+ return tslib.__generator(this, function (_h) {
28
+ component = action.componentId && renderer.props.$schema.id !== action.componentId
29
+ ? (_a = event.context.scoped) === null || _a === void 0 ? void 0 : _a.getComponentById(action.componentId)
30
+ : renderer;
31
+ // 显隐&状态控制
32
+ if (['show', 'hidden'].includes(action.actionType)) {
33
+ return [2 /*return*/, renderer.props.rootStore.setVisible(action.componentId, action.actionType === 'show')];
34
+ }
35
+ else if (['enabled', 'disabled'].includes(action.actionType)) {
36
+ return [2 /*return*/, renderer.props.rootStore.setDisable(action.componentId, action.actionType === 'disabled')];
37
+ }
38
+ // 数据更新
39
+ if (action.actionType === 'setValue') {
40
+ if (component === null || component === void 0 ? void 0 : component.setData) {
41
+ return [2 /*return*/, component === null || component === void 0 ? void 0 : component.setData((_b = action.args) === null || _b === void 0 ? void 0 : _b.value)];
42
+ }
43
+ else {
44
+ return [2 /*return*/, (_d = component === null || component === void 0 ? void 0 : (_c = component.props).onChange) === null || _d === void 0 ? void 0 : _d.call(_c, (_e = action.args) === null || _e === void 0 ? void 0 : _e.value)];
45
+ }
46
+ }
47
+ // 刷新
48
+ if (action.actionType === 'reload') {
49
+ return [2 /*return*/, (_f = component === null || component === void 0 ? void 0 : component.reload) === null || _f === void 0 ? void 0 : _f.call(component, undefined, action.args)];
50
+ }
51
+ // 执行组件动作
52
+ return [2 /*return*/, (_g = component === null || component === void 0 ? void 0 : component.doAction) === null || _g === void 0 ? void 0 : _g.call(component, action, action.args)];
53
+ });
54
+ });
55
+ };
56
+ return CmptAction;
57
+ }());
58
+ Action.registerAction('component', new CmptAction());
59
+
60
+ exports.CmptAction = CmptAction;
@@ -0,0 +1,35 @@
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 tslib = require('tslib');
11
+ var Action = require('./Action.js');
12
+
13
+ /**
14
+ * continue
15
+ *
16
+ * @export
17
+ * @class ContinueAction
18
+ * @implements {Action}
19
+ */
20
+ var ContinueAction = /** @class */ (function () {
21
+ function ContinueAction() {
22
+ }
23
+ ContinueAction.prototype.run = function (action, renderer, event) {
24
+ return tslib.__awaiter(this, void 0, void 0, function () {
25
+ return tslib.__generator(this, function (_a) {
26
+ renderer.loopStatus = Action.LoopStatus.CONTINUE;
27
+ return [2 /*return*/];
28
+ });
29
+ });
30
+ };
31
+ return ContinueAction;
32
+ }());
33
+ Action.registerAction('continue', new ContinueAction());
34
+
35
+ exports.ContinueAction = ContinueAction;
@@ -0,0 +1,43 @@
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 tslib = require('tslib');
11
+ var Action = require('./Action.js');
12
+
13
+ /**
14
+ * 复制动作
15
+ *
16
+ * @export
17
+ * @class CopyAction
18
+ * @implements {Action}
19
+ */
20
+ var CopyAction = /** @class */ (function () {
21
+ function CopyAction() {
22
+ }
23
+ CopyAction.prototype.run = function (action, renderer, event) {
24
+ var _a, _b, _c, _d, _e, _f;
25
+ return tslib.__awaiter(this, void 0, void 0, function () {
26
+ return tslib.__generator(this, function (_g) {
27
+ if (!((_a = renderer.props.env) === null || _a === void 0 ? void 0 : _a.copy)) {
28
+ throw new Error('env.copy is required!');
29
+ }
30
+ if ((_b = action.args) === null || _b === void 0 ? void 0 : _b.content) {
31
+ (_d = (_c = renderer.props.env).copy) === null || _d === void 0 ? void 0 : _d.call(_c, action.args.content, {
32
+ format: (_f = (_e = action.args) === null || _e === void 0 ? void 0 : _e.copyFormat) !== null && _f !== void 0 ? _f : 'text/html'
33
+ });
34
+ }
35
+ return [2 /*return*/];
36
+ });
37
+ });
38
+ };
39
+ return CopyAction;
40
+ }());
41
+ Action.registerAction('copy', new CopyAction());
42
+
43
+ exports.CopyAction = CopyAction;