cnhis-design-vue 3.1.17-beta.0 → 3.1.17-beta.3
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/es/packages/big-table/src/components/separate.js +1 -1
- package/es/packages/big-table/src/hooks/useSeparateRow.js +2 -2
- package/es/packages/fabric-chart/index.d.ts +2 -0
- package/es/packages/fabric-chart/src/FabricChart.js +20 -5
- package/es/packages/fabric-chart/src/FabricChart.vue.d.ts +2 -0
- package/es/packages/fabric-chart/src/hooks/useCenter.js +19 -18
- package/es/packages/fabric-chart/src/hooks/useLeft.d.ts +3 -1
- package/es/packages/fabric-chart/src/hooks/useLeft.js +30 -12
- package/es/packages/fabric-chart/src/hooks/useRight.d.ts +1 -1
- package/es/packages/fabric-chart/src/hooks/useRight.js +11 -69
- package/es/packages/fabric-chart/src/interface.d.ts +3 -0
- package/es/packages/form-config/index.d.ts +115 -1
- package/es/packages/form-config/src/FormConfig.js +11 -17
- package/es/packages/form-config/src/FormConfig.vue.d.ts +115 -1
- package/es/packages/form-config/src/components/CloseButton.js +45 -0
- package/es/packages/form-config/src/components/CloseButton.vue.d.ts +1499 -0
- package/es/packages/form-config/src/components/ComplexNode.js +45 -0
- package/es/packages/form-config/src/components/ComplexNode.vue.d.ts +1661 -0
- package/es/packages/form-config/src/components/DefaultNode.js +54 -0
- package/es/packages/form-config/src/components/DefaultNode.vue.d.ts +1543 -0
- package/es/packages/form-config/src/components/FormConfigCreator.js +3 -1
- package/es/packages/form-config/src/components/FormConfigDragDisplay.js +43 -0
- package/es/packages/form-config/src/components/FormConfigDragDisplay.vue.d.ts +114 -0
- package/es/packages/form-config/src/components/FormConfigEdit.js +1 -0
- package/es/packages/form-config/src/components/FormConfigEdit.vue.d.ts +2 -0
- package/es/packages/form-config/src/constants/index.d.ts +2 -0
- package/es/packages/form-config/src/constants/index.js +5 -2
- package/es/packages/form-config/src/hooks/useConfigurationField.js +9 -9
- package/es/packages/form-config/src/hooks/usePresetRenderer.d.ts +2 -2
- package/es/packages/form-config/src/hooks/usePresetRenderer.js +6 -84
- package/es/packages/form-config/src/hooks/useSortable.js +3 -7
- package/es/packages/form-config/src/types/index.d.ts +2 -1
- package/es/packages/form-config/src/utils/index.d.ts +8 -1
- package/es/packages/form-config/src/utils/index.js +23 -9
- package/es/packages/form-config/style/index.css +26 -5
- package/es/packages/form-render/index.js +1 -1
- package/es/packages/form-render/src/hooks/index.d.ts +1 -1
- package/es/packages/form-render/src/hooks/index.js +1 -1
- package/es/packages/form-render/src/hooks/useBusinessBinding.d.ts +5 -6
- package/es/packages/form-render/src/hooks/useBusinessBinding.js +22 -20
- package/es/packages/form-render/src/hooks/useFieldListAdaptor.js +4 -4
- package/es/packages/form-render/src/hooks/useFieldNormalize.d.ts +5 -0
- package/es/packages/form-render/src/hooks/useFieldNormalize.js +58 -0
- package/es/packages/form-render/src/hooks/useFieldVisitor.js +1 -5
- package/es/packages/index.css +26 -5
- package/es/packages/index.js +1 -1
- package/es/src/utils/tapable/AsyncParallelBailHook.d.ts +3 -0
- package/es/src/utils/tapable/AsyncParallelBailHook.js +78 -0
- package/es/src/utils/tapable/AsyncParallelHook.d.ts +3 -0
- package/es/src/utils/tapable/AsyncParallelHook.js +27 -0
- package/es/src/utils/tapable/AsyncSeriesBailHook.d.ts +3 -0
- package/es/src/utils/tapable/AsyncSeriesBailHook.js +33 -0
- package/es/src/utils/tapable/AsyncSeriesHook.d.ts +3 -0
- package/es/src/utils/tapable/AsyncSeriesHook.js +27 -0
- package/es/src/utils/tapable/AsyncSeriesLoopHook.d.ts +3 -0
- package/es/src/utils/tapable/AsyncSeriesLoopHook.js +27 -0
- package/es/src/utils/tapable/AsyncSeriesWaterfallHook.d.ts +3 -0
- package/es/src/utils/tapable/AsyncSeriesWaterfallHook.js +40 -0
- package/es/src/utils/tapable/Hook.d.ts +50 -0
- package/es/src/utils/tapable/Hook.js +140 -0
- package/es/src/utils/tapable/HookCodeFactory.d.ts +58 -0
- package/es/src/utils/tapable/HookCodeFactory.js +444 -0
- package/es/src/utils/tapable/HookMap.d.ts +11 -0
- package/es/src/utils/tapable/HookMap.js +32 -0
- package/es/src/utils/tapable/MultiHook.d.ts +12 -0
- package/es/src/utils/tapable/MultiHook.js +38 -0
- package/es/src/utils/tapable/SyncBailHook.d.ts +3 -0
- package/es/src/utils/tapable/SyncBailHook.js +40 -0
- package/es/src/utils/tapable/SyncHook.d.ts +3 -0
- package/es/src/utils/tapable/SyncHook.js +34 -0
- package/es/src/utils/tapable/SyncLoopHook.d.ts +3 -0
- package/es/src/utils/tapable/SyncLoopHook.js +34 -0
- package/es/src/utils/tapable/SyncWaterfallHook.d.ts +3 -0
- package/es/src/utils/tapable/SyncWaterfallHook.js +48 -0
- package/es/src/utils/tapable/index.d.ts +139 -0
- package/es/src/utils/tapable/index.js +12 -0
- package/package.json +1 -1
- package/es/packages/form-render/src/hooks/useTypeNormalize.d.ts +0 -4
- package/es/packages/form-render/src/hooks/useTypeNormalize.js +0 -46
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
export default HookCodeFactory;
|
|
2
|
+
declare class HookCodeFactory {
|
|
3
|
+
constructor(config: any);
|
|
4
|
+
config: any;
|
|
5
|
+
options: {
|
|
6
|
+
type: "sync" | "promise" | "async";
|
|
7
|
+
taps: Array<Tap>;
|
|
8
|
+
interceptors: Array<Interceptor>;
|
|
9
|
+
} | undefined;
|
|
10
|
+
_args: any;
|
|
11
|
+
create(options: any): Function;
|
|
12
|
+
setup(instance: any, options: any): void;
|
|
13
|
+
/**
|
|
14
|
+
* @param {{ type: "sync" | "promise" | "async", taps: Array<Tap>, interceptors: Array<Interceptor> }} options
|
|
15
|
+
*/
|
|
16
|
+
init(options: {
|
|
17
|
+
type: "sync" | "promise" | "async";
|
|
18
|
+
taps: Array<Tap>;
|
|
19
|
+
interceptors: Array<Interceptor>;
|
|
20
|
+
}): void;
|
|
21
|
+
deinit(): void;
|
|
22
|
+
contentWithInterceptors(options: any): any;
|
|
23
|
+
header(): string;
|
|
24
|
+
needContext(): boolean;
|
|
25
|
+
callTap(tapIndex: any, { onError, onResult, onDone, rethrowIfPossible }: {
|
|
26
|
+
onError: any;
|
|
27
|
+
onResult: any;
|
|
28
|
+
onDone: any;
|
|
29
|
+
rethrowIfPossible: any;
|
|
30
|
+
}): string;
|
|
31
|
+
callTapsSeries({ onError, onResult, resultReturns, onDone, doneReturns, rethrowIfPossible }: {
|
|
32
|
+
onError: any;
|
|
33
|
+
onResult: any;
|
|
34
|
+
resultReturns: any;
|
|
35
|
+
onDone: any;
|
|
36
|
+
doneReturns: any;
|
|
37
|
+
rethrowIfPossible: any;
|
|
38
|
+
}): any;
|
|
39
|
+
callTapsLooping({ onError, onDone, rethrowIfPossible }: {
|
|
40
|
+
onError: any;
|
|
41
|
+
onDone: any;
|
|
42
|
+
rethrowIfPossible: any;
|
|
43
|
+
}): any;
|
|
44
|
+
callTapsParallel({ onError, onResult, onDone, rethrowIfPossible, onTap }: {
|
|
45
|
+
onError: any;
|
|
46
|
+
onResult: any;
|
|
47
|
+
onDone: any;
|
|
48
|
+
rethrowIfPossible: any;
|
|
49
|
+
onTap?: ((i: any, run: any) => any) | undefined;
|
|
50
|
+
}): any;
|
|
51
|
+
args({ before, after }?: {
|
|
52
|
+
before: any;
|
|
53
|
+
after: any;
|
|
54
|
+
}): any;
|
|
55
|
+
getTapFn(idx: any): string;
|
|
56
|
+
getTap(idx: any): string;
|
|
57
|
+
getInterceptor(idx: any): string;
|
|
58
|
+
}
|
|
@@ -0,0 +1,444 @@
|
|
|
1
|
+
class HookCodeFactory {
|
|
2
|
+
constructor(config) {
|
|
3
|
+
this.config = config;
|
|
4
|
+
this.options = void 0;
|
|
5
|
+
this._args = void 0;
|
|
6
|
+
}
|
|
7
|
+
create(options) {
|
|
8
|
+
this.init(options);
|
|
9
|
+
let fn;
|
|
10
|
+
switch (this.options.type) {
|
|
11
|
+
case "sync":
|
|
12
|
+
fn = new Function(this.args(), '"use strict";\n' + this.header() + this.contentWithInterceptors({
|
|
13
|
+
onError: (err) => `throw ${err};
|
|
14
|
+
`,
|
|
15
|
+
onResult: (result) => `return ${result};
|
|
16
|
+
`,
|
|
17
|
+
resultReturns: true,
|
|
18
|
+
onDone: () => "",
|
|
19
|
+
rethrowIfPossible: true
|
|
20
|
+
}));
|
|
21
|
+
break;
|
|
22
|
+
case "async":
|
|
23
|
+
fn = new Function(this.args({
|
|
24
|
+
after: "_callback"
|
|
25
|
+
}), '"use strict";\n' + this.header() + this.contentWithInterceptors({
|
|
26
|
+
onError: (err) => `_callback(${err});
|
|
27
|
+
`,
|
|
28
|
+
onResult: (result) => `_callback(null, ${result});
|
|
29
|
+
`,
|
|
30
|
+
onDone: () => "_callback();\n"
|
|
31
|
+
}));
|
|
32
|
+
break;
|
|
33
|
+
case "promise":
|
|
34
|
+
let errorHelperUsed = false;
|
|
35
|
+
const content = this.contentWithInterceptors({
|
|
36
|
+
onError: (err) => {
|
|
37
|
+
errorHelperUsed = true;
|
|
38
|
+
return `_error(${err});
|
|
39
|
+
`;
|
|
40
|
+
},
|
|
41
|
+
onResult: (result) => `_resolve(${result});
|
|
42
|
+
`,
|
|
43
|
+
onDone: () => "_resolve();\n"
|
|
44
|
+
});
|
|
45
|
+
let code = "";
|
|
46
|
+
code += '"use strict";\n';
|
|
47
|
+
code += this.header();
|
|
48
|
+
code += "return new Promise((function(_resolve, _reject) {\n";
|
|
49
|
+
if (errorHelperUsed) {
|
|
50
|
+
code += "var _sync = true;\n";
|
|
51
|
+
code += "function _error(_err) {\n";
|
|
52
|
+
code += "if(_sync)\n";
|
|
53
|
+
code += "_resolve(Promise.resolve().then((function() { throw _err; })));\n";
|
|
54
|
+
code += "else\n";
|
|
55
|
+
code += "_reject(_err);\n";
|
|
56
|
+
code += "};\n";
|
|
57
|
+
}
|
|
58
|
+
code += content;
|
|
59
|
+
if (errorHelperUsed) {
|
|
60
|
+
code += "_sync = false;\n";
|
|
61
|
+
}
|
|
62
|
+
code += "}));\n";
|
|
63
|
+
fn = new Function(this.args(), code);
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
this.deinit();
|
|
67
|
+
return fn;
|
|
68
|
+
}
|
|
69
|
+
setup(instance, options) {
|
|
70
|
+
instance._x = options.taps.map((t) => t.fn);
|
|
71
|
+
}
|
|
72
|
+
init(options) {
|
|
73
|
+
this.options = options;
|
|
74
|
+
this._args = options.args.slice();
|
|
75
|
+
}
|
|
76
|
+
deinit() {
|
|
77
|
+
this.options = void 0;
|
|
78
|
+
this._args = void 0;
|
|
79
|
+
}
|
|
80
|
+
contentWithInterceptors(options) {
|
|
81
|
+
if (this.options.interceptors.length > 0) {
|
|
82
|
+
const onError = options.onError;
|
|
83
|
+
const onResult = options.onResult;
|
|
84
|
+
const onDone = options.onDone;
|
|
85
|
+
let code = "";
|
|
86
|
+
for (let i = 0; i < this.options.interceptors.length; i++) {
|
|
87
|
+
const interceptor = this.options.interceptors[i];
|
|
88
|
+
if (interceptor.call) {
|
|
89
|
+
code += `${this.getInterceptor(i)}.call(${this.args({
|
|
90
|
+
before: interceptor.context ? "_context" : void 0
|
|
91
|
+
})});
|
|
92
|
+
`;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
code += this.content(Object.assign(options, {
|
|
96
|
+
onError: onError && ((err) => {
|
|
97
|
+
let code2 = "";
|
|
98
|
+
for (let i = 0; i < this.options.interceptors.length; i++) {
|
|
99
|
+
const interceptor = this.options.interceptors[i];
|
|
100
|
+
if (interceptor.error) {
|
|
101
|
+
code2 += `${this.getInterceptor(i)}.error(${err});
|
|
102
|
+
`;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
code2 += onError(err);
|
|
106
|
+
return code2;
|
|
107
|
+
}),
|
|
108
|
+
onResult: onResult && ((result) => {
|
|
109
|
+
let code2 = "";
|
|
110
|
+
for (let i = 0; i < this.options.interceptors.length; i++) {
|
|
111
|
+
const interceptor = this.options.interceptors[i];
|
|
112
|
+
if (interceptor.result) {
|
|
113
|
+
code2 += `${this.getInterceptor(i)}.result(${result});
|
|
114
|
+
`;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
code2 += onResult(result);
|
|
118
|
+
return code2;
|
|
119
|
+
}),
|
|
120
|
+
onDone: onDone && (() => {
|
|
121
|
+
let code2 = "";
|
|
122
|
+
for (let i = 0; i < this.options.interceptors.length; i++) {
|
|
123
|
+
const interceptor = this.options.interceptors[i];
|
|
124
|
+
if (interceptor.done) {
|
|
125
|
+
code2 += `${this.getInterceptor(i)}.done();
|
|
126
|
+
`;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
code2 += onDone();
|
|
130
|
+
return code2;
|
|
131
|
+
})
|
|
132
|
+
}));
|
|
133
|
+
return code;
|
|
134
|
+
} else {
|
|
135
|
+
return this.content(options);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
header() {
|
|
139
|
+
let code = "";
|
|
140
|
+
if (this.needContext()) {
|
|
141
|
+
code += "var _context = {};\n";
|
|
142
|
+
} else {
|
|
143
|
+
code += "var _context;\n";
|
|
144
|
+
}
|
|
145
|
+
code += "var _x = this._x;\n";
|
|
146
|
+
if (this.options.interceptors.length > 0) {
|
|
147
|
+
code += "var _taps = this.taps;\n";
|
|
148
|
+
code += "var _interceptors = this.interceptors;\n";
|
|
149
|
+
}
|
|
150
|
+
return code;
|
|
151
|
+
}
|
|
152
|
+
needContext() {
|
|
153
|
+
for (const tap of this.options.taps)
|
|
154
|
+
if (tap.context)
|
|
155
|
+
return true;
|
|
156
|
+
return false;
|
|
157
|
+
}
|
|
158
|
+
callTap(tapIndex, { onError, onResult, onDone, rethrowIfPossible }) {
|
|
159
|
+
let code = "";
|
|
160
|
+
let hasTapCached = false;
|
|
161
|
+
for (let i = 0; i < this.options.interceptors.length; i++) {
|
|
162
|
+
const interceptor = this.options.interceptors[i];
|
|
163
|
+
if (interceptor.tap) {
|
|
164
|
+
if (!hasTapCached) {
|
|
165
|
+
code += `var _tap${tapIndex} = ${this.getTap(tapIndex)};
|
|
166
|
+
`;
|
|
167
|
+
hasTapCached = true;
|
|
168
|
+
}
|
|
169
|
+
code += `${this.getInterceptor(i)}.tap(${interceptor.context ? "_context, " : ""}_tap${tapIndex});
|
|
170
|
+
`;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
code += `var _fn${tapIndex} = ${this.getTapFn(tapIndex)};
|
|
174
|
+
`;
|
|
175
|
+
const tap = this.options.taps[tapIndex];
|
|
176
|
+
switch (tap.type) {
|
|
177
|
+
case "sync":
|
|
178
|
+
if (!rethrowIfPossible) {
|
|
179
|
+
code += `var _hasError${tapIndex} = false;
|
|
180
|
+
`;
|
|
181
|
+
code += "try {\n";
|
|
182
|
+
}
|
|
183
|
+
if (onResult) {
|
|
184
|
+
code += `var _result${tapIndex} = _fn${tapIndex}(${this.args({
|
|
185
|
+
before: tap.context ? "_context" : void 0
|
|
186
|
+
})});
|
|
187
|
+
`;
|
|
188
|
+
} else {
|
|
189
|
+
code += `_fn${tapIndex}(${this.args({
|
|
190
|
+
before: tap.context ? "_context" : void 0
|
|
191
|
+
})});
|
|
192
|
+
`;
|
|
193
|
+
}
|
|
194
|
+
if (!rethrowIfPossible) {
|
|
195
|
+
code += "} catch(_err) {\n";
|
|
196
|
+
code += `_hasError${tapIndex} = true;
|
|
197
|
+
`;
|
|
198
|
+
code += onError("_err");
|
|
199
|
+
code += "}\n";
|
|
200
|
+
code += `if(!_hasError${tapIndex}) {
|
|
201
|
+
`;
|
|
202
|
+
}
|
|
203
|
+
if (onResult) {
|
|
204
|
+
code += onResult(`_result${tapIndex}`);
|
|
205
|
+
}
|
|
206
|
+
if (onDone) {
|
|
207
|
+
code += onDone();
|
|
208
|
+
}
|
|
209
|
+
if (!rethrowIfPossible) {
|
|
210
|
+
code += "}\n";
|
|
211
|
+
}
|
|
212
|
+
break;
|
|
213
|
+
case "async":
|
|
214
|
+
let cbCode = "";
|
|
215
|
+
if (onResult)
|
|
216
|
+
cbCode += `(function(_err${tapIndex}, _result${tapIndex}) {
|
|
217
|
+
`;
|
|
218
|
+
else
|
|
219
|
+
cbCode += `(function(_err${tapIndex}) {
|
|
220
|
+
`;
|
|
221
|
+
cbCode += `if(_err${tapIndex}) {
|
|
222
|
+
`;
|
|
223
|
+
cbCode += onError(`_err${tapIndex}`);
|
|
224
|
+
cbCode += "} else {\n";
|
|
225
|
+
if (onResult) {
|
|
226
|
+
cbCode += onResult(`_result${tapIndex}`);
|
|
227
|
+
}
|
|
228
|
+
if (onDone) {
|
|
229
|
+
cbCode += onDone();
|
|
230
|
+
}
|
|
231
|
+
cbCode += "}\n";
|
|
232
|
+
cbCode += "})";
|
|
233
|
+
code += `_fn${tapIndex}(${this.args({
|
|
234
|
+
before: tap.context ? "_context" : void 0,
|
|
235
|
+
after: cbCode
|
|
236
|
+
})});
|
|
237
|
+
`;
|
|
238
|
+
break;
|
|
239
|
+
case "promise":
|
|
240
|
+
code += `var _hasResult${tapIndex} = false;
|
|
241
|
+
`;
|
|
242
|
+
code += `var _promise${tapIndex} = _fn${tapIndex}(${this.args({
|
|
243
|
+
before: tap.context ? "_context" : void 0
|
|
244
|
+
})});
|
|
245
|
+
`;
|
|
246
|
+
code += `if (!_promise${tapIndex} || !_promise${tapIndex}.then)
|
|
247
|
+
`;
|
|
248
|
+
code += ` throw new Error('Tap function (tapPromise) did not return promise (returned ' + _promise${tapIndex} + ')');
|
|
249
|
+
`;
|
|
250
|
+
code += `_promise${tapIndex}.then((function(_result${tapIndex}) {
|
|
251
|
+
`;
|
|
252
|
+
code += `_hasResult${tapIndex} = true;
|
|
253
|
+
`;
|
|
254
|
+
if (onResult) {
|
|
255
|
+
code += onResult(`_result${tapIndex}`);
|
|
256
|
+
}
|
|
257
|
+
if (onDone) {
|
|
258
|
+
code += onDone();
|
|
259
|
+
}
|
|
260
|
+
code += `}), function(_err${tapIndex}) {
|
|
261
|
+
`;
|
|
262
|
+
code += `if(_hasResult${tapIndex}) throw _err${tapIndex};
|
|
263
|
+
`;
|
|
264
|
+
code += onError(`_err${tapIndex}`);
|
|
265
|
+
code += "});\n";
|
|
266
|
+
break;
|
|
267
|
+
}
|
|
268
|
+
return code;
|
|
269
|
+
}
|
|
270
|
+
callTapsSeries({ onError, onResult, resultReturns, onDone, doneReturns, rethrowIfPossible }) {
|
|
271
|
+
if (this.options.taps.length === 0)
|
|
272
|
+
return onDone();
|
|
273
|
+
const firstAsync = this.options.taps.findIndex((t) => t.type !== "sync");
|
|
274
|
+
const somethingReturns = resultReturns || doneReturns;
|
|
275
|
+
let code = "";
|
|
276
|
+
let current = onDone;
|
|
277
|
+
let unrollCounter = 0;
|
|
278
|
+
for (let j = this.options.taps.length - 1; j >= 0; j--) {
|
|
279
|
+
const i = j;
|
|
280
|
+
const unroll = current !== onDone && (this.options.taps[i].type !== "sync" || unrollCounter++ > 20);
|
|
281
|
+
if (unroll) {
|
|
282
|
+
unrollCounter = 0;
|
|
283
|
+
code += `function _next${i}() {
|
|
284
|
+
`;
|
|
285
|
+
code += current();
|
|
286
|
+
code += `}
|
|
287
|
+
`;
|
|
288
|
+
current = () => `${somethingReturns ? "return " : ""}_next${i}();
|
|
289
|
+
`;
|
|
290
|
+
}
|
|
291
|
+
const done = current;
|
|
292
|
+
const doneBreak = (skipDone) => {
|
|
293
|
+
if (skipDone)
|
|
294
|
+
return "";
|
|
295
|
+
return onDone();
|
|
296
|
+
};
|
|
297
|
+
const content = this.callTap(i, {
|
|
298
|
+
onError: (error) => onError(i, error, done, doneBreak),
|
|
299
|
+
onResult: onResult && ((result) => {
|
|
300
|
+
return onResult(i, result, done, doneBreak);
|
|
301
|
+
}),
|
|
302
|
+
onDone: !onResult && done,
|
|
303
|
+
rethrowIfPossible: rethrowIfPossible && (firstAsync < 0 || i < firstAsync)
|
|
304
|
+
});
|
|
305
|
+
current = () => content;
|
|
306
|
+
}
|
|
307
|
+
code += current();
|
|
308
|
+
return code;
|
|
309
|
+
}
|
|
310
|
+
callTapsLooping({ onError, onDone, rethrowIfPossible }) {
|
|
311
|
+
if (this.options.taps.length === 0)
|
|
312
|
+
return onDone();
|
|
313
|
+
const syncOnly = this.options.taps.every((t) => t.type === "sync");
|
|
314
|
+
let code = "";
|
|
315
|
+
if (!syncOnly) {
|
|
316
|
+
code += "var _looper = (function() {\n";
|
|
317
|
+
code += "var _loopAsync = false;\n";
|
|
318
|
+
}
|
|
319
|
+
code += "var _loop;\n";
|
|
320
|
+
code += "do {\n";
|
|
321
|
+
code += "_loop = false;\n";
|
|
322
|
+
for (let i = 0; i < this.options.interceptors.length; i++) {
|
|
323
|
+
const interceptor = this.options.interceptors[i];
|
|
324
|
+
if (interceptor.loop) {
|
|
325
|
+
code += `${this.getInterceptor(i)}.loop(${this.args({
|
|
326
|
+
before: interceptor.context ? "_context" : void 0
|
|
327
|
+
})});
|
|
328
|
+
`;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
code += this.callTapsSeries({
|
|
332
|
+
onError,
|
|
333
|
+
onResult: (i, result, next, doneBreak) => {
|
|
334
|
+
let code2 = "";
|
|
335
|
+
code2 += `if(${result} !== undefined) {
|
|
336
|
+
`;
|
|
337
|
+
code2 += "_loop = true;\n";
|
|
338
|
+
if (!syncOnly)
|
|
339
|
+
code2 += "if(_loopAsync) _looper();\n";
|
|
340
|
+
code2 += doneBreak(true);
|
|
341
|
+
code2 += `} else {
|
|
342
|
+
`;
|
|
343
|
+
code2 += next();
|
|
344
|
+
code2 += `}
|
|
345
|
+
`;
|
|
346
|
+
return code2;
|
|
347
|
+
},
|
|
348
|
+
onDone: onDone && (() => {
|
|
349
|
+
let code2 = "";
|
|
350
|
+
code2 += "if(!_loop) {\n";
|
|
351
|
+
code2 += onDone();
|
|
352
|
+
code2 += "}\n";
|
|
353
|
+
return code2;
|
|
354
|
+
}),
|
|
355
|
+
rethrowIfPossible: rethrowIfPossible && syncOnly
|
|
356
|
+
});
|
|
357
|
+
code += "} while(_loop);\n";
|
|
358
|
+
if (!syncOnly) {
|
|
359
|
+
code += "_loopAsync = true;\n";
|
|
360
|
+
code += "});\n";
|
|
361
|
+
code += "_looper();\n";
|
|
362
|
+
}
|
|
363
|
+
return code;
|
|
364
|
+
}
|
|
365
|
+
callTapsParallel({ onError, onResult, onDone, rethrowIfPossible, onTap = (i, run) => run() }) {
|
|
366
|
+
if (this.options.taps.length <= 1) {
|
|
367
|
+
return this.callTapsSeries({
|
|
368
|
+
onError,
|
|
369
|
+
onResult,
|
|
370
|
+
onDone,
|
|
371
|
+
rethrowIfPossible
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
let code = "";
|
|
375
|
+
code += "do {\n";
|
|
376
|
+
code += `var _counter = ${this.options.taps.length};
|
|
377
|
+
`;
|
|
378
|
+
if (onDone) {
|
|
379
|
+
code += "var _done = (function() {\n";
|
|
380
|
+
code += onDone();
|
|
381
|
+
code += "});\n";
|
|
382
|
+
}
|
|
383
|
+
for (let i = 0; i < this.options.taps.length; i++) {
|
|
384
|
+
const done = () => {
|
|
385
|
+
if (onDone)
|
|
386
|
+
return "if(--_counter === 0) _done();\n";
|
|
387
|
+
else
|
|
388
|
+
return "--_counter;";
|
|
389
|
+
};
|
|
390
|
+
const doneBreak = (skipDone) => {
|
|
391
|
+
if (skipDone || !onDone)
|
|
392
|
+
return "_counter = 0;\n";
|
|
393
|
+
else
|
|
394
|
+
return "_counter = 0;\n_done();\n";
|
|
395
|
+
};
|
|
396
|
+
code += "if(_counter <= 0) break;\n";
|
|
397
|
+
code += onTap(i, () => this.callTap(i, {
|
|
398
|
+
onError: (error) => {
|
|
399
|
+
let code2 = "";
|
|
400
|
+
code2 += "if(_counter > 0) {\n";
|
|
401
|
+
code2 += onError(i, error, done, doneBreak);
|
|
402
|
+
code2 += "}\n";
|
|
403
|
+
return code2;
|
|
404
|
+
},
|
|
405
|
+
onResult: onResult && ((result) => {
|
|
406
|
+
let code2 = "";
|
|
407
|
+
code2 += "if(_counter > 0) {\n";
|
|
408
|
+
code2 += onResult(i, result, done, doneBreak);
|
|
409
|
+
code2 += "}\n";
|
|
410
|
+
return code2;
|
|
411
|
+
}),
|
|
412
|
+
onDone: !onResult && (() => {
|
|
413
|
+
return done();
|
|
414
|
+
}),
|
|
415
|
+
rethrowIfPossible
|
|
416
|
+
}), done, doneBreak);
|
|
417
|
+
}
|
|
418
|
+
code += "} while(false);\n";
|
|
419
|
+
return code;
|
|
420
|
+
}
|
|
421
|
+
args({ before, after } = {}) {
|
|
422
|
+
let allArgs = this._args;
|
|
423
|
+
if (before)
|
|
424
|
+
allArgs = [before].concat(allArgs);
|
|
425
|
+
if (after)
|
|
426
|
+
allArgs = allArgs.concat(after);
|
|
427
|
+
if (allArgs.length === 0) {
|
|
428
|
+
return "";
|
|
429
|
+
} else {
|
|
430
|
+
return allArgs.join(", ");
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
getTapFn(idx) {
|
|
434
|
+
return `_x[${idx}]`;
|
|
435
|
+
}
|
|
436
|
+
getTap(idx) {
|
|
437
|
+
return `_taps[${idx}]`;
|
|
438
|
+
}
|
|
439
|
+
getInterceptor(idx) {
|
|
440
|
+
return `_interceptors[${idx}]`;
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
export { HookCodeFactory as default };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export default HookMap;
|
|
2
|
+
declare class HookMap {
|
|
3
|
+
constructor(factory: any, name?: undefined);
|
|
4
|
+
_map: Map<any, any>;
|
|
5
|
+
name: any;
|
|
6
|
+
_factory: any;
|
|
7
|
+
_interceptors: any[];
|
|
8
|
+
get(key: any): any;
|
|
9
|
+
for(key: any): any;
|
|
10
|
+
intercept(interceptor: any): void;
|
|
11
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
const defaultFactory = (key, hook) => hook;
|
|
2
|
+
class HookMap {
|
|
3
|
+
constructor(factory, name = void 0) {
|
|
4
|
+
this._map = /* @__PURE__ */ new Map();
|
|
5
|
+
this.name = name;
|
|
6
|
+
this._factory = factory;
|
|
7
|
+
this._interceptors = [];
|
|
8
|
+
}
|
|
9
|
+
get(key) {
|
|
10
|
+
return this._map.get(key);
|
|
11
|
+
}
|
|
12
|
+
for(key) {
|
|
13
|
+
const hook = this.get(key);
|
|
14
|
+
if (hook !== void 0) {
|
|
15
|
+
return hook;
|
|
16
|
+
}
|
|
17
|
+
let newHook = this._factory(key);
|
|
18
|
+
const interceptors = this._interceptors;
|
|
19
|
+
for (let i = 0; i < interceptors.length; i++) {
|
|
20
|
+
newHook = interceptors[i].factory(key, newHook);
|
|
21
|
+
}
|
|
22
|
+
this._map.set(key, newHook);
|
|
23
|
+
return newHook;
|
|
24
|
+
}
|
|
25
|
+
intercept(interceptor) {
|
|
26
|
+
this._interceptors.push(Object.assign({
|
|
27
|
+
factory: defaultFactory
|
|
28
|
+
}, interceptor));
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export { HookMap as default };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export default MultiHook;
|
|
2
|
+
declare class MultiHook {
|
|
3
|
+
constructor(hooks: any, name?: undefined);
|
|
4
|
+
hooks: any;
|
|
5
|
+
name: any;
|
|
6
|
+
tap(options: any, fn: any): void;
|
|
7
|
+
tapAsync(options: any, fn: any): void;
|
|
8
|
+
tapPromise(options: any, fn: any): void;
|
|
9
|
+
isUsed(): boolean;
|
|
10
|
+
intercept(interceptor: any): void;
|
|
11
|
+
withOptions(options: any): MultiHook;
|
|
12
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
class MultiHook {
|
|
2
|
+
constructor(hooks, name = void 0) {
|
|
3
|
+
this.hooks = hooks;
|
|
4
|
+
this.name = name;
|
|
5
|
+
}
|
|
6
|
+
tap(options, fn) {
|
|
7
|
+
for (const hook of this.hooks) {
|
|
8
|
+
hook.tap(options, fn);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
tapAsync(options, fn) {
|
|
12
|
+
for (const hook of this.hooks) {
|
|
13
|
+
hook.tapAsync(options, fn);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
tapPromise(options, fn) {
|
|
17
|
+
for (const hook of this.hooks) {
|
|
18
|
+
hook.tapPromise(options, fn);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
isUsed() {
|
|
22
|
+
for (const hook of this.hooks) {
|
|
23
|
+
if (hook.isUsed())
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
intercept(interceptor) {
|
|
29
|
+
for (const hook of this.hooks) {
|
|
30
|
+
hook.intercept(interceptor);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
withOptions(options) {
|
|
34
|
+
return new MultiHook(this.hooks.map((h) => h.withOptions(options)), this.name);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export { MultiHook as default };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import Hook from './Hook.js';
|
|
2
|
+
import HookCodeFactory from './HookCodeFactory.js';
|
|
3
|
+
|
|
4
|
+
class SyncBailHookCodeFactory extends HookCodeFactory {
|
|
5
|
+
content({ onError, onResult, resultReturns, onDone, rethrowIfPossible }) {
|
|
6
|
+
return this.callTapsSeries({
|
|
7
|
+
onError: (i, err) => onError(err),
|
|
8
|
+
onResult: (i, result, next) => `if(${result} !== undefined) {
|
|
9
|
+
${onResult(result)};
|
|
10
|
+
} else {
|
|
11
|
+
${next()}}
|
|
12
|
+
`,
|
|
13
|
+
resultReturns,
|
|
14
|
+
onDone,
|
|
15
|
+
rethrowIfPossible
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
const factory = new SyncBailHookCodeFactory();
|
|
20
|
+
const TAP_ASYNC = () => {
|
|
21
|
+
throw new Error("tapAsync is not supported on a SyncBailHook");
|
|
22
|
+
};
|
|
23
|
+
const TAP_PROMISE = () => {
|
|
24
|
+
throw new Error("tapPromise is not supported on a SyncBailHook");
|
|
25
|
+
};
|
|
26
|
+
const COMPILE = function(options) {
|
|
27
|
+
factory.setup(this, options);
|
|
28
|
+
return factory.create(options);
|
|
29
|
+
};
|
|
30
|
+
function SyncBailHook(args = [], name = void 0) {
|
|
31
|
+
const hook = new Hook(args, name);
|
|
32
|
+
hook.constructor = SyncBailHook;
|
|
33
|
+
hook.tapAsync = TAP_ASYNC;
|
|
34
|
+
hook.tapPromise = TAP_PROMISE;
|
|
35
|
+
hook.compile = COMPILE;
|
|
36
|
+
return hook;
|
|
37
|
+
}
|
|
38
|
+
SyncBailHook.prototype = null;
|
|
39
|
+
|
|
40
|
+
export { SyncBailHook as default };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import Hook from './Hook.js';
|
|
2
|
+
import HookCodeFactory from './HookCodeFactory.js';
|
|
3
|
+
|
|
4
|
+
class SyncHookCodeFactory extends HookCodeFactory {
|
|
5
|
+
content({ onError, onDone, rethrowIfPossible }) {
|
|
6
|
+
return this.callTapsSeries({
|
|
7
|
+
onError: (i, err) => onError(err),
|
|
8
|
+
onDone,
|
|
9
|
+
rethrowIfPossible
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
const factory = new SyncHookCodeFactory();
|
|
14
|
+
const TAP_ASYNC = () => {
|
|
15
|
+
throw new Error("tapAsync is not supported on a SyncHook");
|
|
16
|
+
};
|
|
17
|
+
const TAP_PROMISE = () => {
|
|
18
|
+
throw new Error("tapPromise is not supported on a SyncHook");
|
|
19
|
+
};
|
|
20
|
+
const COMPILE = function(options) {
|
|
21
|
+
factory.setup(this, options);
|
|
22
|
+
return factory.create(options);
|
|
23
|
+
};
|
|
24
|
+
function SyncHook(args = [], name = void 0) {
|
|
25
|
+
const hook = new Hook(args, name);
|
|
26
|
+
hook.constructor = SyncHook;
|
|
27
|
+
hook.tapAsync = TAP_ASYNC;
|
|
28
|
+
hook.tapPromise = TAP_PROMISE;
|
|
29
|
+
hook.compile = COMPILE;
|
|
30
|
+
return hook;
|
|
31
|
+
}
|
|
32
|
+
SyncHook.prototype = null;
|
|
33
|
+
|
|
34
|
+
export { SyncHook as default };
|