@kne/react-form-antd 2.0.17-alpha.0.0 → 2.0.17

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.
@@ -13,6 +13,7 @@ import AvatarEditor from 'react-avatar-editor';
13
13
  import moment from 'moment';
14
14
  import useControlValue from '@kne/use-control-value';
15
15
  import { withFetch } from '@kne/react-fetch';
16
+ import useEvent from '@kne/use-event';
16
17
  import groupBy from 'lodash/groupBy';
17
18
  import uniqueId from 'lodash/uniqueId';
18
19
 
@@ -638,539 +639,7 @@ const _Select = props => {
638
639
  _Select.Option = Select$1.Option;
639
640
  _Select.OptGroup = Select$1.OptGroup;
640
641
 
641
- /**
642
- * Copyright (c) 2014-present, Facebook, Inc.
643
- * All rights reserved.
644
- *
645
- * This source code is licensed under the BSD-style license found in the
646
- * LICENSE file in the root directory of this source tree. An additional grant
647
- * of patent rights can be found in the PATENTS file in the same directory.
648
- *
649
- * @providesModule EventSubscription
650
- * @typechecks
651
- */
652
- /**
653
- * EventSubscription represents a subscription to a particular event. It can
654
- * remove its own subscription.
655
- */
656
-
657
- var EventSubscription = /*#__PURE__*/function () {
658
- /**
659
- * @param {EventSubscriptionVendor} subscriber the subscriber that controls
660
- * this subscription.
661
- */
662
- function EventSubscription(subscriber) {
663
- this.subscriber = subscriber;
664
- }
665
- /**
666
- * Removes this subscription from the subscriber that controls it.
667
- */
668
-
669
-
670
- var _proto = EventSubscription.prototype;
671
-
672
- _proto.remove = function remove() {
673
- if (this.subscriber) {
674
- this.subscriber.removeSubscription(this);
675
- this.subscriber = null;
676
- }
677
- };
678
-
679
- return EventSubscription;
680
- }();
681
-
682
- var EventSubscription_1 = EventSubscription;
683
-
684
- /**
685
- * Copyright (c) 2014-present, Facebook, Inc.
686
- * All rights reserved.
687
- *
688
- * This source code is licensed under the BSD-style license found in the
689
- * LICENSE file in the root directory of this source tree. An additional grant
690
- * of patent rights can be found in the PATENTS file in the same directory.
691
- *
692
- * @providesModule EmitterSubscription
693
- * @typechecks
694
- */
695
-
696
- function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
697
-
698
-
699
- /**
700
- * EmitterSubscription represents a subscription with listener and context data.
701
- */
702
-
703
-
704
- var EmitterSubscription = /*#__PURE__*/function (_EventSubscription) {
705
- _inheritsLoose(EmitterSubscription, _EventSubscription);
706
-
707
- /**
708
- * @param {EventSubscriptionVendor} subscriber - The subscriber that controls
709
- * this subscription
710
- * @param {function} listener - Function to invoke when the specified event is
711
- * emitted
712
- * @param {*} context - Optional context object to use when invoking the
713
- * listener
714
- */
715
- function EmitterSubscription(subscriber, listener, context) {
716
- var _this;
717
-
718
- _this = _EventSubscription.call(this, subscriber) || this;
719
- _this.listener = listener;
720
- _this.context = context;
721
- return _this;
722
- }
723
-
724
- return EmitterSubscription;
725
- }(EventSubscription_1);
726
-
727
- var EmitterSubscription_1 = EmitterSubscription;
728
-
729
- /**
730
- * Copyright (c) 2013-present, Facebook, Inc.
731
- *
732
- * This source code is licensed under the MIT license found in the
733
- * LICENSE file in the root directory of this source tree.
734
- *
735
- *
736
- */
737
-
738
- var validateFormat = process.env.NODE_ENV !== "production" ? function (format) {
739
- if (format === undefined) {
740
- throw new Error('invariant(...): Second argument must be a string.');
741
- }
742
- } : function (format) {};
743
- /**
744
- * Use invariant() to assert state which your program assumes to be true.
745
- *
746
- * Provide sprintf-style format (only %s is supported) and arguments to provide
747
- * information about what broke and what you were expecting.
748
- *
749
- * The invariant message will be stripped in production, but the invariant will
750
- * remain to ensure logic does not differ in production.
751
- */
752
-
753
- function invariant(condition, format) {
754
- for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
755
- args[_key - 2] = arguments[_key];
756
- }
757
-
758
- validateFormat(format);
759
-
760
- if (!condition) {
761
- var error;
762
-
763
- if (format === undefined) {
764
- error = new Error('Minified exception occurred; use the non-minified dev environment ' + 'for the full error message and additional helpful warnings.');
765
- } else {
766
- var argIndex = 0;
767
- error = new Error(format.replace(/%s/g, function () {
768
- return String(args[argIndex++]);
769
- }));
770
- error.name = 'Invariant Violation';
771
- }
772
-
773
- error.framesToPop = 1; // Skip invariant's own stack frame.
774
-
775
- throw error;
776
- }
777
- }
778
-
779
- var invariant_1 = invariant;
780
-
781
- /**
782
- * Copyright (c) 2014-present, Facebook, Inc.
783
- * All rights reserved.
784
- *
785
- * This source code is licensed under the BSD-style license found in the
786
- * LICENSE file in the root directory of this source tree. An additional grant
787
- * of patent rights can be found in the PATENTS file in the same directory.
788
- *
789
- * @providesModule EventSubscriptionVendor
790
- * @typechecks
791
- */
792
-
793
-
794
- /**
795
- * EventSubscriptionVendor stores a set of EventSubscriptions that are
796
- * subscribed to a particular event type.
797
- */
798
-
799
-
800
- var EventSubscriptionVendor = /*#__PURE__*/function () {
801
- function EventSubscriptionVendor() {
802
- this._subscriptionsForType = {};
803
- this._currentSubscription = null;
804
- }
805
- /**
806
- * Adds a subscription keyed by an event type.
807
- *
808
- * @param {string} eventType
809
- * @param {EventSubscription} subscription
810
- */
811
-
812
-
813
- var _proto = EventSubscriptionVendor.prototype;
814
-
815
- _proto.addSubscription = function addSubscription(eventType, subscription) {
816
- !(subscription.subscriber === this) ? process.env.NODE_ENV !== "production" ? invariant_1(false, 'The subscriber of the subscription is incorrectly set.') : invariant_1(false) : void 0;
817
-
818
- if (!this._subscriptionsForType[eventType]) {
819
- this._subscriptionsForType[eventType] = [];
820
- }
821
-
822
- var key = this._subscriptionsForType[eventType].length;
823
-
824
- this._subscriptionsForType[eventType].push(subscription);
825
-
826
- subscription.eventType = eventType;
827
- subscription.key = key;
828
- return subscription;
829
- }
830
- /**
831
- * Removes a bulk set of the subscriptions.
832
- *
833
- * @param {?string} eventType - Optional name of the event type whose
834
- * registered supscriptions to remove, if null remove all subscriptions.
835
- */
836
- ;
837
-
838
- _proto.removeAllSubscriptions = function removeAllSubscriptions(eventType) {
839
- if (eventType === undefined) {
840
- this._subscriptionsForType = {};
841
- } else {
842
- delete this._subscriptionsForType[eventType];
843
- }
844
- }
845
- /**
846
- * Removes a specific subscription. Instead of calling this function, call
847
- * `subscription.remove()` directly.
848
- *
849
- * @param {object} subscription
850
- */
851
- ;
852
-
853
- _proto.removeSubscription = function removeSubscription(subscription) {
854
- var eventType = subscription.eventType;
855
- var key = subscription.key;
856
- var subscriptionsForType = this._subscriptionsForType[eventType];
857
-
858
- if (subscriptionsForType) {
859
- delete subscriptionsForType[key];
860
- }
861
- }
862
- /**
863
- * Returns the array of subscriptions that are currently registered for the
864
- * given event type.
865
- *
866
- * Note: This array can be potentially sparse as subscriptions are deleted
867
- * from it when they are removed.
868
- *
869
- * TODO: This returns a nullable array. wat?
870
- *
871
- * @param {string} eventType
872
- * @return {?array}
873
- */
874
- ;
875
-
876
- _proto.getSubscriptionsForType = function getSubscriptionsForType(eventType) {
877
- return this._subscriptionsForType[eventType];
878
- };
879
-
880
- return EventSubscriptionVendor;
881
- }();
882
-
883
- var EventSubscriptionVendor_1 = EventSubscriptionVendor;
884
-
885
- /**
886
- * Copyright (c) 2013-present, Facebook, Inc.
887
- *
888
- * This source code is licensed under the MIT license found in the
889
- * LICENSE file in the root directory of this source tree.
890
- *
891
- *
892
- */
893
- function makeEmptyFunction(arg) {
894
- return function () {
895
- return arg;
896
- };
897
- }
898
- /**
899
- * This function accepts and discards inputs; it has no side effects. This is
900
- * primarily useful idiomatically for overridable function endpoints which
901
- * always need to be callable, since JS lacks a null-call idiom ala Cocoa.
902
- */
903
-
904
-
905
- var emptyFunction = function emptyFunction() {};
906
-
907
- emptyFunction.thatReturns = makeEmptyFunction;
908
- emptyFunction.thatReturnsFalse = makeEmptyFunction(false);
909
- emptyFunction.thatReturnsTrue = makeEmptyFunction(true);
910
- emptyFunction.thatReturnsNull = makeEmptyFunction(null);
911
-
912
- emptyFunction.thatReturnsThis = function () {
913
- return this;
914
- };
915
-
916
- emptyFunction.thatReturnsArgument = function (arg) {
917
- return arg;
918
- };
919
-
920
- var emptyFunction_1 = emptyFunction;
921
-
922
- /**
923
- * Copyright (c) 2014-present, Facebook, Inc.
924
- * All rights reserved.
925
- *
926
- * This source code is licensed under the BSD-style license found in the
927
- * LICENSE file in the root directory of this source tree. An additional grant
928
- * of patent rights can be found in the PATENTS file in the same directory.
929
- *
930
- * @providesModule BaseEventEmitter
931
- * @typechecks
932
- */
933
-
934
-
935
-
936
-
937
-
938
-
939
-
940
- /**
941
- * @class BaseEventEmitter
942
- * @description
943
- * An EventEmitter is responsible for managing a set of listeners and publishing
944
- * events to them when it is told that such events happened. In addition to the
945
- * data for the given event it also sends a event control object which allows
946
- * the listeners/handlers to prevent the default behavior of the given event.
947
- *
948
- * The emitter is designed to be generic enough to support all the different
949
- * contexts in which one might want to emit events. It is a simple multicast
950
- * mechanism on top of which extra functionality can be composed. For example, a
951
- * more advanced emitter may use an EventHolder and EventFactory.
952
- */
953
-
954
-
955
- var BaseEventEmitter = /*#__PURE__*/function () {
956
- /**
957
- * @constructor
958
- */
959
- function BaseEventEmitter() {
960
- this._subscriber = new EventSubscriptionVendor_1();
961
- this._currentSubscription = null;
962
- }
963
- /**
964
- * Adds a listener to be invoked when events of the specified type are
965
- * emitted. An optional calling context may be provided. The data arguments
966
- * emitted will be passed to the listener function.
967
- *
968
- * TODO: Annotate the listener arg's type. This is tricky because listeners
969
- * can be invoked with varargs.
970
- *
971
- * @param {string} eventType - Name of the event to listen to
972
- * @param {function} listener - Function to invoke when the specified event is
973
- * emitted
974
- * @param {*} context - Optional context object to use when invoking the
975
- * listener
976
- */
977
-
978
-
979
- var _proto = BaseEventEmitter.prototype;
980
-
981
- _proto.addListener = function addListener(eventType, listener, context) {
982
- return this._subscriber.addSubscription(eventType, new EmitterSubscription_1(this._subscriber, listener, context));
983
- }
984
- /**
985
- * Similar to addListener, except that the listener is removed after it is
986
- * invoked once.
987
- *
988
- * @param {string} eventType - Name of the event to listen to
989
- * @param {function} listener - Function to invoke only once when the
990
- * specified event is emitted
991
- * @param {*} context - Optional context object to use when invoking the
992
- * listener
993
- */
994
- ;
995
-
996
- _proto.once = function once(eventType, listener, context) {
997
- var emitter = this;
998
- return this.addListener(eventType, function () {
999
- emitter.removeCurrentListener();
1000
- listener.apply(context, arguments);
1001
- });
1002
- }
1003
- /**
1004
- * Removes all of the registered listeners, including those registered as
1005
- * listener maps.
1006
- *
1007
- * @param {?string} eventType - Optional name of the event whose registered
1008
- * listeners to remove
1009
- */
1010
- ;
1011
-
1012
- _proto.removeAllListeners = function removeAllListeners(eventType) {
1013
- this._subscriber.removeAllSubscriptions(eventType);
1014
- }
1015
- /**
1016
- * Provides an API that can be called during an eventing cycle to remove the
1017
- * last listener that was invoked. This allows a developer to provide an event
1018
- * object that can remove the listener (or listener map) during the
1019
- * invocation.
1020
- *
1021
- * If it is called when not inside of an emitting cycle it will throw.
1022
- *
1023
- * @throws {Error} When called not during an eventing cycle
1024
- *
1025
- * @example
1026
- * var subscription = emitter.addListenerMap({
1027
- * someEvent: function(data, event) {
1028
- * console.log(data);
1029
- * emitter.removeCurrentListener();
1030
- * }
1031
- * });
1032
- *
1033
- * emitter.emit('someEvent', 'abc'); // logs 'abc'
1034
- * emitter.emit('someEvent', 'def'); // does not log anything
1035
- */
1036
- ;
1037
-
1038
- _proto.removeCurrentListener = function removeCurrentListener() {
1039
- !!!this._currentSubscription ? process.env.NODE_ENV !== "production" ? invariant_1(false, 'Not in an emitting cycle; there is no current subscription') : invariant_1(false) : void 0;
1040
-
1041
- this._subscriber.removeSubscription(this._currentSubscription);
1042
- }
1043
- /**
1044
- * Returns an array of listeners that are currently registered for the given
1045
- * event.
1046
- *
1047
- * @param {string} eventType - Name of the event to query
1048
- * @return {array}
1049
- */
1050
- ;
1051
-
1052
- _proto.listeners = function listeners(eventType)
1053
- /* TODO: Array<EventSubscription> */
1054
- {
1055
- var subscriptions = this._subscriber.getSubscriptionsForType(eventType);
1056
-
1057
- return subscriptions ? subscriptions.filter(emptyFunction_1.thatReturnsTrue).map(function (subscription) {
1058
- return subscription.listener;
1059
- }) : [];
1060
- }
1061
- /**
1062
- * Emits an event of the given type with the given data. All handlers of that
1063
- * particular type will be notified.
1064
- *
1065
- * @param {string} eventType - Name of the event to emit
1066
- * @param {*} Arbitrary arguments to be passed to each registered listener
1067
- *
1068
- * @example
1069
- * emitter.addListener('someEvent', function(message) {
1070
- * console.log(message);
1071
- * });
1072
- *
1073
- * emitter.emit('someEvent', 'abc'); // logs 'abc'
1074
- */
1075
- ;
1076
-
1077
- _proto.emit = function emit(eventType) {
1078
- var subscriptions = this._subscriber.getSubscriptionsForType(eventType);
1079
-
1080
- if (subscriptions) {
1081
- var keys = Object.keys(subscriptions);
1082
-
1083
- for (var ii = 0; ii < keys.length; ii++) {
1084
- var key = keys[ii];
1085
- var subscription = subscriptions[key]; // The subscription may have been removed during this event loop.
1086
-
1087
- if (subscription) {
1088
- this._currentSubscription = subscription;
1089
-
1090
- this.__emitToSubscription.apply(this, [subscription].concat(Array.prototype.slice.call(arguments)));
1091
- }
1092
- }
1093
-
1094
- this._currentSubscription = null;
1095
- }
1096
- }
1097
- /**
1098
- * Provides a hook to override how the emitter emits an event to a specific
1099
- * subscription. This allows you to set up logging and error boundaries
1100
- * specific to your environment.
1101
- *
1102
- * @param {EmitterSubscription} subscription
1103
- * @param {string} eventType
1104
- * @param {*} Arbitrary arguments to be passed to each registered listener
1105
- */
1106
- ;
1107
-
1108
- _proto.__emitToSubscription = function __emitToSubscription(subscription, eventType) {
1109
- var args = Array.prototype.slice.call(arguments, 2);
1110
- subscription.listener.apply(subscription.context, args);
1111
- };
1112
-
1113
- return BaseEventEmitter;
1114
- }();
1115
-
1116
- var BaseEventEmitter_1 = BaseEventEmitter;
1117
-
1118
- /**
1119
- * Copyright (c) 2014-present, Facebook, Inc.
1120
- * All rights reserved.
1121
- *
1122
- * This source code is licensed under the BSD-style license found in the
1123
- * LICENSE file in the root directory of this source tree. An additional grant
1124
- * of patent rights can be found in the PATENTS file in the same directory.
1125
- */
1126
-
1127
- var fbemitter = {
1128
- EventEmitter: BaseEventEmitter_1,
1129
- EmitterSubscription : EmitterSubscription_1
1130
- };
1131
-
1132
- var fbemitter_1 = fbemitter;
1133
-
1134
- const {
1135
- EventEmitter
1136
- } = fbemitter_1;
1137
-
1138
- class FormEventEmitter extends EventEmitter {
1139
- constructor(options) {
1140
- super();
1141
- const {
1142
- debug,
1143
- name = 'event'
1144
- } = Object.assign({}, options);
1145
- this.debug = debug;
1146
- this.name = name;
1147
- }
1148
-
1149
- emit(...args) {
1150
- if (this.debug) {
1151
- console.log(`[${this.name}][debug]:`, ...args);
1152
- }
1153
-
1154
- super.emit(...args);
1155
- }
1156
-
1157
- }
1158
-
1159
- const useEvent = debug => {
1160
- const debugRef = useRef(debug);
1161
- return useMemo(() => {
1162
- const emitter = new FormEventEmitter(debugRef.current);
1163
- return {
1164
- addListener: (...args) => emitter.addListener(...args),
1165
- emit: (...args) => emitter.emit(...args),
1166
- removeAllListeners: (...args) => emitter.removeAllListeners(...args),
1167
- listeners: (...args) => emitter.listeners(...args),
1168
- once: (...args) => emitter.once(...args)
1169
- };
1170
- }, []);
1171
- };
1172
-
1173
- const _excluded$4 = ["data", "setData", "refresh", "reload", "emitter", "isLoading", "children"];
642
+ const _excluded$4 = ["data", "setData", "refresh", "reload", "emitter", "isLoading", "children", "onLoaded"];
1174
643
  const {
1175
644
  useOnChange: useOnChange$4
1176
645
  } = hooks;
@@ -1183,7 +652,8 @@ const _SelectFetch = withFetch(_ref => {
1183
652
  reload,
1184
653
  emitter,
1185
654
  isLoading,
1186
- children
655
+ children,
656
+ onLoaded
1187
657
  } = _ref,
1188
658
  props = _objectWithoutPropertiesLoose(_ref, _excluded$4);
1189
659
 
@@ -1193,6 +663,7 @@ const _SelectFetch = withFetch(_ref => {
1193
663
  reloadRef.current = reload;
1194
664
  const setDataRef = useRef(setData);
1195
665
  setDataRef.current = setData;
666
+ const dataRef = useRef(data);
1196
667
  useEffect(() => {
1197
668
  const token1 = emitter.addListener('select-fetch-refresh', () => refreshRef.current());
1198
669
  const token2 = emitter.addListener('select-fetch-reload', () => reloadRef.current());
@@ -1203,6 +674,9 @@ const _SelectFetch = withFetch(_ref => {
1203
674
  token3 && token3.remove();
1204
675
  };
1205
676
  }, [emitter]);
677
+ useEffect(() => {
678
+ onLoaded && onLoaded(dataRef.current);
679
+ }, []);
1206
680
  return /*#__PURE__*/React.createElement(Select$1, props, children({
1207
681
  data,
1208
682
  refresh,