victory-create-container 36.9.1 → 36.9.2-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
@@ -1,204 +1,116 @@
1
- import _isFunction from "lodash/isFunction";
2
1
  import _isEmpty from "lodash/isEmpty";
3
2
  import _flow from "lodash/flow";
4
3
  import _includes from "lodash/includes";
5
4
  import _forOwn from "lodash/forOwn";
6
5
  import _groupBy from "lodash/groupBy";
7
6
  import _toPairs from "lodash/toPairs";
8
-
9
- function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
10
-
11
- 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."); }
12
-
13
- function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
14
-
15
- function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
16
-
17
- 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; }
18
-
19
- 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; }
20
-
21
- 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; }
22
-
23
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
24
-
25
- 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); } }
26
-
27
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
28
-
29
- 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); }
30
-
31
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
32
-
33
- 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); }; }
34
-
35
- 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); }
36
-
37
- function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
38
-
39
- 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; } }
40
-
41
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
42
-
43
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
44
-
45
- 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."); }
46
-
47
- 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); }
48
-
49
- 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; }
50
-
51
- 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; }
52
-
53
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
54
-
55
- import { VictoryContainer, Log } from "victory-core";
7
+ import { Helpers, VictoryContainer, Log } from "victory-core";
56
8
  import { voronoiContainerMixin } from "victory-voronoi-container";
57
9
  import { zoomContainerMixin } from "victory-zoom-container";
58
10
  import { selectionContainerMixin } from "victory-selection-container";
59
11
  import { brushContainerMixin } from "victory-brush-container";
60
12
  import { cursorContainerMixin } from "victory-cursor-container";
61
-
62
13
  function ensureArray(thing) {
63
14
  if (!thing) {
64
15
  return [];
65
16
  } else if (!Array.isArray(thing)) {
66
17
  return [thing];
67
18
  }
68
-
69
19
  return thing;
70
20
  }
71
-
72
- var combineEventHandlers = function (eventHandlersArray) {
21
+ const combineEventHandlers = eventHandlersArray => {
73
22
  // takes an array of event handler objects and produces one eventHandlers object
74
23
  // creates a custom combinedHandler() for events with multiple conflicting handlers
75
- return eventHandlersArray.reduce(function (localHandlers, finalHandlers) {
76
- _forOwn(localHandlers, function (localHandler, eventName) {
77
- var existingHandler = finalHandlers[eventName];
78
-
24
+ return eventHandlersArray.reduce((localHandlers, finalHandlers) => {
25
+ _forOwn(localHandlers, (localHandler, eventName) => {
26
+ const existingHandler = finalHandlers[eventName];
79
27
  if (existingHandler) {
80
28
  // create new handler for event that concats the existing handler's mutations with new ones
81
29
  finalHandlers[eventName] = function combinedHandler() {
82
30
  // named for debug clarity
83
31
  // sometimes handlers return undefined; use empty array instead, for concat()
84
- var existingMutations = ensureArray(existingHandler.apply(void 0, arguments));
85
- var localMutations = ensureArray(localHandler.apply(void 0, arguments));
32
+ const existingMutations = ensureArray(existingHandler(...arguments));
33
+ const localMutations = ensureArray(localHandler(...arguments));
86
34
  return existingMutations.concat(localMutations);
87
35
  };
88
36
  } else {
89
37
  finalHandlers[eventName] = localHandler;
90
38
  }
91
39
  });
92
-
93
40
  return finalHandlers;
94
41
  });
95
42
  };
96
-
97
- var combineDefaultEvents = function (defaultEvents) {
43
+ const combineDefaultEvents = defaultEvents => {
98
44
  // takes a defaultEvents array and returns one equal or lesser length,
99
45
  // by combining any events that have the same target
100
- var eventsByTarget = _groupBy(defaultEvents, "target");
101
-
102
- var events = _toPairs(eventsByTarget).map(function (_ref) {
103
- var _ref2 = _slicedToArray(_ref, 2),
104
- target = _ref2[0],
105
- eventsArray = _ref2[1];
106
-
107
- var newEventsArray = eventsArray.filter(Boolean);
46
+ const eventsByTarget = _groupBy(defaultEvents, "target");
47
+ const events = _toPairs(eventsByTarget).map(_ref => {
48
+ let [target, eventsArray] = _ref;
49
+ const newEventsArray = eventsArray.filter(Boolean);
108
50
  return _isEmpty(newEventsArray) ? null : {
109
- target: target,
110
- eventHandlers: combineEventHandlers(eventsArray.map(function (event) {
111
- return event.eventHandlers;
112
- })) // note: does not currently handle eventKey or childName
113
-
51
+ target,
52
+ eventHandlers: combineEventHandlers(eventsArray.map(event => event.eventHandlers))
53
+ // note: does not currently handle eventKey or childName
114
54
  };
115
55
  });
116
-
117
56
  return events.filter(Boolean);
118
57
  };
119
-
120
- export var combineContainerMixins = function (mixins, Container) {
121
- var _class;
122
-
58
+ export const combineContainerMixins = (mixins, Container) => {
123
59
  // similar to Object.assign(A, B), this function will decide conflicts in favor mixinB.
124
60
  // this applies to propTypes and defaultProps.
125
61
  // getChildren will call A's getChildren() and pass the resulting children to B's.
126
62
  // defaultEvents attempts to resolve any conflicts between A and B's defaultEvents.
127
- var Classes = mixins.map(function (mixin) {
128
- return mixin(Container);
129
- });
130
- var instances = Classes.map(function (Class) {
131
- return new Class();
132
- });
133
-
134
- var NaiveCombinedContainer = _flow(mixins)(Container);
135
-
136
- var displayType = Classes.map(function (Class) {
137
- var match = Class.displayName.match(/Victory(.*)Container/);
63
+ const Classes = mixins.map(mixin => mixin(Container));
64
+ const instances = Classes.map(Class => new Class());
65
+ const NaiveCombinedContainer = _flow(mixins)(Container);
66
+ const displayType = Classes.map(Class => {
67
+ const match = Class.displayName.match(/Victory(.*)Container/);
138
68
  return match[1] || "";
139
69
  }).join("");
140
- return _class = /*#__PURE__*/function (_NaiveCombinedContain) {
141
- _inherits(VictoryCombinedContainer, _NaiveCombinedContain);
142
-
143
- var _super = _createSuper(VictoryCombinedContainer);
144
-
145
- function VictoryCombinedContainer() {
146
- _classCallCheck(this, VictoryCombinedContainer);
147
-
148
- return _super.apply(this, arguments);
70
+ return class VictoryCombinedContainer extends NaiveCombinedContainer {
71
+ static displayName = `Victory${displayType}Container`;
72
+ static propTypes = Classes.reduce((propTypes, Class) => ({
73
+ ...propTypes,
74
+ ...Class.propTypes
75
+ }), {});
76
+ static defaultProps = Classes.reduce((defaultProps, Class) => ({
77
+ ...defaultProps,
78
+ ...Class.defaultProps
79
+ }), {});
80
+ static defaultEvents = props => {
81
+ return combineDefaultEvents(Classes.reduce((defaultEvents, Class) => {
82
+ const events = Helpers.isFunction(Class.defaultEvents) ? Class.defaultEvents(props) : Class.defaultEvents;
83
+ return [...defaultEvents, ...events];
84
+ }, []));
85
+ };
86
+ getChildren(props) {
87
+ return instances.reduce((children, instance) => instance.getChildren({
88
+ ...props,
89
+ children
90
+ }), props.children);
149
91
  }
150
-
151
- _createClass(VictoryCombinedContainer, [{
152
- key: "getChildren",
153
- value: function getChildren(props) {
154
- return instances.reduce(function (children, instance) {
155
- return instance.getChildren(_objectSpread(_objectSpread({}, props), {}, {
156
- children: children
157
- }));
158
- }, props.children);
159
- }
160
- }]);
161
-
162
- return VictoryCombinedContainer;
163
- }(NaiveCombinedContainer), _class.displayName = "Victory".concat(displayType, "Container"), _class.propTypes = Classes.reduce(function (propTypes, Class) {
164
- return _objectSpread(_objectSpread({}, propTypes), Class.propTypes);
165
- }, {}), _class.defaultProps = Classes.reduce(function (defaultProps, Class) {
166
- return _objectSpread(_objectSpread({}, defaultProps), Class.defaultProps);
167
- }, {}), _class.defaultEvents = function (props) {
168
- return combineDefaultEvents(Classes.reduce(function (defaultEvents, Class) {
169
- var events = _isFunction(Class.defaultEvents) ? Class.defaultEvents(props) : Class.defaultEvents;
170
- return [].concat(_toConsumableArray(defaultEvents), _toConsumableArray(events));
171
- }, []));
172
- }, _class;
92
+ };
173
93
  };
174
-
175
- var checkBehaviorName = function (behavior, behaviors) {
94
+ const checkBehaviorName = (behavior, behaviors) => {
176
95
  if (behavior && !_includes(behaviors, behavior)) {
177
- Log.warn("\"".concat(behavior, "\" is not a valid behavior. Choose from [").concat(behaviors.join(", "), "]."));
96
+ Log.warn(`"${behavior}" is not a valid behavior. Choose from [${behaviors.join(", ")}].`);
178
97
  }
179
98
  };
180
-
181
- export var makeCreateContainerFunction = function (mixinMap, Container) {
182
- return function (behaviorA, behaviorB) {
183
- var behaviors = Object.keys(mixinMap);
184
- checkBehaviorName(behaviorA, behaviors);
185
- checkBehaviorName(behaviorB, behaviors);
186
-
187
- if (arguments.length <= 2 ? 0 : arguments.length - 2) {
188
- Log.warn("too many arguments given to createContainer (maximum accepted: 2).");
189
- }
190
-
191
- var firstMixins = mixinMap[behaviorA];
192
- var secondMixins = mixinMap[behaviorB] || [];
193
-
194
- if (!firstMixins) {
195
- return Container;
196
- }
197
-
198
- return combineContainerMixins([].concat(_toConsumableArray(firstMixins), _toConsumableArray(secondMixins)), Container);
199
- };
99
+ export const makeCreateContainerFunction = (mixinMap, Container) => function (behaviorA, behaviorB) {
100
+ const behaviors = Object.keys(mixinMap);
101
+ checkBehaviorName(behaviorA, behaviors);
102
+ checkBehaviorName(behaviorB, behaviors);
103
+ if (arguments.length <= 2 ? 0 : arguments.length - 2) {
104
+ Log.warn("too many arguments given to createContainer (maximum accepted: 2).");
105
+ }
106
+ const firstMixins = mixinMap[behaviorA];
107
+ const secondMixins = mixinMap[behaviorB] || [];
108
+ if (!firstMixins) {
109
+ return Container;
110
+ }
111
+ return combineContainerMixins([...firstMixins, ...secondMixins], Container);
200
112
  };
201
- export var createContainer = makeCreateContainerFunction({
113
+ export const createContainer = makeCreateContainerFunction({
202
114
  zoom: [zoomContainerMixin],
203
115
  voronoi: [voronoiContainerMixin],
204
116
  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