@easy-editor/react-renderer 0.0.17 → 0.0.18

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/dist/esm/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { observer } from 'mobx-react';
2
2
  import { createContext, useContext, useMemo, Component, forwardRef, createElement, PureComponent } from 'react';
3
- import { isSetterConfig, createLogger, isJSExpression, DESIGNER_EVENT, TRANSFORM_STAGE, isJSFunction, logger as logger$1 } from '@easy-editor/core';
3
+ import { isSetterConfig, isJSExpression, isJSFunction, createLogger, DESIGNER_EVENT, TRANSFORM_STAGE, logger as logger$1 } from '@easy-editor/core';
4
4
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
5
5
 
6
6
  const SettingRendererContext = /*#__PURE__*/createContext({});
@@ -284,12 +284,12 @@ var root = freeGlobal || freeSelf || Function('return this')();
284
284
 
285
285
  var Symbol = root.Symbol;
286
286
 
287
- var objectProto$7 = Object.prototype;
288
- var hasOwnProperty$5 = objectProto$7.hasOwnProperty;
289
- var nativeObjectToString$1 = objectProto$7.toString;
287
+ var objectProto$c = Object.prototype;
288
+ var hasOwnProperty$a = objectProto$c.hasOwnProperty;
289
+ var nativeObjectToString$1 = objectProto$c.toString;
290
290
  var symToStringTag$1 = Symbol ? Symbol.toStringTag : undefined;
291
291
  function getRawTag(value) {
292
- var isOwn = hasOwnProperty$5.call(value, symToStringTag$1),
292
+ var isOwn = hasOwnProperty$a.call(value, symToStringTag$1),
293
293
  tag = value[symToStringTag$1];
294
294
  try {
295
295
  value[symToStringTag$1] = undefined;
@@ -306,8 +306,8 @@ function getRawTag(value) {
306
306
  return result;
307
307
  }
308
308
 
309
- var objectProto$6 = Object.prototype;
310
- var nativeObjectToString = objectProto$6.toString;
309
+ var objectProto$b = Object.prototype;
310
+ var nativeObjectToString = objectProto$b.toString;
311
311
  function objectToString(value) {
312
312
  return nativeObjectToString.call(value);
313
313
  }
@@ -345,7 +345,7 @@ function baseTrim(string) {
345
345
  return string ? string.slice(0, trimmedEndIndex(string) + 1).replace(reTrimStart, '') : string;
346
346
  }
347
347
 
348
- function isObject(value) {
348
+ function isObject$1(value) {
349
349
  var type = typeof value;
350
350
  return value != null && (type == 'object' || type == 'function');
351
351
  }
@@ -362,9 +362,9 @@ function toNumber(value) {
362
362
  if (isSymbol(value)) {
363
363
  return NAN;
364
364
  }
365
- if (isObject(value)) {
365
+ if (isObject$1(value)) {
366
366
  var other = typeof value.valueOf == 'function' ? value.valueOf() : value;
367
- value = isObject(other) ? other + '' : other;
367
+ value = isObject$1(other) ? other + '' : other;
368
368
  }
369
369
  if (typeof value != 'string') {
370
370
  return value === 0 ? value : +value;
@@ -383,7 +383,7 @@ var asyncTag = '[object AsyncFunction]',
383
383
  genTag = '[object GeneratorFunction]',
384
384
  proxyTag = '[object Proxy]';
385
385
  function isFunction(value) {
386
- if (!isObject(value)) {
386
+ if (!isObject$1(value)) {
387
387
  return false;
388
388
  }
389
389
  var tag = baseGetTag(value);
@@ -400,12 +400,12 @@ function isMasked(func) {
400
400
  return !!maskSrcKey && maskSrcKey in func;
401
401
  }
402
402
 
403
- var funcProto$1 = Function.prototype;
404
- var funcToString$1 = funcProto$1.toString;
403
+ var funcProto$2 = Function.prototype;
404
+ var funcToString$2 = funcProto$2.toString;
405
405
  function toSource(func) {
406
406
  if (func != null) {
407
407
  try {
408
- return funcToString$1.call(func);
408
+ return funcToString$2.call(func);
409
409
  } catch (e) {}
410
410
  try {
411
411
  return func + '';
@@ -416,13 +416,13 @@ function toSource(func) {
416
416
 
417
417
  var reRegExpChar = /[\\^$.*+?()[\]{}|]/g;
418
418
  var reIsHostCtor = /^\[object .+?Constructor\]$/;
419
- var funcProto = Function.prototype,
420
- objectProto$5 = Object.prototype;
421
- var funcToString = funcProto.toString;
422
- var hasOwnProperty$4 = objectProto$5.hasOwnProperty;
423
- var reIsNative = RegExp('^' + funcToString.call(hasOwnProperty$4).replace(reRegExpChar, '\\$&').replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$');
419
+ var funcProto$1 = Function.prototype,
420
+ objectProto$a = Object.prototype;
421
+ var funcToString$1 = funcProto$1.toString;
422
+ var hasOwnProperty$9 = objectProto$a.hasOwnProperty;
423
+ var reIsNative = RegExp('^' + funcToString$1.call(hasOwnProperty$9).replace(reRegExpChar, '\\$&').replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$');
424
424
  function baseIsNative(value) {
425
- if (!isObject(value) || isMasked(value)) {
425
+ if (!isObject$1(value) || isMasked(value)) {
426
426
  return false;
427
427
  }
428
428
  var pattern = isFunction(value) ? reIsNative : reIsHostCtor;
@@ -440,6 +440,93 @@ function getNative(object, key) {
440
440
 
441
441
  var WeakMap = getNative(root, 'WeakMap');
442
442
 
443
+ var objectCreate = Object.create;
444
+ var baseCreate = function () {
445
+ function object() {}
446
+ return function (proto) {
447
+ if (!isObject$1(proto)) {
448
+ return {};
449
+ }
450
+ if (objectCreate) {
451
+ return objectCreate(proto);
452
+ }
453
+ object.prototype = proto;
454
+ var result = new object();
455
+ object.prototype = undefined;
456
+ return result;
457
+ };
458
+ }();
459
+
460
+ function apply(func, thisArg, args) {
461
+ switch (args.length) {
462
+ case 0:
463
+ return func.call(thisArg);
464
+ case 1:
465
+ return func.call(thisArg, args[0]);
466
+ case 2:
467
+ return func.call(thisArg, args[0], args[1]);
468
+ case 3:
469
+ return func.call(thisArg, args[0], args[1], args[2]);
470
+ }
471
+ return func.apply(thisArg, args);
472
+ }
473
+
474
+ function copyArray(source, array) {
475
+ var index = -1,
476
+ length = source.length;
477
+ array || (array = Array(length));
478
+ while (++index < length) {
479
+ array[index] = source[index];
480
+ }
481
+ return array;
482
+ }
483
+
484
+ var HOT_COUNT = 800,
485
+ HOT_SPAN = 16;
486
+ var nativeNow = Date.now;
487
+ function shortOut(func) {
488
+ var count = 0,
489
+ lastCalled = 0;
490
+ return function () {
491
+ var stamp = nativeNow(),
492
+ remaining = HOT_SPAN - (stamp - lastCalled);
493
+ lastCalled = stamp;
494
+ if (remaining > 0) {
495
+ if (++count >= HOT_COUNT) {
496
+ return arguments[0];
497
+ }
498
+ } else {
499
+ count = 0;
500
+ }
501
+ return func.apply(undefined, arguments);
502
+ };
503
+ }
504
+
505
+ function constant(value) {
506
+ return function () {
507
+ return value;
508
+ };
509
+ }
510
+
511
+ var defineProperty = function () {
512
+ try {
513
+ var func = getNative(Object, 'defineProperty');
514
+ func({}, '', {});
515
+ return func;
516
+ } catch (e) {}
517
+ }();
518
+
519
+ var baseSetToString = !defineProperty ? identity : function (func, string) {
520
+ return defineProperty(func, 'toString', {
521
+ 'configurable': true,
522
+ 'enumerable': false,
523
+ 'value': constant(string),
524
+ 'writable': true
525
+ });
526
+ };
527
+
528
+ var setToString = shortOut(baseSetToString);
529
+
443
530
  function arrayEach(array, iteratee) {
444
531
  var index = -1,
445
532
  length = array == null ? 0 : array.length;
@@ -459,6 +546,77 @@ function isIndex(value, length) {
459
546
  return !!length && (type == 'number' || type != 'symbol' && reIsUint.test(value)) && value > -1 && value % 1 == 0 && value < length;
460
547
  }
461
548
 
549
+ function baseAssignValue(object, key, value) {
550
+ if (key == '__proto__' && defineProperty) {
551
+ defineProperty(object, key, {
552
+ 'configurable': true,
553
+ 'enumerable': true,
554
+ 'value': value,
555
+ 'writable': true
556
+ });
557
+ } else {
558
+ object[key] = value;
559
+ }
560
+ }
561
+
562
+ function eq(value, other) {
563
+ return value === other || value !== value && other !== other;
564
+ }
565
+
566
+ var objectProto$9 = Object.prototype;
567
+ var hasOwnProperty$8 = objectProto$9.hasOwnProperty;
568
+ function assignValue(object, key, value) {
569
+ var objValue = object[key];
570
+ if (!(hasOwnProperty$8.call(object, key) && eq(objValue, value)) || value === undefined && !(key in object)) {
571
+ baseAssignValue(object, key, value);
572
+ }
573
+ }
574
+
575
+ function copyObject(source, props, object, customizer) {
576
+ var isNew = !object;
577
+ object || (object = {});
578
+ var index = -1,
579
+ length = props.length;
580
+ while (++index < length) {
581
+ var key = props[index];
582
+ var newValue = undefined;
583
+ if (newValue === undefined) {
584
+ newValue = source[key];
585
+ }
586
+ if (isNew) {
587
+ baseAssignValue(object, key, newValue);
588
+ } else {
589
+ assignValue(object, key, newValue);
590
+ }
591
+ }
592
+ return object;
593
+ }
594
+
595
+ var nativeMax$1 = Math.max;
596
+ function overRest(func, start, transform) {
597
+ start = nativeMax$1(start === undefined ? func.length - 1 : start, 0);
598
+ return function () {
599
+ var args = arguments,
600
+ index = -1,
601
+ length = nativeMax$1(args.length - start, 0),
602
+ array = Array(length);
603
+ while (++index < length) {
604
+ array[index] = args[start + index];
605
+ }
606
+ index = -1;
607
+ var otherArgs = Array(start + 1);
608
+ while (++index < start) {
609
+ otherArgs[index] = args[index];
610
+ }
611
+ otherArgs[start] = transform(array);
612
+ return apply(func, this, otherArgs);
613
+ };
614
+ }
615
+
616
+ function baseRest(func, start) {
617
+ return setToString(overRest(func, start, identity), func + '');
618
+ }
619
+
462
620
  var MAX_SAFE_INTEGER = 9007199254740991;
463
621
  function isLength(value) {
464
622
  return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
@@ -468,10 +626,43 @@ function isArrayLike(value) {
468
626
  return value != null && isLength(value.length) && !isFunction(value);
469
627
  }
470
628
 
471
- var objectProto$4 = Object.prototype;
629
+ function isIterateeCall(value, index, object) {
630
+ if (!isObject$1(object)) {
631
+ return false;
632
+ }
633
+ var type = typeof index;
634
+ if (type == 'number' ? isArrayLike(object) && isIndex(index, object.length) : type == 'string' && index in object) {
635
+ return eq(object[index], value);
636
+ }
637
+ return false;
638
+ }
639
+
640
+ function createAssigner(assigner) {
641
+ return baseRest(function (object, sources) {
642
+ var index = -1,
643
+ length = sources.length,
644
+ customizer = length > 1 ? sources[length - 1] : undefined,
645
+ guard = length > 2 ? sources[2] : undefined;
646
+ customizer = assigner.length > 3 && typeof customizer == 'function' ? (length--, customizer) : undefined;
647
+ if (guard && isIterateeCall(sources[0], sources[1], guard)) {
648
+ customizer = length < 3 ? undefined : customizer;
649
+ length = 1;
650
+ }
651
+ object = Object(object);
652
+ while (++index < length) {
653
+ var source = sources[index];
654
+ if (source) {
655
+ assigner(object, source, index, customizer);
656
+ }
657
+ }
658
+ return object;
659
+ });
660
+ }
661
+
662
+ var objectProto$8 = Object.prototype;
472
663
  function isPrototype(value) {
473
664
  var Ctor = value && value.constructor,
474
- proto = typeof Ctor == 'function' && Ctor.prototype || objectProto$4;
665
+ proto = typeof Ctor == 'function' && Ctor.prototype || objectProto$8;
475
666
  return value === proto;
476
667
  }
477
668
 
@@ -489,24 +680,24 @@ function baseIsArguments(value) {
489
680
  return isObjectLike(value) && baseGetTag(value) == argsTag$1;
490
681
  }
491
682
 
492
- var objectProto$3 = Object.prototype;
493
- var hasOwnProperty$3 = objectProto$3.hasOwnProperty;
494
- var propertyIsEnumerable = objectProto$3.propertyIsEnumerable;
683
+ var objectProto$7 = Object.prototype;
684
+ var hasOwnProperty$7 = objectProto$7.hasOwnProperty;
685
+ var propertyIsEnumerable = objectProto$7.propertyIsEnumerable;
495
686
  var isArguments = baseIsArguments(function () {
496
687
  return arguments;
497
688
  }()) ? baseIsArguments : function (value) {
498
- return isObjectLike(value) && hasOwnProperty$3.call(value, 'callee') && !propertyIsEnumerable.call(value, 'callee');
689
+ return isObjectLike(value) && hasOwnProperty$7.call(value, 'callee') && !propertyIsEnumerable.call(value, 'callee');
499
690
  };
500
691
 
501
692
  function stubFalse() {
502
693
  return false;
503
694
  }
504
695
 
505
- var freeExports$1 = typeof exports == 'object' && exports && !exports.nodeType && exports;
506
- var freeModule$1 = freeExports$1 && typeof module == 'object' && module && !module.nodeType && module;
507
- var moduleExports$1 = freeModule$1 && freeModule$1.exports === freeExports$1;
508
- var Buffer = moduleExports$1 ? root.Buffer : undefined;
509
- var nativeIsBuffer = Buffer ? Buffer.isBuffer : undefined;
696
+ var freeExports$2 = typeof exports == 'object' && exports && !exports.nodeType && exports;
697
+ var freeModule$2 = freeExports$2 && typeof module == 'object' && module && !module.nodeType && module;
698
+ var moduleExports$2 = freeModule$2 && freeModule$2.exports === freeExports$2;
699
+ var Buffer$1 = moduleExports$2 ? root.Buffer : undefined;
700
+ var nativeIsBuffer = Buffer$1 ? Buffer$1.isBuffer : undefined;
510
701
  var isBuffer = nativeIsBuffer || stubFalse;
511
702
 
512
703
  var argsTag = '[object Arguments]',
@@ -517,7 +708,7 @@ var argsTag = '[object Arguments]',
517
708
  funcTag = '[object Function]',
518
709
  mapTag$2 = '[object Map]',
519
710
  numberTag = '[object Number]',
520
- objectTag$1 = '[object Object]',
711
+ objectTag$2 = '[object Object]',
521
712
  regexpTag = '[object RegExp]',
522
713
  setTag$2 = '[object Set]',
523
714
  stringTag = '[object String]',
@@ -535,7 +726,7 @@ var arrayBufferTag = '[object ArrayBuffer]',
535
726
  uint32Tag = '[object Uint32Array]';
536
727
  var typedArrayTags = {};
537
728
  typedArrayTags[float32Tag] = typedArrayTags[float64Tag] = typedArrayTags[int8Tag] = typedArrayTags[int16Tag] = typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] = typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] = typedArrayTags[uint32Tag] = true;
538
- typedArrayTags[argsTag] = typedArrayTags[arrayTag] = typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] = typedArrayTags[dataViewTag$1] = typedArrayTags[dateTag] = typedArrayTags[errorTag] = typedArrayTags[funcTag] = typedArrayTags[mapTag$2] = typedArrayTags[numberTag] = typedArrayTags[objectTag$1] = typedArrayTags[regexpTag] = typedArrayTags[setTag$2] = typedArrayTags[stringTag] = typedArrayTags[weakMapTag$1] = false;
729
+ typedArrayTags[argsTag] = typedArrayTags[arrayTag] = typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] = typedArrayTags[dataViewTag$1] = typedArrayTags[dateTag] = typedArrayTags[errorTag] = typedArrayTags[funcTag] = typedArrayTags[mapTag$2] = typedArrayTags[numberTag] = typedArrayTags[objectTag$2] = typedArrayTags[regexpTag] = typedArrayTags[setTag$2] = typedArrayTags[stringTag] = typedArrayTags[weakMapTag$1] = false;
539
730
  function baseIsTypedArray(value) {
540
731
  return isObjectLike(value) && isLength(value.length) && !!typedArrayTags[baseGetTag(value)];
541
732
  }
@@ -546,13 +737,13 @@ function baseUnary(func) {
546
737
  };
547
738
  }
548
739
 
549
- var freeExports = typeof exports == 'object' && exports && !exports.nodeType && exports;
550
- var freeModule = freeExports && typeof module == 'object' && module && !module.nodeType && module;
551
- var moduleExports = freeModule && freeModule.exports === freeExports;
552
- var freeProcess = moduleExports && freeGlobal.process;
740
+ var freeExports$1 = typeof exports == 'object' && exports && !exports.nodeType && exports;
741
+ var freeModule$1 = freeExports$1 && typeof module == 'object' && module && !module.nodeType && module;
742
+ var moduleExports$1 = freeModule$1 && freeModule$1.exports === freeExports$1;
743
+ var freeProcess = moduleExports$1 && freeGlobal.process;
553
744
  var nodeUtil = function () {
554
745
  try {
555
- var types = freeModule && freeModule.require && freeModule.require('util').types;
746
+ var types = freeModule$1 && freeModule$1.require && freeModule$1.require('util').types;
556
747
  if (types) {
557
748
  return types;
558
749
  }
@@ -563,8 +754,8 @@ var nodeUtil = function () {
563
754
  var nodeIsTypedArray = nodeUtil && nodeUtil.isTypedArray;
564
755
  var isTypedArray = nodeIsTypedArray ? baseUnary(nodeIsTypedArray) : baseIsTypedArray;
565
756
 
566
- var objectProto$2 = Object.prototype;
567
- var hasOwnProperty$2 = objectProto$2.hasOwnProperty;
757
+ var objectProto$6 = Object.prototype;
758
+ var hasOwnProperty$6 = objectProto$6.hasOwnProperty;
568
759
  function arrayLikeKeys(value, inherited) {
569
760
  var isArr = isArray(value),
570
761
  isArg = !isArr && isArguments(value),
@@ -574,7 +765,7 @@ function arrayLikeKeys(value, inherited) {
574
765
  result = skipIndexes ? baseTimes(value.length, String) : [],
575
766
  length = result.length;
576
767
  for (var key in value) {
577
- if ((hasOwnProperty$2.call(value, key)) && !(skipIndexes && (
768
+ if ((inherited || hasOwnProperty$6.call(value, key)) && !(skipIndexes && (
578
769
  key == 'length' ||
579
770
  isBuff && (key == 'offset' || key == 'parent') ||
580
771
  isType && (key == 'buffer' || key == 'byteLength' || key == 'byteOffset') ||
@@ -593,15 +784,15 @@ function overArg(func, transform) {
593
784
 
594
785
  var nativeKeys = overArg(Object.keys, Object);
595
786
 
596
- var objectProto$1 = Object.prototype;
597
- var hasOwnProperty$1 = objectProto$1.hasOwnProperty;
787
+ var objectProto$5 = Object.prototype;
788
+ var hasOwnProperty$5 = objectProto$5.hasOwnProperty;
598
789
  function baseKeys(object) {
599
790
  if (!isPrototype(object)) {
600
791
  return nativeKeys(object);
601
792
  }
602
793
  var result = [];
603
794
  for (var key in Object(object)) {
604
- if (hasOwnProperty$1.call(object, key) && key != 'constructor') {
795
+ if (hasOwnProperty$5.call(object, key) && key != 'constructor') {
605
796
  result.push(key);
606
797
  }
607
798
  }
@@ -612,8 +803,297 @@ function keys(object) {
612
803
  return isArrayLike(object) ? arrayLikeKeys(object) : baseKeys(object);
613
804
  }
614
805
 
806
+ function nativeKeysIn(object) {
807
+ var result = [];
808
+ if (object != null) {
809
+ for (var key in Object(object)) {
810
+ result.push(key);
811
+ }
812
+ }
813
+ return result;
814
+ }
815
+
816
+ var objectProto$4 = Object.prototype;
817
+ var hasOwnProperty$4 = objectProto$4.hasOwnProperty;
818
+ function baseKeysIn(object) {
819
+ if (!isObject$1(object)) {
820
+ return nativeKeysIn(object);
821
+ }
822
+ var isProto = isPrototype(object),
823
+ result = [];
824
+ for (var key in object) {
825
+ if (!(key == 'constructor' && (isProto || !hasOwnProperty$4.call(object, key)))) {
826
+ result.push(key);
827
+ }
828
+ }
829
+ return result;
830
+ }
831
+
832
+ function keysIn(object) {
833
+ return isArrayLike(object) ? arrayLikeKeys(object, true) : baseKeysIn(object);
834
+ }
835
+
836
+ var nativeCreate = getNative(Object, 'create');
837
+
838
+ function hashClear() {
839
+ this.__data__ = nativeCreate ? nativeCreate(null) : {};
840
+ this.size = 0;
841
+ }
842
+
843
+ function hashDelete(key) {
844
+ var result = this.has(key) && delete this.__data__[key];
845
+ this.size -= result ? 1 : 0;
846
+ return result;
847
+ }
848
+
849
+ var HASH_UNDEFINED$1 = '__lodash_hash_undefined__';
850
+ var objectProto$3 = Object.prototype;
851
+ var hasOwnProperty$3 = objectProto$3.hasOwnProperty;
852
+ function hashGet(key) {
853
+ var data = this.__data__;
854
+ if (nativeCreate) {
855
+ var result = data[key];
856
+ return result === HASH_UNDEFINED$1 ? undefined : result;
857
+ }
858
+ return hasOwnProperty$3.call(data, key) ? data[key] : undefined;
859
+ }
860
+
861
+ var objectProto$2 = Object.prototype;
862
+ var hasOwnProperty$2 = objectProto$2.hasOwnProperty;
863
+ function hashHas(key) {
864
+ var data = this.__data__;
865
+ return nativeCreate ? data[key] !== undefined : hasOwnProperty$2.call(data, key);
866
+ }
867
+
868
+ var HASH_UNDEFINED = '__lodash_hash_undefined__';
869
+ function hashSet(key, value) {
870
+ var data = this.__data__;
871
+ this.size += this.has(key) ? 0 : 1;
872
+ data[key] = nativeCreate && value === undefined ? HASH_UNDEFINED : value;
873
+ return this;
874
+ }
875
+
876
+ function Hash(entries) {
877
+ var index = -1,
878
+ length = entries == null ? 0 : entries.length;
879
+ this.clear();
880
+ while (++index < length) {
881
+ var entry = entries[index];
882
+ this.set(entry[0], entry[1]);
883
+ }
884
+ }
885
+ Hash.prototype.clear = hashClear;
886
+ Hash.prototype['delete'] = hashDelete;
887
+ Hash.prototype.get = hashGet;
888
+ Hash.prototype.has = hashHas;
889
+ Hash.prototype.set = hashSet;
890
+
891
+ function listCacheClear() {
892
+ this.__data__ = [];
893
+ this.size = 0;
894
+ }
895
+
896
+ function assocIndexOf(array, key) {
897
+ var length = array.length;
898
+ while (length--) {
899
+ if (eq(array[length][0], key)) {
900
+ return length;
901
+ }
902
+ }
903
+ return -1;
904
+ }
905
+
906
+ var arrayProto = Array.prototype;
907
+ var splice = arrayProto.splice;
908
+ function listCacheDelete(key) {
909
+ var data = this.__data__,
910
+ index = assocIndexOf(data, key);
911
+ if (index < 0) {
912
+ return false;
913
+ }
914
+ var lastIndex = data.length - 1;
915
+ if (index == lastIndex) {
916
+ data.pop();
917
+ } else {
918
+ splice.call(data, index, 1);
919
+ }
920
+ --this.size;
921
+ return true;
922
+ }
923
+
924
+ function listCacheGet(key) {
925
+ var data = this.__data__,
926
+ index = assocIndexOf(data, key);
927
+ return index < 0 ? undefined : data[index][1];
928
+ }
929
+
930
+ function listCacheHas(key) {
931
+ return assocIndexOf(this.__data__, key) > -1;
932
+ }
933
+
934
+ function listCacheSet(key, value) {
935
+ var data = this.__data__,
936
+ index = assocIndexOf(data, key);
937
+ if (index < 0) {
938
+ ++this.size;
939
+ data.push([key, value]);
940
+ } else {
941
+ data[index][1] = value;
942
+ }
943
+ return this;
944
+ }
945
+
946
+ function ListCache(entries) {
947
+ var index = -1,
948
+ length = entries == null ? 0 : entries.length;
949
+ this.clear();
950
+ while (++index < length) {
951
+ var entry = entries[index];
952
+ this.set(entry[0], entry[1]);
953
+ }
954
+ }
955
+ ListCache.prototype.clear = listCacheClear;
956
+ ListCache.prototype['delete'] = listCacheDelete;
957
+ ListCache.prototype.get = listCacheGet;
958
+ ListCache.prototype.has = listCacheHas;
959
+ ListCache.prototype.set = listCacheSet;
960
+
615
961
  var Map$1 = getNative(root, 'Map');
616
962
 
963
+ function mapCacheClear() {
964
+ this.size = 0;
965
+ this.__data__ = {
966
+ 'hash': new Hash(),
967
+ 'map': new (Map$1 || ListCache)(),
968
+ 'string': new Hash()
969
+ };
970
+ }
971
+
972
+ function isKeyable(value) {
973
+ var type = typeof value;
974
+ return type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean' ? value !== '__proto__' : value === null;
975
+ }
976
+
977
+ function getMapData(map, key) {
978
+ var data = map.__data__;
979
+ return isKeyable(key) ? data[typeof key == 'string' ? 'string' : 'hash'] : data.map;
980
+ }
981
+
982
+ function mapCacheDelete(key) {
983
+ var result = getMapData(this, key)['delete'](key);
984
+ this.size -= result ? 1 : 0;
985
+ return result;
986
+ }
987
+
988
+ function mapCacheGet(key) {
989
+ return getMapData(this, key).get(key);
990
+ }
991
+
992
+ function mapCacheHas(key) {
993
+ return getMapData(this, key).has(key);
994
+ }
995
+
996
+ function mapCacheSet(key, value) {
997
+ var data = getMapData(this, key),
998
+ size = data.size;
999
+ data.set(key, value);
1000
+ this.size += data.size == size ? 0 : 1;
1001
+ return this;
1002
+ }
1003
+
1004
+ function MapCache(entries) {
1005
+ var index = -1,
1006
+ length = entries == null ? 0 : entries.length;
1007
+ this.clear();
1008
+ while (++index < length) {
1009
+ var entry = entries[index];
1010
+ this.set(entry[0], entry[1]);
1011
+ }
1012
+ }
1013
+ MapCache.prototype.clear = mapCacheClear;
1014
+ MapCache.prototype['delete'] = mapCacheDelete;
1015
+ MapCache.prototype.get = mapCacheGet;
1016
+ MapCache.prototype.has = mapCacheHas;
1017
+ MapCache.prototype.set = mapCacheSet;
1018
+
1019
+ var getPrototype = overArg(Object.getPrototypeOf, Object);
1020
+
1021
+ var objectTag$1 = '[object Object]';
1022
+ var funcProto = Function.prototype,
1023
+ objectProto$1 = Object.prototype;
1024
+ var funcToString = funcProto.toString;
1025
+ var hasOwnProperty$1 = objectProto$1.hasOwnProperty;
1026
+ var objectCtorString = funcToString.call(Object);
1027
+ function isPlainObject(value) {
1028
+ if (!isObjectLike(value) || baseGetTag(value) != objectTag$1) {
1029
+ return false;
1030
+ }
1031
+ var proto = getPrototype(value);
1032
+ if (proto === null) {
1033
+ return true;
1034
+ }
1035
+ var Ctor = hasOwnProperty$1.call(proto, 'constructor') && proto.constructor;
1036
+ return typeof Ctor == 'function' && Ctor instanceof Ctor && funcToString.call(Ctor) == objectCtorString;
1037
+ }
1038
+
1039
+ function stackClear() {
1040
+ this.__data__ = new ListCache();
1041
+ this.size = 0;
1042
+ }
1043
+
1044
+ function stackDelete(key) {
1045
+ var data = this.__data__,
1046
+ result = data['delete'](key);
1047
+ this.size = data.size;
1048
+ return result;
1049
+ }
1050
+
1051
+ function stackGet(key) {
1052
+ return this.__data__.get(key);
1053
+ }
1054
+
1055
+ function stackHas(key) {
1056
+ return this.__data__.has(key);
1057
+ }
1058
+
1059
+ var LARGE_ARRAY_SIZE = 200;
1060
+ function stackSet(key, value) {
1061
+ var data = this.__data__;
1062
+ if (data instanceof ListCache) {
1063
+ var pairs = data.__data__;
1064
+ if (!Map$1 || pairs.length < LARGE_ARRAY_SIZE - 1) {
1065
+ pairs.push([key, value]);
1066
+ this.size = ++data.size;
1067
+ return this;
1068
+ }
1069
+ data = this.__data__ = new MapCache(pairs);
1070
+ }
1071
+ data.set(key, value);
1072
+ this.size = data.size;
1073
+ return this;
1074
+ }
1075
+
1076
+ function Stack(entries) {
1077
+ var data = this.__data__ = new ListCache(entries);
1078
+ this.size = data.size;
1079
+ }
1080
+ Stack.prototype.clear = stackClear;
1081
+ Stack.prototype['delete'] = stackDelete;
1082
+ Stack.prototype.get = stackGet;
1083
+ Stack.prototype.has = stackHas;
1084
+ Stack.prototype.set = stackSet;
1085
+
1086
+ var freeExports = typeof exports == 'object' && exports && !exports.nodeType && exports;
1087
+ var freeModule = freeExports && typeof module == 'object' && module && !module.nodeType && module;
1088
+ var moduleExports = freeModule && freeModule.exports === freeExports;
1089
+ var Buffer = moduleExports ? root.Buffer : undefined;
1090
+ Buffer ? Buffer.allocUnsafe : undefined;
1091
+ function cloneBuffer(buffer, isDeep) {
1092
+ {
1093
+ return buffer.slice();
1094
+ }
1095
+ }
1096
+
617
1097
  var DataView = getNative(root, 'DataView');
618
1098
 
619
1099
  var Promise$1 = getNative(root, 'Promise');
@@ -655,6 +1135,23 @@ if (DataView && getTag(new DataView(new ArrayBuffer(1))) != dataViewTag || Map$1
655
1135
  };
656
1136
  }
657
1137
 
1138
+ var Uint8Array = root.Uint8Array;
1139
+
1140
+ function cloneArrayBuffer(arrayBuffer) {
1141
+ var result = new arrayBuffer.constructor(arrayBuffer.byteLength);
1142
+ new Uint8Array(result).set(new Uint8Array(arrayBuffer));
1143
+ return result;
1144
+ }
1145
+
1146
+ function cloneTypedArray(typedArray, isDeep) {
1147
+ var buffer = cloneArrayBuffer(typedArray.buffer) ;
1148
+ return new typedArray.constructor(buffer, typedArray.byteOffset, typedArray.length);
1149
+ }
1150
+
1151
+ function initCloneObject(object) {
1152
+ return typeof object.constructor == 'function' && !isPrototype(object) ? baseCreate(getPrototype(object)) : {};
1153
+ }
1154
+
658
1155
  function createBaseFor(fromRight) {
659
1156
  return function (object, iteratee, keysFunc) {
660
1157
  var index = -1,
@@ -721,7 +1218,7 @@ function debounce(func, wait, options) {
721
1218
  throw new TypeError(FUNC_ERROR_TEXT);
722
1219
  }
723
1220
  wait = toNumber(wait) || 0;
724
- if (isObject(options)) {
1221
+ if (isObject$1(options)) {
725
1222
  leading = !!options.leading;
726
1223
  maxing = 'maxWait' in options;
727
1224
  maxWait = maxing ? nativeMax(toNumber(options.maxWait) || 0, wait) : maxWait;
@@ -802,6 +1299,96 @@ function debounce(func, wait, options) {
802
1299
  return debounced;
803
1300
  }
804
1301
 
1302
+ function assignMergeValue(object, key, value) {
1303
+ if (value !== undefined && !eq(object[key], value) || value === undefined && !(key in object)) {
1304
+ baseAssignValue(object, key, value);
1305
+ }
1306
+ }
1307
+
1308
+ function isArrayLikeObject(value) {
1309
+ return isObjectLike(value) && isArrayLike(value);
1310
+ }
1311
+
1312
+ function safeGet(object, key) {
1313
+ if (key === 'constructor' && typeof object[key] === 'function') {
1314
+ return;
1315
+ }
1316
+ if (key == '__proto__') {
1317
+ return;
1318
+ }
1319
+ return object[key];
1320
+ }
1321
+
1322
+ function toPlainObject(value) {
1323
+ return copyObject(value, keysIn(value));
1324
+ }
1325
+
1326
+ function baseMergeDeep(object, source, key, srcIndex, mergeFunc, customizer, stack) {
1327
+ var objValue = safeGet(object, key),
1328
+ srcValue = safeGet(source, key),
1329
+ stacked = stack.get(srcValue);
1330
+ if (stacked) {
1331
+ assignMergeValue(object, key, stacked);
1332
+ return;
1333
+ }
1334
+ var newValue = customizer ? customizer(objValue, srcValue, key + '', object, source, stack) : undefined;
1335
+ var isCommon = newValue === undefined;
1336
+ if (isCommon) {
1337
+ var isArr = isArray(srcValue),
1338
+ isBuff = !isArr && isBuffer(srcValue),
1339
+ isTyped = !isArr && !isBuff && isTypedArray(srcValue);
1340
+ newValue = srcValue;
1341
+ if (isArr || isBuff || isTyped) {
1342
+ if (isArray(objValue)) {
1343
+ newValue = objValue;
1344
+ } else if (isArrayLikeObject(objValue)) {
1345
+ newValue = copyArray(objValue);
1346
+ } else if (isBuff) {
1347
+ isCommon = false;
1348
+ newValue = cloneBuffer(srcValue);
1349
+ } else if (isTyped) {
1350
+ isCommon = false;
1351
+ newValue = cloneTypedArray(srcValue);
1352
+ } else {
1353
+ newValue = [];
1354
+ }
1355
+ } else if (isPlainObject(srcValue) || isArguments(srcValue)) {
1356
+ newValue = objValue;
1357
+ if (isArguments(objValue)) {
1358
+ newValue = toPlainObject(objValue);
1359
+ } else if (!isObject$1(objValue) || isFunction(objValue)) {
1360
+ newValue = initCloneObject(srcValue);
1361
+ }
1362
+ } else {
1363
+ isCommon = false;
1364
+ }
1365
+ }
1366
+ if (isCommon) {
1367
+ stack.set(srcValue, newValue);
1368
+ mergeFunc(newValue, srcValue, srcIndex, customizer, stack);
1369
+ stack['delete'](srcValue);
1370
+ }
1371
+ assignMergeValue(object, key, newValue);
1372
+ }
1373
+
1374
+ function baseMerge(object, source, srcIndex, customizer, stack) {
1375
+ if (object === source) {
1376
+ return;
1377
+ }
1378
+ baseFor(source, function (srcValue, key) {
1379
+ stack || (stack = new Stack());
1380
+ if (isObject$1(srcValue)) {
1381
+ baseMergeDeep(object, source, key, srcIndex, baseMerge, customizer, stack);
1382
+ } else {
1383
+ var newValue = customizer ? customizer(safeGet(object, key), srcValue, key + '', object, source, stack) : undefined;
1384
+ if (newValue === undefined) {
1385
+ newValue = srcValue;
1386
+ }
1387
+ assignMergeValue(object, key, newValue);
1388
+ }
1389
+ }, keysIn);
1390
+ }
1391
+
805
1392
  function castFunction(value) {
806
1393
  return typeof value == 'function' ? value : identity;
807
1394
  }
@@ -837,6 +1424,367 @@ function isEmpty(value) {
837
1424
  return true;
838
1425
  }
839
1426
 
1427
+ var merge = createAssigner(function (object, source, srcIndex) {
1428
+ baseMerge(object, source, srcIndex);
1429
+ });
1430
+
1431
+ let RuntimeDataSourceStatus = /*#__PURE__*/function (RuntimeDataSourceStatus) {
1432
+ RuntimeDataSourceStatus["Initial"] = "init";
1433
+ RuntimeDataSourceStatus["Loading"] = "loading";
1434
+ RuntimeDataSourceStatus["Loaded"] = "loaded";
1435
+ RuntimeDataSourceStatus["Error"] = "error";
1436
+ return RuntimeDataSourceStatus;
1437
+ }({});
1438
+
1439
+ class RuntimeDataSourceItem {
1440
+ _data;
1441
+ _error;
1442
+ _status = RuntimeDataSourceStatus.Initial;
1443
+ _dataSourceConfig;
1444
+ _request;
1445
+ _context;
1446
+ _options;
1447
+ constructor(dataSourceConfig, request, context) {
1448
+ this._dataSourceConfig = dataSourceConfig;
1449
+ this._request = request;
1450
+ this._context = context;
1451
+ }
1452
+ get data() {
1453
+ return this._data;
1454
+ }
1455
+ get error() {
1456
+ return this._error;
1457
+ }
1458
+ get status() {
1459
+ return this._status;
1460
+ }
1461
+ get isLoading() {
1462
+ return this._status === RuntimeDataSourceStatus.Loading;
1463
+ }
1464
+ async load(params) {
1465
+ if (!this._dataSourceConfig) return;
1466
+ if (!this._request) {
1467
+ this._error = new Error(`no ${this._dataSourceConfig.type} handler provide`);
1468
+ this._status = RuntimeDataSourceStatus.Error;
1469
+ throw this._error;
1470
+ }
1471
+ if (this._dataSourceConfig.type === 'urlParams') {
1472
+ const response = await this._request(this._context);
1473
+ this._context.setState({
1474
+ [this._dataSourceConfig.id]: response
1475
+ });
1476
+ this._data = response;
1477
+ this._status = RuntimeDataSourceStatus.Loaded;
1478
+ return response;
1479
+ }
1480
+ if (!this._dataSourceConfig.options) {
1481
+ throw new Error(`${this._dataSourceConfig.id} has no options`);
1482
+ }
1483
+ if (typeof this._dataSourceConfig.options === 'function') {
1484
+ this._options = this._dataSourceConfig.options();
1485
+ }
1486
+ if (!this._options) {
1487
+ throw new Error(`${this._dataSourceConfig.id} options transform error`);
1488
+ }
1489
+ let shouldFetch = true;
1490
+ let fetchOptions = this._options;
1491
+ if (params) {
1492
+ fetchOptions.params = merge(fetchOptions.params, params);
1493
+ }
1494
+ if (this._dataSourceConfig.shouldFetch) {
1495
+ if (typeof this._dataSourceConfig.shouldFetch === 'function') {
1496
+ shouldFetch = this._dataSourceConfig.shouldFetch(fetchOptions);
1497
+ } else if (typeof this._dataSourceConfig.shouldFetch === 'boolean') {
1498
+ shouldFetch = this._dataSourceConfig.shouldFetch;
1499
+ }
1500
+ }
1501
+ if (!shouldFetch) {
1502
+ this._status = RuntimeDataSourceStatus.Error;
1503
+ this._error = new Error(`the ${this._dataSourceConfig.id} request should not fetch, please check the condition`);
1504
+ console.warn(this.error);
1505
+ return;
1506
+ }
1507
+ if (this._dataSourceConfig.willFetch) {
1508
+ try {
1509
+ fetchOptions = await this._dataSourceConfig.willFetch(this._options);
1510
+ } catch (error) {
1511
+ console.error(error);
1512
+ }
1513
+ }
1514
+ const dataHandler = this._dataSourceConfig.dataHandler;
1515
+ const {
1516
+ errorHandler
1517
+ } = this._dataSourceConfig;
1518
+ try {
1519
+ this._status = RuntimeDataSourceStatus.Loading;
1520
+ const result = await this._request(fetchOptions, this._context).then(dataHandler, errorHandler);
1521
+ this._data = result;
1522
+ this._status = RuntimeDataSourceStatus.Loaded;
1523
+ this._context.setState({
1524
+ UNSTABLE_dataSourceUpdatedAt: Date.now(),
1525
+ [this._dataSourceConfig.id]: result
1526
+ });
1527
+ return this._data;
1528
+ } catch (error) {
1529
+ this._error = error;
1530
+ this._status = RuntimeDataSourceStatus.Error;
1531
+ this._context.setState({
1532
+ UNSTABLE_dataSourceUpdatedAt: Date.now(),
1533
+ [`UNSTABLE_${this._dataSourceConfig.id}_error`]: error
1534
+ });
1535
+ throw error;
1536
+ }
1537
+ }
1538
+ }
1539
+
1540
+ const defaultDataHandler = async response => response.data;
1541
+ const defaultWillFetch = options => options;
1542
+ const getRequestHandler = (ds, requestHandlersMap) => {
1543
+ if (ds.type === 'custom') {
1544
+ return ds.requestHandler;
1545
+ }
1546
+ return requestHandlersMap[ds.type || 'fetch'];
1547
+ };
1548
+ const promiseSettled = (Promise.allSettled ? Promise.allSettled.bind(Promise) : null) || (promises => {
1549
+ return Promise.all(promises.map(p => {
1550
+ return p.then(v => ({
1551
+ status: 'fulfilled',
1552
+ value: v
1553
+ })).catch(e => ({
1554
+ status: 'rejected',
1555
+ reason: e
1556
+ }));
1557
+ }));
1558
+ });
1559
+
1560
+ function isObject(obj) {
1561
+ return Object.prototype.toString.call(obj).indexOf('Object') !== -1;
1562
+ }
1563
+ const transformExpression = (code, context) => {
1564
+ if (code === undefined) {
1565
+ return () => {};
1566
+ }
1567
+ if (code === '') {
1568
+ return () => '';
1569
+ }
1570
+ try {
1571
+ return new Function(`return (${code})`).call(context);
1572
+ } catch (error) {
1573
+ console.error(`transformExpression error, code is ${code}, context is ${context}, error is ${error}`);
1574
+ }
1575
+ };
1576
+ const transformFunction = (code, context) => {
1577
+ if (code === undefined) {
1578
+ return () => {};
1579
+ }
1580
+ if (code === '') {
1581
+ return () => '';
1582
+ }
1583
+ try {
1584
+ return new Function(`return (${code})`).call(context).bind(context);
1585
+ } catch (error) {
1586
+ console.error(`transformFunction error, code is ${code}, context is ${context}, error is ${error}`);
1587
+ }
1588
+ };
1589
+ const transformBoolStr = str => {
1590
+ return str !== 'false';
1591
+ };
1592
+ const getRuntimeJsValue = (value, context) => {
1593
+ if (!['JSExpression', 'JSFunction'].includes(value.type)) {
1594
+ console.error(`translate error, value is ${JSON.stringify(value)}`);
1595
+ return '';
1596
+ }
1597
+ const code = value.compiled || value.value;
1598
+ return value.type === 'JSFunction' ? transformFunction(code, context) : transformExpression(code, context);
1599
+ };
1600
+ const getRuntimeBaseValue = (type, value) => {
1601
+ switch (type) {
1602
+ case 'string':
1603
+ return `${value}`;
1604
+ case 'boolean':
1605
+ return typeof value === 'string' ? transformBoolStr(value) : !!value;
1606
+ case 'number':
1607
+ return Number(value);
1608
+ default:
1609
+ return value;
1610
+ }
1611
+ };
1612
+ const getRuntimeValueFromConfig = (type, value, context) => {
1613
+ if (value === undefined) {
1614
+ return undefined;
1615
+ }
1616
+ if (isJSExpression(value) || isJSFunction(value)) {
1617
+ return getRuntimeBaseValue(type, getRuntimeJsValue(value, context));
1618
+ }
1619
+ return value;
1620
+ };
1621
+ const buildJsonObj = (params, context) => {
1622
+ if (isJSExpression(params)) {
1623
+ return transformExpression(params.value, context);
1624
+ } else if (isObject(params)) {
1625
+ const newParams = {};
1626
+ for (const [name, param] of Object.entries(params)) {
1627
+ if (isJSExpression(param)) {
1628
+ newParams[name] = transformExpression(param?.value, context);
1629
+ } else if (isObject(param)) {
1630
+ newParams[name] = buildJsonObj(param, context);
1631
+ } else {
1632
+ newParams[name] = param;
1633
+ }
1634
+ }
1635
+ return newParams;
1636
+ }
1637
+ return params;
1638
+ };
1639
+ const buildShouldFetch = (ds, context) => {
1640
+ if (!ds.options || !ds.shouldFetch) {
1641
+ return true;
1642
+ }
1643
+ if (isJSExpression(ds.shouldFetch) || isJSFunction(ds.shouldFetch)) {
1644
+ return getRuntimeJsValue(ds.shouldFetch, context);
1645
+ }
1646
+ return getRuntimeBaseValue('boolean', ds.shouldFetch);
1647
+ };
1648
+ const buildOptions = (ds, context) => {
1649
+ const {
1650
+ options
1651
+ } = ds;
1652
+ if (!options) return undefined;
1653
+ return () => {
1654
+ const fetchOptions = {
1655
+ uri: '',
1656
+ params: {},
1657
+ method: 'GET',
1658
+ isCors: true,
1659
+ timeout: 5000,
1660
+ headers: undefined,
1661
+ v: '1.0'
1662
+ };
1663
+ Object.keys(options).forEach(key => {
1664
+ switch (key) {
1665
+ case 'uri':
1666
+ fetchOptions.uri = getRuntimeValueFromConfig('string', options.uri, context);
1667
+ break;
1668
+ case 'params':
1669
+ fetchOptions.params = buildJsonObj(options.params, context);
1670
+ break;
1671
+ case 'method':
1672
+ fetchOptions.method = getRuntimeValueFromConfig('string', options.method, context);
1673
+ break;
1674
+ case 'isCors':
1675
+ fetchOptions.isCors = getRuntimeValueFromConfig('boolean', options.isCors, context);
1676
+ break;
1677
+ case 'timeout':
1678
+ fetchOptions.timeout = getRuntimeValueFromConfig('number', options.timeout, context);
1679
+ break;
1680
+ case 'headers':
1681
+ fetchOptions.headers = buildJsonObj(options.headers, context);
1682
+ break;
1683
+ case 'v':
1684
+ fetchOptions.v = getRuntimeValueFromConfig('string', options.v, context);
1685
+ break;
1686
+ default:
1687
+ fetchOptions[key] = getRuntimeValueFromConfig('unknown', options[key], context);
1688
+ }
1689
+ });
1690
+ return fetchOptions;
1691
+ };
1692
+ };
1693
+
1694
+ const adapt2Runtime = (dataSource, context, extraConfig) => {
1695
+ const {
1696
+ list: interpretConfigList,
1697
+ dataHandler: interpretDataHandler
1698
+ } = dataSource;
1699
+ const dataHandler = interpretDataHandler ? getRuntimeJsValue(interpretDataHandler, context) : undefined;
1700
+ if (!interpretConfigList || !interpretConfigList.length) {
1701
+ return {
1702
+ list: [],
1703
+ dataHandler
1704
+ };
1705
+ }
1706
+ const list = interpretConfigList.map(el => {
1707
+ const {
1708
+ defaultDataHandler: customDataHandler
1709
+ } = extraConfig;
1710
+ const finalDataHandler = customDataHandler || defaultDataHandler;
1711
+ return {
1712
+ id: el.id,
1713
+ isInit: getRuntimeValueFromConfig('boolean', el.isInit, context),
1714
+ isSync: getRuntimeValueFromConfig('boolean', el.isSync, context),
1715
+ type: el.type || 'fetch',
1716
+ willFetch: el.willFetch ? getRuntimeJsValue(el.willFetch, context) : defaultWillFetch,
1717
+ shouldFetch: buildShouldFetch(el, context),
1718
+ dataHandler: el.dataHandler ? getRuntimeJsValue(el.dataHandler, context) : finalDataHandler,
1719
+ errorHandler: el.errorHandler ? getRuntimeJsValue(el.errorHandler, context) : undefined,
1720
+ requestHandler: el.requestHandler ? getRuntimeJsValue(el.requestHandler, context) : undefined,
1721
+ options: buildOptions(el, context)
1722
+ };
1723
+ });
1724
+ return {
1725
+ list,
1726
+ dataHandler
1727
+ };
1728
+ };
1729
+
1730
+ const reloadDataSourceFactory = (dataSource, dataSourceMap, dataHandler) => {
1731
+ return async () => {
1732
+ const allAsyncLoadings = [];
1733
+ dataSource.list.filter(el => el.type === 'urlParams' && isInit(el)).forEach(el => {
1734
+ dataSourceMap[el.id].load();
1735
+ });
1736
+ const remainRuntimeDataSourceList = dataSource.list.filter(el => el.type !== 'urlParams');
1737
+ for (const ds of remainRuntimeDataSourceList) {
1738
+ if (!ds.options) {
1739
+ continue;
1740
+ }
1741
+ if (
1742
+ isInit(ds) && !ds.isSync) {
1743
+ allAsyncLoadings.push(dataSourceMap[ds.id].load());
1744
+ }
1745
+ }
1746
+ for (const ds of remainRuntimeDataSourceList) {
1747
+ if (!ds.options) {
1748
+ continue;
1749
+ }
1750
+ if (
1751
+ isInit(ds) && ds.isSync) {
1752
+ try {
1753
+ await dataSourceMap[ds.id].load();
1754
+ } catch (e) {
1755
+ console.error(e);
1756
+ }
1757
+ }
1758
+ }
1759
+ await promiseSettled(allAsyncLoadings);
1760
+ if (dataHandler) {
1761
+ dataHandler(dataSourceMap);
1762
+ }
1763
+ };
1764
+ };
1765
+ function isInit(ds) {
1766
+ return typeof ds.isInit === 'function' ? ds.isInit() : ds.isInit ?? true;
1767
+ }
1768
+
1769
+ var createDataSourceEngine = (dataSource, context, extraConfig = {
1770
+ requestHandlersMap: {}
1771
+ }) => {
1772
+ const {
1773
+ requestHandlersMap
1774
+ } = extraConfig;
1775
+ const runtimeDataSource = adapt2Runtime(dataSource, context, {
1776
+ defaultDataHandler: extraConfig.defaultDataHandler
1777
+ });
1778
+ const dataSourceMap = runtimeDataSource.list.reduce((prev, current) => {
1779
+ prev[current.id] = new RuntimeDataSourceItem(current, getRequestHandler(current, requestHandlersMap), context);
1780
+ return prev;
1781
+ }, {});
1782
+ return {
1783
+ dataSourceMap,
1784
+ reloadDataSource: reloadDataSourceFactory(runtimeDataSource, dataSourceMap, runtimeDataSource.dataHandler)
1785
+ };
1786
+ };
1787
+
840
1788
  const RendererContext = /*#__PURE__*/createContext({});
841
1789
  const useRendererContext = () => {
842
1790
  try {
@@ -1043,6 +1991,20 @@ const isReactClass = obj => {
1043
1991
  function isReactComponent(obj) {
1044
1992
  return obj && (isReactClass(obj) || typeof obj === 'function');
1045
1993
  }
1994
+ function serializeParams(obj) {
1995
+ const result = [];
1996
+ forEach(obj, (val, key) => {
1997
+ if (val === null || val === undefined || val === '') {
1998
+ return;
1999
+ }
2000
+ if (typeof val === 'object') {
2001
+ result.push(`${key}=${encodeURIComponent(JSON.stringify(val))}`);
2002
+ } else {
2003
+ result.push(`${key}=${encodeURIComponent(val)}`);
2004
+ }
2005
+ });
2006
+ return result.join('&');
2007
+ }
1046
2008
 
1047
2009
  const excludePropertyNames = ['$$typeof', 'render', 'defaultProps', 'props', 'length', 'prototype', 'name', 'caller', 'callee', 'arguments'];
1048
2010
  const cloneEnumerableProperty = (target, origin, excludes = excludePropertyNames) => {
@@ -1607,6 +2569,338 @@ const leafWrapper = (Comp, {
1607
2569
  return LeafWrapper;
1608
2570
  };
1609
2571
 
2572
+ function buildUrl(dataAPI, params) {
2573
+ const paramStr = serializeParams(params);
2574
+ if (paramStr) {
2575
+ return dataAPI.indexOf('?') > 0 ? `${dataAPI}&${paramStr}` : `${dataAPI}?${paramStr}`;
2576
+ }
2577
+ return dataAPI;
2578
+ }
2579
+ function get(dataAPI, params = {}, headers = {}, otherProps = {}) {
2580
+ const processedHeaders = {
2581
+ Accept: 'application/json',
2582
+ ...headers
2583
+ };
2584
+ const url = buildUrl(dataAPI, params);
2585
+ return request(url, 'GET', null, processedHeaders, otherProps);
2586
+ }
2587
+ function post(dataAPI, params = {}, headers = {}, otherProps = {}) {
2588
+ const processedHeaders = {
2589
+ Accept: 'application/json',
2590
+ 'Content-Type': 'application/x-www-form-urlencoded',
2591
+ ...headers
2592
+ };
2593
+ const body = processedHeaders['Content-Type'].indexOf('application/json') > -1 || Array.isArray(params) ? JSON.stringify(params) : serializeParams(params);
2594
+ return request(dataAPI, 'POST', body, processedHeaders, otherProps);
2595
+ }
2596
+ function request(dataAPI, method = 'GET', data, headers = {}, otherProps = {}) {
2597
+ let processedHeaders = headers || {};
2598
+ let payload = data;
2599
+ if (method === 'PUT' || method === 'DELETE') {
2600
+ processedHeaders = {
2601
+ Accept: 'application/json',
2602
+ 'Content-Type': 'application/json',
2603
+ ...processedHeaders
2604
+ };
2605
+ payload = JSON.stringify(payload || {});
2606
+ }
2607
+ return new Promise((resolve, reject) => {
2608
+ if (otherProps.timeout) {
2609
+ setTimeout(() => {
2610
+ reject(new Error('timeout'));
2611
+ }, otherProps.timeout);
2612
+ }
2613
+ fetch(dataAPI, {
2614
+ method,
2615
+ credentials: 'include',
2616
+ headers: processedHeaders,
2617
+ body: payload,
2618
+ ...otherProps
2619
+ }).then(response => {
2620
+ switch (response.status) {
2621
+ case 200:
2622
+ case 201:
2623
+ case 202:
2624
+ return response.json();
2625
+ case 204:
2626
+ if (method === 'DELETE') {
2627
+ return {
2628
+ success: true
2629
+ };
2630
+ } else {
2631
+ return {
2632
+ __success: false,
2633
+ code: response.status
2634
+ };
2635
+ }
2636
+ case 400:
2637
+ case 401:
2638
+ case 403:
2639
+ case 404:
2640
+ case 406:
2641
+ case 410:
2642
+ case 422:
2643
+ case 500:
2644
+ return response.json().then(res => {
2645
+ return {
2646
+ __success: false,
2647
+ code: response.status,
2648
+ data: res
2649
+ };
2650
+ }).catch(() => {
2651
+ return {
2652
+ __success: false,
2653
+ code: response.status
2654
+ };
2655
+ });
2656
+ }
2657
+ return null;
2658
+ }).then(json => {
2659
+ if (!json) {
2660
+ reject(json);
2661
+ return;
2662
+ }
2663
+ if (json.__success !== false) {
2664
+ resolve(json);
2665
+ } else {
2666
+ delete json.__success;
2667
+ reject(json);
2668
+ }
2669
+ }).catch(err => {
2670
+ reject(err);
2671
+ });
2672
+ });
2673
+ }
2674
+
2675
+ const DS_STATUS = {
2676
+ INIT: 'init',
2677
+ LOADING: 'loading',
2678
+ LOADED: 'loaded',
2679
+ ERROR: 'error'
2680
+ };
2681
+ function doRequest(type, options) {
2682
+ let {
2683
+ uri,
2684
+ url,
2685
+ method = 'GET',
2686
+ headers,
2687
+ params,
2688
+ ...otherProps
2689
+ } = options;
2690
+ otherProps = otherProps || {};
2691
+ if (type === 'fetch') {
2692
+ switch (method.toUpperCase()) {
2693
+ case 'GET':
2694
+ return get(uri, params, headers, otherProps);
2695
+ case 'POST':
2696
+ return post(uri, params, headers, otherProps);
2697
+ default:
2698
+ return request(uri, method, params, headers, otherProps);
2699
+ }
2700
+ }
2701
+ logger.log(`Engine default dataSource does not support type:[${type}] dataSource request!`, options);
2702
+ }
2703
+ class DataHelper {
2704
+ host;
2705
+ config;
2706
+ parser;
2707
+ ajaxList;
2708
+ dataHandler;
2709
+ ajaxMap;
2710
+ dataSourceMap;
2711
+ appHelper;
2712
+ constructor(comp, config, appHelper, parser) {
2713
+ this.host = comp;
2714
+ this.config = config || {};
2715
+ this.parser = parser;
2716
+ this.ajaxList = config?.list || [];
2717
+ this.ajaxMap = transformArrayToMap(this.ajaxList, 'id');
2718
+ this.dataSourceMap = this.generateDataSourceMap();
2719
+ this.appHelper = appHelper;
2720
+ this.dataHandler = config?.dataHandler ? parseExpression(config?.dataHandler, comp, true) : undefined;
2721
+ }
2722
+ updateConfig(config = {}) {
2723
+ this.config = config;
2724
+ this.ajaxList = config?.list || [];
2725
+ const ajaxMap = transformArrayToMap(this.ajaxList, 'id');
2726
+ Object.keys(this.ajaxMap).forEach(key => {
2727
+ if (!ajaxMap[key]) {
2728
+ delete this.dataSourceMap[key];
2729
+ }
2730
+ });
2731
+ this.ajaxMap = ajaxMap;
2732
+ this.ajaxList.forEach(item => {
2733
+ if (!this.dataSourceMap[item.id]) {
2734
+ this.dataSourceMap[item.id] = {
2735
+ status: DS_STATUS.INIT,
2736
+ load: (...args) => {
2737
+ return this.getDataSource(item.id, ...args);
2738
+ }
2739
+ };
2740
+ }
2741
+ });
2742
+ return this.dataSourceMap;
2743
+ }
2744
+ generateDataSourceMap() {
2745
+ const res = {};
2746
+ this.ajaxList.forEach(item => {
2747
+ res[item.id] = {
2748
+ status: DS_STATUS.INIT,
2749
+ load: (...args) => {
2750
+ return this.getDataSource(item.id, ...args);
2751
+ }
2752
+ };
2753
+ });
2754
+ return res;
2755
+ }
2756
+ updateDataSourceMap(id, data, error) {
2757
+ this.dataSourceMap[id].error = error || undefined;
2758
+ this.dataSourceMap[id].data = data;
2759
+ this.dataSourceMap[id].status = error ? DS_STATUS.ERROR : DS_STATUS.LOADED;
2760
+ }
2761
+ getInitDataSourseConfigs() {
2762
+ const initConfigs = this.parser(this.ajaxList).filter(item => {
2763
+ if (item.isInit === true) {
2764
+ this.dataSourceMap[item.id].status = DS_STATUS.LOADING;
2765
+ return true;
2766
+ }
2767
+ return false;
2768
+ });
2769
+ return initConfigs;
2770
+ }
2771
+ getInitData() {
2772
+ const initSyncData = this.getInitDataSourseConfigs();
2773
+ return this.asyncDataHandler(initSyncData).then(res => {
2774
+ const {
2775
+ dataHandler
2776
+ } = this.config;
2777
+ return this.handleData(null, dataHandler, res, null);
2778
+ });
2779
+ }
2780
+ async reloadDataSource() {
2781
+ const dataSourceMap = await this.getInitData();
2782
+ if (isEmpty(dataSourceMap)) {
2783
+ return;
2784
+ }
2785
+ this.host.setState(dataSourceMap);
2786
+ if (this.dataHandler) {
2787
+ this.dataHandler(dataSourceMap);
2788
+ }
2789
+ }
2790
+ getDataSource(id, params, otherOptions, callback) {
2791
+ const req = this.parser(this.ajaxMap[id]);
2792
+ const options = req.options || {};
2793
+ let callbackFn = callback;
2794
+ let otherOptionsObj = otherOptions;
2795
+ if (typeof otherOptions === 'function') {
2796
+ callbackFn = otherOptions;
2797
+ otherOptionsObj = {};
2798
+ }
2799
+ const {
2800
+ headers,
2801
+ ...otherProps
2802
+ } = otherOptionsObj || {};
2803
+ if (!req) {
2804
+ logger.warn(`getDataSource API named ${id} not exist`);
2805
+ return;
2806
+ }
2807
+ return this.asyncDataHandler([{
2808
+ ...req,
2809
+ options: {
2810
+ ...options,
2811
+ params: Array.isArray(options.params) || Array.isArray(params) ? params || options.params : {
2812
+ ...options.params,
2813
+ ...params
2814
+ },
2815
+ headers: {
2816
+ ...options.headers,
2817
+ ...headers
2818
+ },
2819
+ ...otherProps
2820
+ }
2821
+ }]).then(res => {
2822
+ try {
2823
+ callbackFn && callbackFn(res && res[id]);
2824
+ } catch (e) {
2825
+ logger.error('load请求回调函数报错', e);
2826
+ }
2827
+ return res && res[id];
2828
+ }).catch(err => {
2829
+ try {
2830
+ callbackFn && callbackFn(null, err);
2831
+ } catch (e) {
2832
+ logger.error('load请求回调函数报错', e);
2833
+ }
2834
+ return err;
2835
+ });
2836
+ }
2837
+ asyncDataHandler(asyncDataList) {
2838
+ return new Promise((resolve, reject) => {
2839
+ const allReq = [];
2840
+ asyncDataList.forEach(req => {
2841
+ const {
2842
+ id,
2843
+ type
2844
+ } = req;
2845
+ if (!id || !type || type === 'legao') {
2846
+ return;
2847
+ }
2848
+ allReq.push(req);
2849
+ });
2850
+ if (allReq.length === 0) {
2851
+ resolve({});
2852
+ }
2853
+ const res = {};
2854
+ Promise.all(allReq.map(item => {
2855
+ return new Promise(innerResolve => {
2856
+ const {
2857
+ type,
2858
+ id,
2859
+ dataHandler,
2860
+ options
2861
+ } = item;
2862
+ const fetchHandler = (data, error) => {
2863
+ res[id] = this.handleData(id, dataHandler, data, error);
2864
+ this.updateDataSourceMap(id, res[id], error);
2865
+ innerResolve({});
2866
+ };
2867
+ const doFetch = (innerType, innerOptions) => {
2868
+ doRequest(innerType, innerOptions)?.then(data => {
2869
+ fetchHandler(data, undefined);
2870
+ }).catch(err => {
2871
+ fetchHandler(undefined, err);
2872
+ });
2873
+ };
2874
+ this.dataSourceMap[id].status = DS_STATUS.LOADING;
2875
+ doFetch(type, options);
2876
+ });
2877
+ })).then(() => {
2878
+ resolve(res);
2879
+ }).catch(e => {
2880
+ reject(e);
2881
+ });
2882
+ });
2883
+ }
2884
+ handleData(id, dataHandler, data, error) {
2885
+ let dataHandlerFun = dataHandler;
2886
+ if (isJSFunction(dataHandler)) {
2887
+ dataHandlerFun = transformStringToFunction(dataHandler.value);
2888
+ }
2889
+ if (!dataHandlerFun || typeof dataHandlerFun !== 'function') {
2890
+ return data;
2891
+ }
2892
+ try {
2893
+ return dataHandlerFun.call(this.host, data, error);
2894
+ } catch (e) {
2895
+ if (id) {
2896
+ logger.error(`[${id}]单个请求数据处理函数运行出错`, e);
2897
+ } else {
2898
+ logger.error('请求数据处理函数运行出错', e);
2899
+ }
2900
+ }
2901
+ }
2902
+ }
2903
+
1610
2904
  function executeLifeCycleMethod(context, schema, method, args) {
1611
2905
  if (!context || !isSchema(schema) || !method) {
1612
2906
  return;
@@ -1832,60 +3126,44 @@ function baseRendererFactory() {
1832
3126
  if (!props) {
1833
3127
  return;
1834
3128
  }
1835
- // TODO: 数据源引擎方案
1836
- // const schema = props.__schema || {}
1837
- // const defaultDataSource: DataSource = {
1838
- // list: [],
1839
- // }
1840
- // const dataSource = schema.dataSource || defaultDataSource
1841
- // // requestHandlersMap 存在才走数据源引擎方案
1842
- // // TODO: 下面if else 抽成独立函数
1843
- // const useDataSourceEngine = !!props.__appHelper?.requestHandlersMap
1844
- // if (useDataSourceEngine) {
1845
- // this.__dataHelper = {
1846
- // updateConfig: (updateDataSource: any) => {
1847
- // const { dataSourceMap, reloadDataSource } = createDataSourceEngine(
1848
- // updateDataSource ?? {},
1849
- // this,
1850
- // props.__appHelper.requestHandlersMap
1851
- // ? { requestHandlersMap: props.__appHelper.requestHandlersMap }
1852
- // : undefined,
1853
- // )
1854
-
1855
- // this.reloadDataSource = () =>
1856
- // new Promise(resolve => {
1857
- // logger.log('reload data source')
1858
- // reloadDataSource().then(() => {
1859
- // resolve({})
1860
- // })
1861
- // })
1862
- // return dataSourceMap
1863
- // },
1864
- // }
1865
- // this.dataSourceMap = this.__dataHelper.updateConfig(dataSource)
1866
- // } else {
1867
- // const appHelper = props.__appHelper
1868
- // this.__dataHelper = new DataHelper(this, dataSource, appHelper, (config: any) => this.__parseData(config))
1869
- // this.dataSourceMap = this.__dataHelper.dataSourceMap
1870
- // this.reloadDataSource = () =>
1871
- // new Promise((resolve, reject) => {
1872
- // logger.log('reload data source')
1873
- // if (!this.__dataHelper) {
1874
- // return resolve({})
1875
- // }
1876
- // this.__dataHelper
1877
- // .getInitData()
1878
- // .then((res: any) => {
1879
- // if (isEmpty(res)) {
1880
- // return resolve({})
1881
- // }
1882
- // this.setState(res, resolve as () => void)
1883
- // })
1884
- // .catch((err: Error) => {
1885
- // reject(err)
1886
- // })
1887
- // })
1888
- // }
3129
+ const schema = props.__schema || {};
3130
+ const defaultDataSource = {
3131
+ list: []
3132
+ };
3133
+ const dataSource = schema.dataSource || defaultDataSource;
3134
+ // requestHandlersMap 存在才走数据源引擎方案
3135
+ // TODO: 下面if else 抽成独立函数
3136
+ const useDataSourceEngine = !!props.__appHelper?.requestHandlersMap;
3137
+ if (useDataSourceEngine) {
3138
+ this.__dataHelper = {
3139
+ updateConfig: updateDataSource => {
3140
+ const {
3141
+ dataSourceMap,
3142
+ reloadDataSource
3143
+ } = createDataSourceEngine(updateDataSource ?? {}, this, props.__appHelper?.requestHandlersMap ? {
3144
+ requestHandlersMap: props.__appHelper.requestHandlersMap
3145
+ } : undefined);
3146
+ this.reloadDataSource = () => new Promise(resolve => {
3147
+ logger.log('reload data source');
3148
+ reloadDataSource().then(() => {
3149
+ resolve({});
3150
+ });
3151
+ });
3152
+ return dataSourceMap;
3153
+ }
3154
+ };
3155
+ this.dataSourceMap = this.__dataHelper.updateConfig(dataSource);
3156
+ } else {
3157
+ const appHelper = props.__appHelper || {};
3158
+ this.__dataHelper = new DataHelper(this, dataSource, appHelper, config => this.__parseData(config));
3159
+ this.dataSourceMap = this.__dataHelper.dataSourceMap;
3160
+ this.reloadDataSource = () => new Promise(resolve => {
3161
+ logger.log('reload data source');
3162
+ this.__dataHelper.reloadDataSource().then(() => {
3163
+ resolve({});
3164
+ });
3165
+ });
3166
+ }
1889
3167
  };
1890
3168
 
1891
3169
  /**
@@ -2695,5 +3973,5 @@ function rendererFactory() {
2695
3973
 
2696
3974
  const DEV = '_EASY_EDITOR_DEV_';
2697
3975
 
2698
- export { DEV, RendererContext, SettingFieldView, SettingRender, adapter, baseRendererFactory, capitalizeFirstLetter, checkPropTypes, classnames, cloneEnumerableProperty, compWrapper, componentRendererFactory, contextFactory, createForwardRefHocElement, executeLifeCycleMethod, getFileCssName, getSchemaChildren, getValue, inSameDomain, isReactClass, isReactComponent, isSchema, isString, isUseLoop, leafWrapper, logger, pageRendererFactory, parseData, parseExpression, parseThisRequiredExpression, rendererFactory, transformArrayToMap, transformStringToFunction, useRendererContext };
3976
+ export { DEV, RendererContext, SettingFieldView, SettingRender, adapter, baseRendererFactory, capitalizeFirstLetter, checkPropTypes, classnames, cloneEnumerableProperty, compWrapper, componentRendererFactory, contextFactory, createForwardRefHocElement, executeLifeCycleMethod, getFileCssName, getSchemaChildren, getValue, inSameDomain, isReactClass, isReactComponent, isSchema, isString, isUseLoop, leafWrapper, logger, pageRendererFactory, parseData, parseExpression, parseThisRequiredExpression, rendererFactory, serializeParams, transformArrayToMap, transformStringToFunction, useRendererContext };
2699
3977
  //# sourceMappingURL=index.js.map