icarys-fc-vant 1.0.14 → 1.0.16

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 (101) hide show
  1. package/README.md +87 -278
  2. package/dist/components/common/subform/package.json +48 -0
  3. package/dist/components/common/subform/src/component.jsx +75 -0
  4. package/dist/components/common/subform/src/index.js +3 -0
  5. package/dist/components/common/wangeditor/package-lock.json +114 -0
  6. package/dist/components/common/wangeditor/package.json +52 -0
  7. package/dist/components/common/wangeditor/src/component.jsx +74 -0
  8. package/dist/components/common/wangeditor/src/index.js +3 -0
  9. package/dist/core/babel.config.js +13 -0
  10. package/dist/core/bili.config.js +34 -0
  11. package/dist/core/package-lock.json +13 -0
  12. package/dist/core/package.json +61 -0
  13. package/dist/core/src/components/formCreate.js +287 -0
  14. package/dist/core/src/components/fragment.js +12 -0
  15. package/dist/core/src/factory/context.js +264 -0
  16. package/dist/core/src/factory/creator.js +63 -0
  17. package/dist/core/src/factory/maker.js +17 -0
  18. package/dist/core/src/factory/manager.js +87 -0
  19. package/dist/core/src/factory/node.js +89 -0
  20. package/dist/core/src/factory/parser.js +28 -0
  21. package/dist/core/src/frame/api.js +691 -0
  22. package/dist/core/src/frame/attrs.js +12 -0
  23. package/dist/core/src/frame/dataDriver.js +76 -0
  24. package/dist/core/src/frame/fetch.js +128 -0
  25. package/dist/core/src/frame/index.js +792 -0
  26. package/dist/core/src/frame/language.js +50 -0
  27. package/dist/core/src/frame/provider.js +297 -0
  28. package/dist/core/src/frame/util.js +311 -0
  29. package/dist/core/src/handler/context.js +573 -0
  30. package/dist/core/src/handler/effect.js +122 -0
  31. package/dist/core/src/handler/index.js +143 -0
  32. package/dist/core/src/handler/inject.js +199 -0
  33. package/dist/core/src/handler/input.js +199 -0
  34. package/dist/core/src/handler/lifecycle.js +55 -0
  35. package/dist/core/src/handler/loader.js +375 -0
  36. package/dist/core/src/handler/page.js +46 -0
  37. package/dist/core/src/handler/render.js +29 -0
  38. package/dist/core/src/index.js +12 -0
  39. package/dist/core/src/parser/html.js +17 -0
  40. package/dist/core/src/render/cache.js +47 -0
  41. package/dist/core/src/render/index.js +33 -0
  42. package/dist/core/src/render/render.js +418 -0
  43. package/dist/core/types/index.d.ts +842 -0
  44. package/dist/icarys-fc-vant.umd.js +17 -0
  45. package/dist/index.d.ts +27 -0
  46. package/dist/index.esm.js +39 -0
  47. package/dist/index.js +46 -0
  48. package/dist/utils/lib/console.js +16 -0
  49. package/dist/utils/lib/debounce.js +9 -0
  50. package/dist/utils/lib/deepextend.js +51 -0
  51. package/dist/utils/lib/deepset.js +14 -0
  52. package/dist/utils/lib/extend.js +20 -0
  53. package/dist/utils/lib/index.js +14 -0
  54. package/dist/utils/lib/json.js +90 -0
  55. package/dist/utils/lib/mergeprops.js +62 -0
  56. package/dist/utils/lib/mitt.js +43 -0
  57. package/dist/utils/lib/modify.js +8 -0
  58. package/dist/utils/lib/slot.js +8 -0
  59. package/dist/utils/lib/toarray.js +5 -0
  60. package/dist/utils/lib/tocase.js +11 -0
  61. package/dist/utils/lib/todate.js +10 -0
  62. package/dist/utils/lib/toline.js +10 -0
  63. package/dist/utils/lib/topromise.js +10 -0
  64. package/dist/utils/lib/tostring.js +7 -0
  65. package/dist/utils/lib/type.js +45 -0
  66. package/dist/utils/lib/unique.js +6 -0
  67. package/dist/utils/package.json +32 -0
  68. package/dist/vant/auto-import.d.ts +5 -0
  69. package/dist/vant/auto-import.js +50 -0
  70. package/dist/vant/babel.config.js +10 -0
  71. package/dist/vant/bili.config.js +40 -0
  72. package/dist/vant/examples/main.js +13 -0
  73. package/dist/vant/examples/rule.js +366 -0
  74. package/dist/vant/package.json +83 -0
  75. package/dist/vant/src/components/calendar.jsx +128 -0
  76. package/dist/vant/src/components/cascader.jsx +120 -0
  77. package/dist/vant/src/components/checkbox.jsx +38 -0
  78. package/dist/vant/src/components/datePicker.jsx +87 -0
  79. package/dist/vant/src/components/group.jsx +384 -0
  80. package/dist/vant/src/components/index.js +26 -0
  81. package/dist/vant/src/components/radio.jsx +38 -0
  82. package/dist/vant/src/components/select.jsx +81 -0
  83. package/dist/vant/src/components/timePicker.jsx +76 -0
  84. package/dist/vant/src/components/uploader.jsx +99 -0
  85. package/dist/vant/src/core/alias.js +31 -0
  86. package/dist/vant/src/core/api.js +135 -0
  87. package/dist/vant/src/core/config.js +35 -0
  88. package/dist/vant/src/core/index.js +45 -0
  89. package/dist/vant/src/core/manager.js +282 -0
  90. package/dist/vant/src/core/provider.js +63 -0
  91. package/dist/vant/src/core/utils.js +15 -0
  92. package/dist/vant/src/index.js +13 -0
  93. package/dist/vant/src/parsers/hidden.js +12 -0
  94. package/dist/vant/src/parsers/index.js +59 -0
  95. package/dist/vant/src/parsers/row.js +10 -0
  96. package/dist/vant/src/style/index.css +495 -0
  97. package/dist/vant/types/config.d.ts +99 -0
  98. package/dist/vant/types/index.d.ts +27 -0
  99. package/dist/vant/vue.config.js +21 -0
  100. package/package.json +29 -52
  101. package/dist/index.min.js +0 -7411
@@ -0,0 +1,691 @@
1
+ import {byCtx, invoke, mergeRule, parseFn, toJson} from './util';
2
+ import {$set} from '../../../utils/lib/modify';
3
+ import {deepCopy} from '../../../utils/lib/deepextend';
4
+ import is, {hasProperty} from '../../../utils/lib/type';
5
+ import extend from '../../../utils/lib/extend';
6
+ import {format} from '../../../utils/lib/console';
7
+ import {asyncFetch} from './fetch';
8
+ import {nextTick} from 'vue';
9
+
10
+
11
+ function copy(value) {
12
+ return deepCopy(value);
13
+ }
14
+
15
+ export default function Api(h) {
16
+
17
+ function tidyFields(fields) {
18
+ if (is.Undef(fields))
19
+ fields = h.fields();
20
+ else if (!Array.isArray(fields))
21
+ fields = [fields];
22
+ return fields;
23
+ }
24
+
25
+ function props(fields, key, val) {
26
+ if (is.Undef(fields)) {
27
+ fields = Object.keys({...h.fieldCtx, ...h.nameCtx});
28
+ } else if (!Array.isArray(fields)) {
29
+ fields = [fields];
30
+ }
31
+ fields.forEach(field => {
32
+ const ctxs = h.fieldCtx[field] || h.nameCtx[field];
33
+ ctxs && ctxs.forEach(ctx => {
34
+ $set(ctx.rule, key, val);
35
+ h.$render.clearCache(ctx);
36
+ });
37
+ })
38
+ }
39
+
40
+ function allSubForm() {
41
+ const subs = h.subForm;
42
+ return Object.keys(subs).reduce((initial, k) => {
43
+ const sub = subs[k];
44
+ if (!sub) return initial;
45
+ if (Array.isArray(sub))
46
+ initial.push(...sub);
47
+ else
48
+ initial.push(sub);
49
+ return initial;
50
+ }, []);
51
+ }
52
+
53
+ const api = {
54
+ get isScope() {
55
+ return h.vm.props.subForm === false;
56
+ },
57
+ get isPreview() {
58
+ return h.preview;
59
+ },
60
+ get config() {
61
+ return h.options
62
+ },
63
+ set config(val) {
64
+ h.fc.options.value = val;
65
+ },
66
+ get options() {
67
+ return h.options
68
+ },
69
+ set options(val) {
70
+ h.fc.options.value = val;
71
+ },
72
+ get form() {
73
+ return h.form
74
+ },
75
+ get rule() {
76
+ return h.rules
77
+ },
78
+ get parent() {
79
+ return h.vm.setupState.parent && h.vm.setupState.parent.setupState.fapi
80
+ },
81
+ get top() {
82
+ if (api.parent) {
83
+ return api.parent.top;
84
+ }
85
+ return api;
86
+ },
87
+ get scope() {
88
+ let parent = h.vm;
89
+ while (parent && parent.setupState.fapi) {
90
+ if (!parent.props.subForm) {
91
+ return parent.setupState.fapi;
92
+ } else {
93
+ parent = parent.setupState.parent;
94
+ }
95
+ }
96
+ return api.top;
97
+ },
98
+ get children() {
99
+ return allSubForm();
100
+ },
101
+ get siblings() {
102
+ const inject = h.vm.setupState.getGroupInject();
103
+ if (inject) {
104
+ const subForm = inject.getSubForm();
105
+ if (Array.isArray(subForm)) {
106
+ return [...subForm];
107
+ }
108
+ }
109
+ return undefined;
110
+ },
111
+ get index() {
112
+ const siblings = api.siblings;
113
+ if (siblings) {
114
+ const idx = siblings.indexOf(api);
115
+ return idx > -1 ? idx : undefined;
116
+ }
117
+ return undefined;
118
+ },
119
+ get formulas() {
120
+ return {...h.fc.formulas};
121
+ },
122
+ formData(fields) {
123
+ if (fields == null || typeof fields === 'boolean') {
124
+ const data = {};
125
+ Object.keys(h.form).forEach(k => {
126
+ if (fields === true || h.ignoreFields.indexOf(k) === -1) {
127
+ data[k] = copy(h.form[k]);
128
+ }
129
+ });
130
+ return data;
131
+ } else {
132
+ return tidyFields(fields).reduce((initial, id) => {
133
+ initial[id] = api.getValue(id);
134
+ return initial;
135
+ }, {});
136
+ }
137
+ },
138
+ getValue(field) {
139
+ const ctx = h.getFieldCtx(field);
140
+ if (!ctx) {
141
+ if (h.options.appendValue !== false && hasProperty(h.appendData, field)) {
142
+ return copy(h.appendData[field]);
143
+ }
144
+ return undefined;
145
+ }
146
+ return copy(ctx.rule.value);
147
+ },
148
+ coverValue(formData) {
149
+ const data = {...(formData || {})};
150
+ h.deferSyncValue(() => {
151
+ h.appendData = {};
152
+ api.fields().forEach(key => {
153
+ const ctxs = h.fieldCtx[key];
154
+ if (ctxs) {
155
+ const flag = hasProperty(formData, key);
156
+ ctxs.forEach(ctx => {
157
+ ctx.rule.value = flag ? formData[key] : undefined;
158
+ })
159
+ delete data[key];
160
+ }
161
+ });
162
+ extend(h.appendData, data);
163
+ }, true)
164
+ },
165
+ setValue(field) {
166
+ let formData = field;
167
+ if (arguments.length >= 2)
168
+ formData = {[field]: arguments[1]};
169
+ h.deferSyncValue(() => {
170
+ Object.keys(formData).forEach(key => {
171
+ const ctxs = h.fieldCtx[key];
172
+ if (!ctxs) return h.appendData[key] = formData[key];
173
+ ctxs.forEach(ctx => {
174
+ ctx.rule.value = formData[key];
175
+ });
176
+ });
177
+ }, true)
178
+ },
179
+ removeField(field) {
180
+ const ctx = h.getCtx(field);
181
+ h.deferSyncValue(() => {
182
+ h.getCtxs(field).forEach(ctx => {
183
+ ctx.rm();
184
+ });
185
+ }, true);
186
+ return ctx ? ctx.origin : undefined;
187
+ },
188
+ removeRule(rule) {
189
+ const ctx = rule && byCtx(rule);
190
+ if (!ctx) return;
191
+ ctx.rm();
192
+ return ctx.origin;
193
+ },
194
+ fields: () => h.fields(),
195
+ append: (rule, after, child) => {
196
+ let index = h.sort.length - 1, rules;
197
+ const ctx = h.getCtx(after);
198
+
199
+ if (ctx) {
200
+ if (child) {
201
+ rules = ctx.getPending('children', ctx.rule.children);
202
+ if (!Array.isArray(rules)) return;
203
+ index = ctx.rule.children.length - 1;
204
+ } else {
205
+ index = ctx.root.indexOf(ctx.origin);
206
+ rules = ctx.root;
207
+ }
208
+ } else rules = h.rules;
209
+ rules.splice(index + 1, 0, rule);
210
+ },
211
+ prepend: (rule, after, child) => {
212
+ let index = 0, rules;
213
+ const ctx = h.getCtx(after);
214
+
215
+ if (ctx) {
216
+ if (child) {
217
+ rules = ctx.getPending('children', ctx.rule.children);
218
+ if (!Array.isArray(rules)) return;
219
+ } else {
220
+ index = ctx.root.indexOf(ctx.origin);
221
+ rules = ctx.root;
222
+ }
223
+ } else rules = h.rules;
224
+ rules.splice(index, 0, rule);
225
+ },
226
+ hidden(state, fields) {
227
+ props(fields, 'hidden', !!state);
228
+ h.refresh();
229
+ },
230
+ hiddenStatus(id) {
231
+ const ctx = h.getCtx(id);
232
+ if (!ctx) return;
233
+ return !!ctx.rule.hidden;
234
+ },
235
+ display(state, fields) {
236
+ props(fields, 'display', !!state);
237
+ h.refresh();
238
+ },
239
+ displayStatus(id) {
240
+ const ctx = h.getCtx(id);
241
+ if (!ctx) return;
242
+ return !!ctx.rule.display;
243
+ },
244
+ disabled(disabled, fields) {
245
+ tidyFields(fields).forEach((field) => {
246
+ h.getCtxs(field).forEach(ctx => {
247
+ $set(ctx.rule.props, 'disabled', !!disabled);
248
+ });
249
+ });
250
+ h.refresh();
251
+ },
252
+ all(origin) {
253
+ return Object.keys(h.ctxs).map(k => {
254
+ const ctx = h.ctxs[k];
255
+ return origin ? ctx.origin : ctx.rule;
256
+ });
257
+ },
258
+ model(origin) {
259
+ return h.fields().reduce((initial, key) => {
260
+ const ctx = h.fieldCtx[key][0];
261
+ initial[key] = origin ? ctx.origin : ctx.rule;
262
+ return initial;
263
+ }, {});
264
+ },
265
+ component(origin) {
266
+ return Object.keys(h.nameCtx).reduce((initial, key) => {
267
+ const ctx = h.nameCtx[key].map(ctx => origin ? ctx.origin : ctx.rule);
268
+ initial[key] = ctx.length === 1 ? ctx[0] : ctx;
269
+ return initial;
270
+ }, {});
271
+ },
272
+ bind() {
273
+ return api.form;
274
+ },
275
+ reload: (rules) => {
276
+ h.reloadRule(rules)
277
+ },
278
+ updateOptions(options) {
279
+ h.fc.updateOptions(options);
280
+ api.refresh();
281
+ },
282
+ onSubmit(fn) {
283
+ api.updateOptions({onSubmit: fn});
284
+ },
285
+ sync: (field) => {
286
+ if (Array.isArray(field)) {
287
+ field.forEach(v => api.sync(v));
288
+ return;
289
+ }
290
+ let ctxs = is.Object(field) ? byCtx(field) : h.getCtxs(field);
291
+ if (!ctxs) {
292
+ return;
293
+ }
294
+ ctxs = Array.isArray(ctxs) ? ctxs : [ctxs];
295
+ ctxs.forEach(ctx => {
296
+ if (!ctx.deleted) {
297
+ const subForm = h.subForm[ctx.id];
298
+ if (subForm) {
299
+ if (Array.isArray(subForm)) {
300
+ subForm.forEach(form => {
301
+ form.refresh();
302
+ })
303
+ } else if (subForm) {
304
+ subForm.refresh();
305
+ }
306
+ }
307
+ //ctx.updateKey(true);
308
+ h.$render.clearCache(ctx);
309
+ }
310
+ });
311
+ h.refresh();
312
+ },
313
+ refresh: () => {
314
+ allSubForm().forEach(sub => {
315
+ sub.refresh();
316
+ });
317
+ h.$render.clearCacheAll();
318
+ h.refresh();
319
+ },
320
+ refreshOptions() {
321
+ h.$manager.updateOptions(h.options);
322
+ api.refresh();
323
+ },
324
+ hideForm: (hide) => {
325
+ h.vm.setupState.isShow = !hide;
326
+ },
327
+ changeStatus: () => {
328
+ return h.changeStatus;
329
+ },
330
+ clearChangeStatus: () => {
331
+ h.changeStatus = false;
332
+ },
333
+ updateRule(id, rule) {
334
+ h.getCtxs(id).forEach(ctx => {
335
+ extend(ctx.rule, rule);
336
+ });
337
+ },
338
+ updateRules(rules) {
339
+ Object.keys(rules).forEach(id => {
340
+ api.updateRule(id, rules[id]);
341
+ })
342
+ },
343
+ mergeRule: (id, rule) => {
344
+ h.getCtxs(id).forEach(ctx => {
345
+ mergeRule(ctx.rule, rule);
346
+ });
347
+ },
348
+ mergeRules(rules) {
349
+ Object.keys(rules).forEach(id => {
350
+ api.mergeRule(id, rules[id]);
351
+ })
352
+ },
353
+ getRule: (id, origin) => {
354
+ const ctx = h.getCtx(id);
355
+ if (ctx) {
356
+ return origin ? ctx.origin : ctx.rule;
357
+ }
358
+ },
359
+ findType(type, origin) {
360
+ let rule = undefined;
361
+ Object.keys(h.ctxs).forEach(k => {
362
+ const ctx = h.ctxs[k];
363
+ if (ctx.rule.type === type) {
364
+ rule = origin ? ctx.origin : ctx.rule;
365
+ }
366
+ });
367
+ return rule;
368
+ },
369
+ findTypes(type, origin) {
370
+ let rules = [];
371
+ Object.keys(h.ctxs).forEach(k => {
372
+ const ctx = h.ctxs[k];
373
+ if (ctx.rule.type === type) {
374
+ rules.push(origin ? ctx.origin : ctx.rule);
375
+ }
376
+ });
377
+ return rules;
378
+ },
379
+ getRenderRule: (id) => {
380
+ const ctx = h.getCtx(id);
381
+ if (ctx) {
382
+ return ctx.prop;
383
+ }
384
+ },
385
+ getRefRule: (id) => {
386
+ const ctxs = h.getCtxs(id);
387
+ if (ctxs) {
388
+ const rules = ctxs.map(ctx => {
389
+ return ctx.rule;
390
+ })
391
+ return rules.length === 1 ? rules[0] : rules;
392
+ }
393
+ },
394
+ setEffect(id, attr, value) {
395
+ const ctx = h.getCtx(id);
396
+ if (ctx && attr) {
397
+ if (attr[0] === '$') {
398
+ attr = attr.substr(1);
399
+ }
400
+ if (hasProperty(ctx.rule, '$' + attr)) {
401
+ $set(ctx.rule, '$' + attr, value);
402
+ }
403
+ if (!hasProperty(ctx.rule, 'effect')) {
404
+ ctx.rule.effect = {};
405
+ }
406
+ $set(ctx.rule.effect, attr, value);
407
+ }
408
+ },
409
+ clearEffectData(id, attr) {
410
+ const ctx = h.getCtx(id);
411
+ if (ctx) {
412
+ if (attr && attr[0] === '$') {
413
+ attr = attr.substr(1);
414
+ }
415
+ ctx.clearEffectData(attr);
416
+ api.sync(id);
417
+ }
418
+ },
419
+ updateValidate(id, validate, merge) {
420
+ if (merge) {
421
+ api.mergeRule(id, {validate})
422
+ } else {
423
+ props(id, 'validate', validate);
424
+ }
425
+ },
426
+ updateValidates(validates, merge) {
427
+ Object.keys(validates).forEach(id => {
428
+ api.updateValidate(id, validates[id], merge);
429
+ })
430
+ },
431
+ refreshValidate() {
432
+ api.refresh();
433
+ },
434
+ resetFields(fields) {
435
+ tidyFields(fields).forEach(field => {
436
+ h.getCtxs(field).forEach(ctx => {
437
+ h.$render.clearCache(ctx);
438
+ ctx.rule.value = copy(ctx.defaultValue);
439
+ });
440
+ });
441
+ nextTick(() => {
442
+ nextTick(() => {
443
+ nextTick(() => {
444
+ api.clearValidateState(fields);
445
+ });
446
+ });
447
+ });
448
+ if (fields == null) {
449
+ is.Function(h.options.onReset) && invoke(() => h.options.onReset(api));
450
+ h.vm.emit('reset', api);
451
+ }
452
+ },
453
+ method(id, name) {
454
+ const el = api.el(id);
455
+ if (!el || !el[name])
456
+ throw new Error(format('err', `${name} 方法不存在`));
457
+ return (...args) => {
458
+ return el[name](...args);
459
+ }
460
+ },
461
+ exec(id, name, ...args) {
462
+ return invoke(() => api.method(id, name)(...args));
463
+ },
464
+ toJson(space) {
465
+ return toJson(api.rule, space);
466
+ },
467
+ trigger(id, event, ...args) {
468
+ const el = api.el(id);
469
+ el && el.$emit(event, ...args);
470
+ },
471
+ el(id) {
472
+ const ctx = h.getCtx(id);
473
+ if (ctx) return ctx.el || h.vm.refs[ctx.ref];
474
+ },
475
+ closeModal: (id) => {
476
+ h.bus.$emit('fc:closeModal:' + id);
477
+ },
478
+ getSubForm(field) {
479
+ const ctx = h.getCtx(field);
480
+ return ctx ? h.subForm[ctx.id] : undefined;
481
+ },
482
+ getChildrenRuleList(id) {
483
+ const flag = typeof id === 'object';
484
+ const ctx = flag ? byCtx(id) : h.getCtx(id);
485
+ const rule = ctx ? ctx.rule : (flag ? id : api.getRule(id));
486
+ if (!rule) {
487
+ return [];
488
+ }
489
+ const rules = [];
490
+ const findRules = children => {
491
+ children && children.forEach(item => {
492
+ if (typeof item !== 'object') {
493
+ return;
494
+ }
495
+ if (item.field) {
496
+ rules.push(item);
497
+ }
498
+ rules.push(...api.getChildrenRuleList(item));
499
+ });
500
+ }
501
+ findRules(ctx ? ctx.loadChildrenPending() : rule.children);
502
+ return rules;
503
+ },
504
+ getParentRule(id) {
505
+ const flag = typeof id === 'object';
506
+ const ctx = flag ? byCtx(id) : h.getCtx(id);
507
+ return ctx.parent.rule;
508
+ },
509
+ getParentSubRule(id) {
510
+ const flag = typeof id === 'object';
511
+ const ctx = flag ? byCtx(id) : h.getCtx(id);
512
+ if (ctx) {
513
+ const group = ctx.getParentGroup();
514
+ if (group) {
515
+ return group.rule;
516
+ }
517
+ }
518
+ },
519
+ getChildrenFormData(id, flag) {
520
+ const rules = api.getChildrenRuleList(id);
521
+ return rules.reduce((formData, rule) => {
522
+ if (rule.ignore !== true || flag === true) {
523
+ formData[rule.field] = copy(rule.value);
524
+ }
525
+ return formData;
526
+ }, {});
527
+ },
528
+ setChildrenFormData(id, formData, cover) {
529
+ const rules = api.getChildrenRuleList(id);
530
+ h.deferSyncValue(() => {
531
+ rules.forEach(rule => {
532
+ if (hasProperty(formData, rule.field)) {
533
+ rule.value = formData[rule.field];
534
+ } else if (cover) {
535
+ rule.value = undefined;
536
+ }
537
+ });
538
+ });
539
+ },
540
+ getGlobalEvent(name) {
541
+ let event = api.options.globalEvent[name];
542
+ if (event) {
543
+ if (typeof event === 'object') {
544
+ event = event.handle;
545
+ }
546
+ return parseFn(event);
547
+ }
548
+ return undefined;
549
+ },
550
+ getGlobalData(name) {
551
+ return new Promise((resolve, inject) => {
552
+ let config = api.options.globalData[name];
553
+ if (!config) {
554
+ resolve(h.fc.loadData[name]);
555
+ } else if (config.type === 'fetch') {
556
+ api.fetch(config).then(res => {
557
+ resolve(res);
558
+ }).catch(inject);
559
+ } else {
560
+ resolve(config.data);
561
+ }
562
+ });
563
+ },
564
+ emitGlobalEvent(name, ...args) {
565
+ const fn = api.getGlobalEvent(name);
566
+ if(fn) {
567
+ const data = h.getInjectData({}, undefined);
568
+ data.args = [...args];
569
+ args.unshift(data);
570
+ return fn.apply(null, args);
571
+ }
572
+ },
573
+ setGlobalData(name, value) {
574
+ api.setData('$globalData.' + name, value);
575
+ },
576
+ setGlobalVar(name, value) {
577
+ api.setData('$var.' + name, value);
578
+ },
579
+ renderRule(id, onInput, force) {
580
+ const flag = typeof id === 'object';
581
+ const ctx = flag ? byCtx(id) : h.getCtx(id);
582
+ return ctx ? h.$render.createRuleVnode(ctx, onInput, force) : undefined;
583
+ },
584
+ renderChildren(id, onInput, force) {
585
+ const flag = typeof id === 'object';
586
+ const ctx = flag ? byCtx(id) : h.getCtx(id);
587
+ return ctx ? h.$render.createChildrenVnodes(ctx, onInput, force) : undefined;
588
+ },
589
+ nextTick(fn) {
590
+ h.bus.$once('next-tick', fn);
591
+ h.refresh();
592
+ },
593
+ nextRefresh(fn) {
594
+ h.nextRefresh();
595
+ fn && invoke(fn);
596
+ },
597
+ deferSyncValue(fn, sync) {
598
+ h.deferSyncValue(fn, sync);
599
+ },
600
+ emit(name, ...args) {
601
+ if (h.vm.emitsOptions && !h.vm.emitsOptions[name]) {
602
+ h.vm.emitsOptions[name] = null;
603
+ }
604
+ h.vm.emit(name, ...args);
605
+ },
606
+ bus: h.bus,
607
+ getCurrentFormRule() {
608
+ return h.vm.setupState.getGroupInject()?.rule;
609
+ },
610
+ fetch(opt) {
611
+ return new Promise((resolve, reject) => {
612
+ opt = deepCopy(opt);
613
+ opt = h.loadFetchVar(opt);
614
+ const fail = (e) => {
615
+ invoke(() => opt.onError && opt.onError(e));
616
+ reject(e);
617
+ }
618
+ h.beforeFetch(opt).then(() => {
619
+ return asyncFetch(opt, h.fc.create.fetch, api).then((res) => {
620
+ invoke(() => opt.onSuccess && opt.onSuccess(res));
621
+ resolve(res);
622
+ }).catch((e) => {
623
+ fail(e);
624
+ });
625
+ }).catch(e => {
626
+ fail(e);
627
+ });
628
+ });
629
+ },
630
+ watchFetch(opt, callback, error, beforeFetch) {
631
+ return h.fc.watchLoadData((get, change) => {
632
+ let _opt = deepCopy(opt);
633
+ _opt = h.loadFetchVar(_opt, get);
634
+ if (beforeFetch && beforeFetch(_opt, change) === false) {
635
+ return;
636
+ }
637
+ const fail = (e) => {
638
+ invoke(() => _opt.onError && _opt.onError(e));
639
+ error && error(e);
640
+ }
641
+ h.beforeFetch(_opt).then(() => {
642
+ return asyncFetch(_opt, h.fc.create.fetch, api).then(res => {
643
+ invoke(() => _opt.onSuccess && _opt.onSuccess(res));
644
+ callback && callback(res, change);
645
+ }).catch(e => {
646
+ fail(e);
647
+ });
648
+ }).catch(e => {
649
+ fail(e);
650
+ });
651
+ }, opt.wait == null ? 1000 : opt.wait);
652
+ },
653
+ getData(id, def) {
654
+ if (h.fc.get) {
655
+ return h.fc.get(id, def);
656
+ } else {
657
+ return h.fc.getLoadData(id, def);
658
+ }
659
+ },
660
+ watchData(fn) {
661
+ return h.fc.watchLoadData((get, change) => {
662
+ invoke(() => fn(get, change));
663
+ })
664
+ },
665
+ setData(id, data, isGlobal) {
666
+ return h.fc.setData(id, data, isGlobal);
667
+ },
668
+ refreshData(id) {
669
+ return h.fc.refreshData(id);
670
+ },
671
+ t(id, params) {
672
+ return h.fc.t(id, params);
673
+ },
674
+ getLocale() {
675
+ return h.fc.getLocale();
676
+ },
677
+ helper: {
678
+ tidyFields, props
679
+ }
680
+ };
681
+
682
+ ['on', 'once', 'off'].forEach(n => {
683
+ api[n] = function (...args) {
684
+ h.bus[`$${n}`](...args);
685
+ }
686
+ });
687
+
688
+ api.changeValue = api.changeField = api.setValue;
689
+
690
+ return api;
691
+ }
@@ -0,0 +1,12 @@
1
+ import {functionalMerge, normalMerge, toArrayMerge} from '../../../utils/lib/mergeprops';
2
+
3
+
4
+ export const keyAttrs = ['type', 'slot', 'ignore', 'emitPrefix', 'value', 'name', 'native', 'hidden', 'display', 'inject', 'options', 'emit', 'link', 'prefix', 'suffix', 'update', 'sync', 'optionsTo', 'key', 'slotUpdate', 'computed', 'preview', 'component', 'cache', 'modelEmit'];
5
+
6
+ export const arrayAttrs = ['validate', 'children', 'control'];
7
+
8
+ export const normalAttrs = ['effect', 'deep', 'renderSlots'];
9
+
10
+ export function attrs() {
11
+ return [...keyAttrs, ...normalMerge, ...toArrayMerge, ...functionalMerge, ...arrayAttrs, ...normalAttrs];
12
+ }