victory-create-container 36.9.2 → 37.0.1-next.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,47 +1,47 @@
1
- import React from "react";
2
- export declare type ContainerType = "brush" | "cursor" | "selection" | "voronoi" | "zoom";
3
- declare type MixinFunction = (...args: any[]) => any;
4
- export declare const combineContainerMixins: (mixins: MixinFunction[], Container: React.ComponentType<any>) => {
5
- new (): {
6
- [x: string]: any;
7
- getChildren(props: any): any;
8
- };
9
- [x: string]: any;
10
- displayName: string;
11
- propTypes: any;
12
- defaultProps: any;
13
- defaultEvents: (props: any) => ({
14
- target: string;
15
- eventHandlers: any;
16
- } | null)[];
17
- };
18
- export declare const makeCreateContainerFunction: (mixinMap: Record<ContainerType, MixinFunction[]>, Container: React.ComponentType<any>) => (behaviorA: ContainerType, behaviorB: ContainerType, ...invalid: ContainerType[]) => React.ComponentType<any> | {
19
- new (): {
20
- [x: string]: any;
21
- getChildren(props: any): any;
22
- };
23
- [x: string]: any;
24
- displayName: string;
25
- propTypes: any;
26
- defaultProps: any;
27
- defaultEvents: (props: any) => ({
28
- target: string;
29
- eventHandlers: any;
30
- } | null)[];
31
- };
32
- export declare const createContainer: (behaviorA: ContainerType, behaviorB: ContainerType, ...invalid: ContainerType[]) => React.ComponentType<any> | {
33
- new (): {
34
- [x: string]: any;
35
- getChildren(props: any): any;
36
- };
37
- [x: string]: any;
38
- displayName: string;
39
- propTypes: any;
40
- defaultProps: any;
41
- defaultEvents: (props: any) => ({
42
- target: string;
43
- eventHandlers: any;
44
- } | null)[];
45
- };
46
- export {};
1
+ import React from "react";
2
+ export declare type ContainerType = "brush" | "cursor" | "selection" | "voronoi" | "zoom";
3
+ declare type MixinFunction = (...args: any[]) => any;
4
+ export declare const combineContainerMixins: (mixins: MixinFunction[], Container: React.ComponentType<any>) => {
5
+ new (): {
6
+ [x: string]: any;
7
+ getChildren(props: any): any;
8
+ };
9
+ [x: string]: any;
10
+ displayName: string;
11
+ propTypes: any;
12
+ defaultProps: any;
13
+ defaultEvents(props: any): ({
14
+ target: string;
15
+ eventHandlers: any;
16
+ } | null)[];
17
+ };
18
+ export declare const makeCreateContainerFunction: (mixinMap: Record<ContainerType, MixinFunction[]>, Container: React.ComponentType<any>) => (behaviorA: ContainerType, behaviorB: ContainerType, ...invalid: ContainerType[]) => React.ComponentType<any> | {
19
+ new (): {
20
+ [x: string]: any;
21
+ getChildren(props: any): any;
22
+ };
23
+ [x: string]: any;
24
+ displayName: string;
25
+ propTypes: any;
26
+ defaultProps: any;
27
+ defaultEvents(props: any): ({
28
+ target: string;
29
+ eventHandlers: any;
30
+ } | null)[];
31
+ };
32
+ export declare const createContainer: (behaviorA: ContainerType, behaviorB: ContainerType, ...invalid: ContainerType[]) => React.ComponentType<any> | {
33
+ new (): {
34
+ [x: string]: any;
35
+ getChildren(props: any): any;
36
+ };
37
+ [x: string]: any;
38
+ displayName: string;
39
+ propTypes: any;
40
+ defaultProps: any;
41
+ defaultEvents(props: any): ({
42
+ target: string;
43
+ eventHandlers: any;
44
+ } | null)[];
45
+ };
46
+ export {};
47
47
  //# sourceMappingURL=create-container.d.ts.map
@@ -3,200 +3,113 @@ import _flow from "lodash/flow";
3
3
  import _forOwn from "lodash/forOwn";
4
4
  import _groupBy from "lodash/groupBy";
5
5
  import _toPairs from "lodash/toPairs";
6
-
7
- function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
8
-
9
- function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
10
-
11
- function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
12
-
13
- function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
14
-
15
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
16
-
17
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
18
-
19
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
20
-
21
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
22
-
23
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
24
-
25
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
26
-
27
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
28
-
29
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
30
-
31
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
32
-
33
- function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
34
-
35
- function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
36
-
37
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
38
-
39
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
40
-
41
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
42
-
43
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
44
-
45
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
46
-
47
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
48
-
49
- function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
50
-
51
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
52
-
53
6
  import { Helpers, VictoryContainer, Log } from "victory-core";
54
7
  import { voronoiContainerMixin } from "victory-voronoi-container";
55
8
  import { zoomContainerMixin } from "victory-zoom-container";
56
9
  import { selectionContainerMixin } from "victory-selection-container";
57
10
  import { brushContainerMixin } from "victory-brush-container";
58
11
  import { cursorContainerMixin } from "victory-cursor-container";
59
-
60
12
  function ensureArray(thing) {
61
13
  if (!thing) {
62
14
  return [];
63
15
  } else if (!Array.isArray(thing)) {
64
16
  return [thing];
65
17
  }
66
-
67
18
  return thing;
68
19
  }
69
-
70
- var combineEventHandlers = function (eventHandlersArray) {
20
+ const combineEventHandlers = eventHandlersArray => {
71
21
  // takes an array of event handler objects and produces one eventHandlers object
72
22
  // creates a custom combinedHandler() for events with multiple conflicting handlers
73
- return eventHandlersArray.reduce(function (localHandlers, finalHandlers) {
74
- _forOwn(localHandlers, function (localHandler, eventName) {
75
- var existingHandler = finalHandlers[eventName];
76
-
23
+ return eventHandlersArray.reduce((localHandlers, finalHandlers) => {
24
+ _forOwn(localHandlers, (localHandler, eventName) => {
25
+ const existingHandler = finalHandlers[eventName];
77
26
  if (existingHandler) {
78
27
  // create new handler for event that concats the existing handler's mutations with new ones
79
28
  finalHandlers[eventName] = function combinedHandler() {
80
29
  // named for debug clarity
81
30
  // sometimes handlers return undefined; use empty array instead, for concat()
82
- var existingMutations = ensureArray(existingHandler.apply(void 0, arguments));
83
- var localMutations = ensureArray(localHandler.apply(void 0, arguments));
31
+ const existingMutations = ensureArray(existingHandler(...arguments));
32
+ const localMutations = ensureArray(localHandler(...arguments));
84
33
  return existingMutations.concat(localMutations);
85
34
  };
86
35
  } else {
87
36
  finalHandlers[eventName] = localHandler;
88
37
  }
89
38
  });
90
-
91
39
  return finalHandlers;
92
40
  });
93
41
  };
94
-
95
- var combineDefaultEvents = function (defaultEvents) {
42
+ const combineDefaultEvents = defaultEvents => {
96
43
  // takes a defaultEvents array and returns one equal or lesser length,
97
44
  // by combining any events that have the same target
98
- var eventsByTarget = _groupBy(defaultEvents, "target");
99
-
100
- var events = _toPairs(eventsByTarget).map(function (_ref) {
101
- var _ref2 = _slicedToArray(_ref, 2),
102
- target = _ref2[0],
103
- eventsArray = _ref2[1];
104
-
105
- var newEventsArray = eventsArray.filter(Boolean);
45
+ const eventsByTarget = _groupBy(defaultEvents, "target");
46
+ const events = _toPairs(eventsByTarget).map(_ref => {
47
+ let [target, eventsArray] = _ref;
48
+ const newEventsArray = eventsArray.filter(Boolean);
106
49
  return _isEmpty(newEventsArray) ? null : {
107
- target: target,
108
- eventHandlers: combineEventHandlers(eventsArray.map(function (event) {
109
- return event.eventHandlers;
110
- })) // note: does not currently handle eventKey or childName
111
-
50
+ target,
51
+ eventHandlers: combineEventHandlers(eventsArray.map(event => event.eventHandlers))
52
+ // note: does not currently handle eventKey or childName
112
53
  };
113
54
  });
114
-
115
55
  return events.filter(Boolean);
116
56
  };
117
-
118
- export var combineContainerMixins = function (mixins, Container) {
119
- var _class;
120
-
57
+ export const combineContainerMixins = (mixins, Container) => {
121
58
  // similar to Object.assign(A, B), this function will decide conflicts in favor mixinB.
122
59
  // this applies to propTypes and defaultProps.
123
60
  // getChildren will call A's getChildren() and pass the resulting children to B's.
124
61
  // defaultEvents attempts to resolve any conflicts between A and B's defaultEvents.
125
- var Classes = mixins.map(function (mixin) {
126
- return mixin(Container);
127
- });
128
- var instances = Classes.map(function (Class) {
129
- return new Class();
130
- });
131
-
132
- var NaiveCombinedContainer = _flow(mixins)(Container);
133
-
134
- var displayType = Classes.map(function (Class) {
135
- var match = Class.displayName.match(/Victory(.*)Container/);
62
+ const Classes = mixins.map(mixin => mixin(Container));
63
+ const instances = Classes.map(Class => new Class());
64
+ const NaiveCombinedContainer = _flow(mixins)(Container);
65
+ const displayType = Classes.map(Class => {
66
+ const match = Class.displayName.match(/Victory(.*)Container/);
136
67
  return match[1] || "";
137
68
  }).join("");
138
- return _class = /*#__PURE__*/function (_NaiveCombinedContain) {
139
- _inherits(VictoryCombinedContainer, _NaiveCombinedContain);
140
-
141
- var _super = _createSuper(VictoryCombinedContainer);
142
-
143
- function VictoryCombinedContainer() {
144
- _classCallCheck(this, VictoryCombinedContainer);
145
-
146
- return _super.apply(this, arguments);
69
+ return class VictoryCombinedContainer extends NaiveCombinedContainer {
70
+ static displayName = `Victory${displayType}Container`;
71
+ static propTypes = Classes.reduce((propTypes, Class) => ({
72
+ ...propTypes,
73
+ ...Class.propTypes
74
+ }), {});
75
+ static defaultProps = Classes.reduce((defaultProps, Class) => ({
76
+ ...defaultProps,
77
+ ...Class.defaultProps
78
+ }), {});
79
+ static defaultEvents(props) {
80
+ return combineDefaultEvents(Classes.reduce((defaultEvents, Class) => {
81
+ const events = Helpers.isFunction(Class.defaultEvents) ? Class.defaultEvents(props) : Class.defaultEvents;
82
+ return [...defaultEvents, ...events];
83
+ }, []));
147
84
  }
148
-
149
- _createClass(VictoryCombinedContainer, [{
150
- key: "getChildren",
151
- value: function getChildren(props) {
152
- return instances.reduce(function (children, instance) {
153
- return instance.getChildren(_objectSpread(_objectSpread({}, props), {}, {
154
- children: children
155
- }));
156
- }, props.children);
157
- }
158
- }]);
159
-
160
- return VictoryCombinedContainer;
161
- }(NaiveCombinedContainer), _class.displayName = "Victory".concat(displayType, "Container"), _class.propTypes = Classes.reduce(function (propTypes, Class) {
162
- return _objectSpread(_objectSpread({}, propTypes), Class.propTypes);
163
- }, {}), _class.defaultProps = Classes.reduce(function (defaultProps, Class) {
164
- return _objectSpread(_objectSpread({}, defaultProps), Class.defaultProps);
165
- }, {}), _class.defaultEvents = function (props) {
166
- return combineDefaultEvents(Classes.reduce(function (defaultEvents, Class) {
167
- var events = Helpers.isFunction(Class.defaultEvents) ? Class.defaultEvents(props) : Class.defaultEvents;
168
- return [].concat(_toConsumableArray(defaultEvents), _toConsumableArray(events));
169
- }, []));
170
- }, _class;
85
+ getChildren(props) {
86
+ return instances.reduce((children, instance) => instance.getChildren({
87
+ ...props,
88
+ children
89
+ }), props.children);
90
+ }
91
+ };
171
92
  };
172
-
173
- var checkBehaviorName = function (behavior, behaviors) {
93
+ const checkBehaviorName = (behavior, behaviors) => {
174
94
  if (behavior && !behaviors.includes(behavior)) {
175
- Log.warn("\"".concat(behavior, "\" is not a valid behavior. Choose from [").concat(behaviors.join(", "), "]."));
95
+ Log.warn(`"${behavior}" is not a valid behavior. Choose from [${behaviors.join(", ")}].`);
176
96
  }
177
97
  };
178
-
179
- export var makeCreateContainerFunction = function (mixinMap, Container) {
180
- return function (behaviorA, behaviorB) {
181
- var behaviors = Object.keys(mixinMap);
182
- checkBehaviorName(behaviorA, behaviors);
183
- checkBehaviorName(behaviorB, behaviors);
184
-
185
- if (arguments.length <= 2 ? 0 : arguments.length - 2) {
186
- Log.warn("too many arguments given to createContainer (maximum accepted: 2).");
187
- }
188
-
189
- var firstMixins = mixinMap[behaviorA];
190
- var secondMixins = mixinMap[behaviorB] || [];
191
-
192
- if (!firstMixins) {
193
- return Container;
194
- }
195
-
196
- return combineContainerMixins([].concat(_toConsumableArray(firstMixins), _toConsumableArray(secondMixins)), Container);
197
- };
98
+ export const makeCreateContainerFunction = (mixinMap, Container) => function (behaviorA, behaviorB) {
99
+ const behaviors = Object.keys(mixinMap);
100
+ checkBehaviorName(behaviorA, behaviors);
101
+ checkBehaviorName(behaviorB, behaviors);
102
+ if (arguments.length <= 2 ? 0 : arguments.length - 2) {
103
+ Log.warn("too many arguments given to createContainer (maximum accepted: 2).");
104
+ }
105
+ const firstMixins = mixinMap[behaviorA];
106
+ const secondMixins = mixinMap[behaviorB] || [];
107
+ if (!firstMixins) {
108
+ return Container;
109
+ }
110
+ return combineContainerMixins([...firstMixins, ...secondMixins], Container);
198
111
  };
199
- export var createContainer = makeCreateContainerFunction({
112
+ export const createContainer = makeCreateContainerFunction({
200
113
  zoom: [zoomContainerMixin],
201
114
  voronoi: [voronoiContainerMixin],
202
115
  selection: [selectionContainerMixin],
package/es/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export * from "./create-container";
1
+ export * from "./create-container";
2
2
  //# sourceMappingURL=index.d.ts.map
@@ -1,47 +1,47 @@
1
- import React from "react";
2
- export declare type ContainerType = "brush" | "cursor" | "selection" | "voronoi" | "zoom";
3
- declare type MixinFunction = (...args: any[]) => any;
4
- export declare const combineContainerMixins: (mixins: MixinFunction[], Container: React.ComponentType<any>) => {
5
- new (): {
6
- [x: string]: any;
7
- getChildren(props: any): any;
8
- };
9
- [x: string]: any;
10
- displayName: string;
11
- propTypes: any;
12
- defaultProps: any;
13
- defaultEvents: (props: any) => ({
14
- target: string;
15
- eventHandlers: any;
16
- } | null)[];
17
- };
18
- export declare const makeCreateContainerFunction: (mixinMap: Record<ContainerType, MixinFunction[]>, Container: React.ComponentType<any>) => (behaviorA: ContainerType, behaviorB: ContainerType, ...invalid: ContainerType[]) => React.ComponentType<any> | {
19
- new (): {
20
- [x: string]: any;
21
- getChildren(props: any): any;
22
- };
23
- [x: string]: any;
24
- displayName: string;
25
- propTypes: any;
26
- defaultProps: any;
27
- defaultEvents: (props: any) => ({
28
- target: string;
29
- eventHandlers: any;
30
- } | null)[];
31
- };
32
- export declare const createContainer: (behaviorA: ContainerType, behaviorB: ContainerType, ...invalid: ContainerType[]) => React.ComponentType<any> | {
33
- new (): {
34
- [x: string]: any;
35
- getChildren(props: any): any;
36
- };
37
- [x: string]: any;
38
- displayName: string;
39
- propTypes: any;
40
- defaultProps: any;
41
- defaultEvents: (props: any) => ({
42
- target: string;
43
- eventHandlers: any;
44
- } | null)[];
45
- };
46
- export {};
1
+ import React from "react";
2
+ export declare type ContainerType = "brush" | "cursor" | "selection" | "voronoi" | "zoom";
3
+ declare type MixinFunction = (...args: any[]) => any;
4
+ export declare const combineContainerMixins: (mixins: MixinFunction[], Container: React.ComponentType<any>) => {
5
+ new (): {
6
+ [x: string]: any;
7
+ getChildren(props: any): any;
8
+ };
9
+ [x: string]: any;
10
+ displayName: string;
11
+ propTypes: any;
12
+ defaultProps: any;
13
+ defaultEvents(props: any): ({
14
+ target: string;
15
+ eventHandlers: any;
16
+ } | null)[];
17
+ };
18
+ export declare const makeCreateContainerFunction: (mixinMap: Record<ContainerType, MixinFunction[]>, Container: React.ComponentType<any>) => (behaviorA: ContainerType, behaviorB: ContainerType, ...invalid: ContainerType[]) => React.ComponentType<any> | {
19
+ new (): {
20
+ [x: string]: any;
21
+ getChildren(props: any): any;
22
+ };
23
+ [x: string]: any;
24
+ displayName: string;
25
+ propTypes: any;
26
+ defaultProps: any;
27
+ defaultEvents(props: any): ({
28
+ target: string;
29
+ eventHandlers: any;
30
+ } | null)[];
31
+ };
32
+ export declare const createContainer: (behaviorA: ContainerType, behaviorB: ContainerType, ...invalid: ContainerType[]) => React.ComponentType<any> | {
33
+ new (): {
34
+ [x: string]: any;
35
+ getChildren(props: any): any;
36
+ };
37
+ [x: string]: any;
38
+ displayName: string;
39
+ propTypes: any;
40
+ defaultProps: any;
41
+ defaultEvents(props: any): ({
42
+ target: string;
43
+ eventHandlers: any;
44
+ } | null)[];
45
+ };
46
+ export {};
47
47
  //# sourceMappingURL=create-container.d.ts.map