UNPKG

@visactor/react-vtable

Version:

The react version of VTable

1,283 lines (1,218 loc) 856 kB
(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@visactor/vtable'), require('react')) : typeof define === 'function' && define.amd ? define(['exports', '@visactor/vtable', 'react'], factory) : (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ReactVTable = {}, global.VTable, global.React)); })(this, (function (exports, vtable, React) { 'use strict'; function withContainer(Comp, name = 'TableContainer', getProps) { const Cls = React.forwardRef((props, ref) => { const container = React.useRef(); const [inited, setInited] = React.useState(false); const { className, style, width, ...options } = props; React.useLayoutEffect(() => { setInited(true); }, []); return (React.createElement("div", { ref: container, className: className, style: { position: 'relative', height: props.height || '100%', width: props.width || '100%', ...style } }, inited ? (React.createElement(Comp, { ref: ref, container: container.current, ...(getProps ? getProps(options) : options) })) : (React.createElement(React.Fragment, null)))); }); Cls.displayName = name || Comp.name; return Cls; } const TableContext = React.createContext(null); TableContext.displayName = 'TableContext'; function getDefaultExportFromCjs (x) { return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x; } var eventemitter3 = {exports: {}}; (function (module) { var has = Object.prototype.hasOwnProperty, prefix = '~'; /** * Constructor to create a storage for our `EE` objects. * An `Events` instance is a plain object whose properties are event names. * * @constructor * @private */ function Events() {} // // We try to not inherit from `Object.prototype`. In some engines creating an // instance in this way is faster than calling `Object.create(null)` directly. // If `Object.create(null)` is not supported we prefix the event names with a // character to make sure that the built-in object properties are not // overridden or used as an attack vector. // if (Object.create) { Events.prototype = Object.create(null); // // This hack is needed because the `__proto__` property is still inherited in // some old browsers like Android 4, iPhone 5.1, Opera 11 and Safari 5. // if (!new Events().__proto__) prefix = false; } /** * Representation of a single event listener. * * @param {Function} fn The listener function. * @param {*} context The context to invoke the listener with. * @param {Boolean} [once=false] Specify if the listener is a one-time listener. * @constructor * @private */ function EE(fn, context, once) { this.fn = fn; this.context = context; this.once = once || false; } /** * Add a listener for a given event. * * @param {EventEmitter} emitter Reference to the `EventEmitter` instance. * @param {(String|Symbol)} event The event name. * @param {Function} fn The listener function. * @param {*} context The context to invoke the listener with. * @param {Boolean} once Specify if the listener is a one-time listener. * @returns {EventEmitter} * @private */ function addListener(emitter, event, fn, context, once) { if (typeof fn !== 'function') { throw new TypeError('The listener must be a function'); } var listener = new EE(fn, context || emitter, once), evt = prefix ? prefix + event : event; if (!emitter._events[evt]) emitter._events[evt] = listener, emitter._eventsCount++;else if (!emitter._events[evt].fn) emitter._events[evt].push(listener);else emitter._events[evt] = [emitter._events[evt], listener]; return emitter; } /** * Clear event by name. * * @param {EventEmitter} emitter Reference to the `EventEmitter` instance. * @param {(String|Symbol)} evt The Event name. * @private */ function clearEvent(emitter, evt) { if (--emitter._eventsCount === 0) emitter._events = new Events();else delete emitter._events[evt]; } /** * Minimal `EventEmitter` interface that is molded against the Node.js * `EventEmitter` interface. * * @constructor * @public */ function EventEmitter() { this._events = new Events(); this._eventsCount = 0; } /** * Return an array listing the events for which the emitter has registered * listeners. * * @returns {Array} * @public */ EventEmitter.prototype.eventNames = function eventNames() { var names = [], events, name; if (this._eventsCount === 0) return names; for (name in events = this._events) { if (has.call(events, name)) names.push(prefix ? name.slice(1) : name); } if (Object.getOwnPropertySymbols) { return names.concat(Object.getOwnPropertySymbols(events)); } return names; }; /** * Return the listeners registered for a given event. * * @param {(String|Symbol)} event The event name. * @returns {Array} The registered listeners. * @public */ EventEmitter.prototype.listeners = function listeners(event) { var evt = prefix ? prefix + event : event, handlers = this._events[evt]; if (!handlers) return []; if (handlers.fn) return [handlers.fn]; for (var i = 0, l = handlers.length, ee = new Array(l); i < l; i++) { ee[i] = handlers[i].fn; } return ee; }; /** * Return the number of listeners listening to a given event. * * @param {(String|Symbol)} event The event name. * @returns {Number} The number of listeners. * @public */ EventEmitter.prototype.listenerCount = function listenerCount(event) { var evt = prefix ? prefix + event : event, listeners = this._events[evt]; if (!listeners) return 0; if (listeners.fn) return 1; return listeners.length; }; /** * Calls each of the listeners registered for a given event. * * @param {(String|Symbol)} event The event name. * @returns {Boolean} `true` if the event had listeners, else `false`. * @public */ EventEmitter.prototype.emit = function emit(event, a1, a2, a3, a4, a5) { var evt = prefix ? prefix + event : event; if (!this._events[evt]) return false; var listeners = this._events[evt], len = arguments.length, args, i; if (listeners.fn) { if (listeners.once) this.removeListener(event, listeners.fn, undefined, true); switch (len) { case 1: return listeners.fn.call(listeners.context), true; case 2: return listeners.fn.call(listeners.context, a1), true; case 3: return listeners.fn.call(listeners.context, a1, a2), true; case 4: return listeners.fn.call(listeners.context, a1, a2, a3), true; case 5: return listeners.fn.call(listeners.context, a1, a2, a3, a4), true; case 6: return listeners.fn.call(listeners.context, a1, a2, a3, a4, a5), true; } for (i = 1, args = new Array(len - 1); i < len; i++) { args[i - 1] = arguments[i]; } listeners.fn.apply(listeners.context, args); } else { var length = listeners.length, j; for (i = 0; i < length; i++) { if (listeners[i].once) this.removeListener(event, listeners[i].fn, undefined, true); switch (len) { case 1: listeners[i].fn.call(listeners[i].context); break; case 2: listeners[i].fn.call(listeners[i].context, a1); break; case 3: listeners[i].fn.call(listeners[i].context, a1, a2); break; case 4: listeners[i].fn.call(listeners[i].context, a1, a2, a3); break; default: if (!args) for (j = 1, args = new Array(len - 1); j < len; j++) { args[j - 1] = arguments[j]; } listeners[i].fn.apply(listeners[i].context, args); } } } return true; }; /** * Add a listener for a given event. * * @param {(String|Symbol)} event The event name. * @param {Function} fn The listener function. * @param {*} [context=this] The context to invoke the listener with. * @returns {EventEmitter} `this`. * @public */ EventEmitter.prototype.on = function on(event, fn, context) { return addListener(this, event, fn, context, false); }; /** * Add a one-time listener for a given event. * * @param {(String|Symbol)} event The event name. * @param {Function} fn The listener function. * @param {*} [context=this] The context to invoke the listener with. * @returns {EventEmitter} `this`. * @public */ EventEmitter.prototype.once = function once(event, fn, context) { return addListener(this, event, fn, context, true); }; /** * Remove the listeners of a given event. * * @param {(String|Symbol)} event The event name. * @param {Function} fn Only remove the listeners that match this function. * @param {*} context Only remove the listeners that have this context. * @param {Boolean} once Only remove one-time listeners. * @returns {EventEmitter} `this`. * @public */ EventEmitter.prototype.removeListener = function removeListener(event, fn, context, once) { var evt = prefix ? prefix + event : event; if (!this._events[evt]) return this; if (!fn) { clearEvent(this, evt); return this; } var listeners = this._events[evt]; if (listeners.fn) { if (listeners.fn === fn && (!once || listeners.once) && (!context || listeners.context === context)) { clearEvent(this, evt); } } else { for (var i = 0, events = [], length = listeners.length; i < length; i++) { if (listeners[i].fn !== fn || once && !listeners[i].once || context && listeners[i].context !== context) { events.push(listeners[i]); } } // // Reset the array, or remove it completely if we have no more listeners. // if (events.length) this._events[evt] = events.length === 1 ? events[0] : events;else clearEvent(this, evt); } return this; }; /** * Remove all listeners, or those of the specified event. * * @param {(String|Symbol)} [event] The event name. * @returns {EventEmitter} `this`. * @public */ EventEmitter.prototype.removeAllListeners = function removeAllListeners(event) { var evt; if (event) { evt = prefix ? prefix + event : event; if (this._events[evt]) clearEvent(this, evt); } else { this._events = new Events(); this._eventsCount = 0; } return this; }; // // Alias methods names because people roll like that. // EventEmitter.prototype.off = EventEmitter.prototype.removeListener; EventEmitter.prototype.addListener = EventEmitter.prototype.on; // // Expose the prefix. // EventEmitter.prefixed = prefix; // // Allow `EventEmitter` to be imported as module namespace. // EventEmitter.EventEmitter = EventEmitter; // // Expose the module. // { module.exports = EventEmitter; } })(eventemitter3); var eventemitter3Exports = eventemitter3.exports; var EventEmitter = /*@__PURE__*/getDefaultExportFromCjs(eventemitter3Exports); const isType$2 = (value, type) => Object.prototype.toString.call(value) === `[object ${type}]`; var isType$3 = isType$2; const isFunction$2 = value => "function" == typeof value; var isFunction$3 = isFunction$2; const isNil$2 = value => null == value; var isNil$3 = isNil$2; const isValid$2 = value => null != value; var isValid$3 = isValid$2; const isObject$2 = value => { const type = typeof value; return null !== value && "object" === type || "function" === type; }; var isObject$3 = isObject$2; const isObjectLike$2 = value => "object" == typeof value && null !== value; var isObjectLike$3 = isObjectLike$2; const isPlainObject$2 = function (value) { if (!isObjectLike$3(value) || !isType$3(value, "Object")) return !1; if (null === Object.getPrototypeOf(value)) return !0; let proto = value; for (; null !== Object.getPrototypeOf(proto);) proto = Object.getPrototypeOf(proto); return Object.getPrototypeOf(value) === proto; }; var isPlainObject$3 = isPlainObject$2; const isString$2 = (value, fuzzy = !1) => { const type = typeof value; return fuzzy ? "string" === type : "string" === type || isType$3(value, "String"); }; var isString$3 = isString$2; const isArray$2 = value => Array.isArray ? Array.isArray(value) : isType$3(value, "Array"); var isArray$3 = isArray$2; const isArrayLike$2 = function (value) { return null !== value && "function" != typeof value && Number.isFinite(value.length); }; var isArrayLike$3 = isArrayLike$2; const isNumber$2 = (value, fuzzy = !1) => { const type = typeof value; return fuzzy ? "number" === type : "number" === type || isType$3(value, "Number"); }; var isNumber$3 = isNumber$2; function baseMerge$1(target, source, shallowArray = !1, skipTargetArray = !1) { if (source) { if (target === source) return; if (isValid$3(source) && "object" == typeof source) { const iterable = Object(source), props = []; for (const key in iterable) props.push(key); let { length: length } = props, propIndex = -1; for (; length--;) { const key = props[++propIndex]; !isValid$3(iterable[key]) || "object" != typeof iterable[key] || skipTargetArray && isArray$3(target[key]) ? assignMergeValue$1(target, key, iterable[key]) : baseMergeDeep$1(target, source, key, shallowArray, skipTargetArray); } } } } function baseMergeDeep$1(target, source, key, shallowArray = !1, skipTargetArray = !1) { const objValue = target[key], srcValue = source[key]; let newValue = source[key], isCommon = !0; if (isArray$3(srcValue)) { if (shallowArray) newValue = [];else if (isArray$3(objValue)) newValue = objValue;else if (isArrayLike$3(objValue)) { newValue = new Array(objValue.length); let index = -1; const length = objValue.length; for (; ++index < length;) newValue[index] = objValue[index]; } } else isPlainObject$3(srcValue) ? (newValue = null != objValue ? objValue : {}, "function" != typeof objValue && "object" == typeof objValue || (newValue = {})) : isCommon = !1; isCommon && baseMerge$1(newValue, srcValue, shallowArray, skipTargetArray), assignMergeValue$1(target, key, newValue); } function assignMergeValue$1(target, key, value) { (void 0 !== value && !eq$1(target[key], value) || void 0 === value && !(key in target)) && (target[key] = value); } function eq$1(value, other) { return value === other || Number.isNaN(value) && Number.isNaN(other); } function merge$1(target, ...sources) { let sourceIndex = -1; const length = sources.length; for (; ++sourceIndex < length;) { baseMerge$1(target, sources[sourceIndex], !0); } return target; } function pickWithout(obj, keys) { if (!obj || !isPlainObject$3(obj)) return obj; const result = {}; return Object.keys(obj).forEach(k => { const v = obj[k]; let match = !1; keys.forEach(itKey => { (isString$3(itKey) && itKey === k || itKey instanceof RegExp && k.match(itKey)) && (match = !0); }), match || (result[k] = v); }), result; } function objToString(obj) { return Object.prototype.toString.call(obj); } function objectKeys(obj) { return Object.keys(obj); } function isEqual(a, b, options) { if (a === b) return !0; if (typeof a != typeof b) return !1; if (null == a || null == b) return !1; if (Number.isNaN(a) && Number.isNaN(b)) return !0; if (objToString(a) !== objToString(b)) return !1; if (isFunction$3(a)) return !!(null == options ? void 0 : options.skipFunction); if ("object" != typeof a) return !1; if (isArray$3(a)) { if (a.length !== b.length) return !1; for (let i = a.length - 1; i >= 0; i--) if (!isEqual(a[i], b[i], options)) return !1; return !0; } if (!isPlainObject$3(a)) return !1; const ka = objectKeys(a), kb = objectKeys(b); if (ka.length !== kb.length) return !1; ka.sort(), kb.sort(); for (let i = ka.length - 1; i >= 0; i--) if (ka[i] != kb[i]) return !1; for (let i = ka.length - 1; i >= 0; i--) { const key = ka[i]; if (!isEqual(a[key], b[key], options)) return !1; } return !0; } const calculateAnchorOfBounds$1 = (bounds, anchorType) => { const { x1: x1, x2: x2, y1: y1, y2: y2 } = bounds, rectWidth = Math.abs(x2 - x1), rectHeight = Math.abs(y2 - y1); let anchorX = (x1 + x2) / 2, anchorY = (y1 + y2) / 2, sx = 0, sy = 0; switch (anchorType) { case "top": case "inside-top": sy = -.5; break; case "bottom": case "inside-bottom": sy = .5; break; case "left": case "inside-left": sx = -.5; break; case "right": case "inside-right": sx = .5; break; case "top-right": sx = .5, sy = -.5; break; case "top-left": sx = -.5, sy = -.5; break; case "bottom-right": sx = .5, sy = .5; break; case "bottom-left": sx = -.5, sy = .5; } return anchorX += sx * rectWidth, anchorY += sy * rectHeight, { x: anchorX, y: anchorY }; }; const styleStringToObject$1 = (styleStr = "") => { const res = {}; return styleStr.split(";").forEach(item => { if (item) { const arr = item.split(":"); if (2 === arr.length) { const key = arr[0].trim(), value = arr[1].trim(); key && value && (res[key] = value); } } }), res; }; var reactIs = {exports: {}}; var reactIs_production_min = {}; /** * @license React * react-is.production.min.js * * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ var hasRequiredReactIs_production_min; function requireReactIs_production_min() { if (hasRequiredReactIs_production_min) return reactIs_production_min; hasRequiredReactIs_production_min = 1; var b = Symbol.for("react.element"), c = Symbol.for("react.portal"), d = Symbol.for("react.fragment"), e = Symbol.for("react.strict_mode"), f = Symbol.for("react.profiler"), g = Symbol.for("react.provider"), h = Symbol.for("react.context"), k = Symbol.for("react.server_context"), l = Symbol.for("react.forward_ref"), m = Symbol.for("react.suspense"), n = Symbol.for("react.suspense_list"), p = Symbol.for("react.memo"), q = Symbol.for("react.lazy"), t = Symbol.for("react.offscreen"), u; u = Symbol.for("react.module.reference"); function v(a) { if ("object" === typeof a && null !== a) { var r = a.$$typeof; switch (r) { case b: switch (a = a.type, a) { case d: case f: case e: case m: case n: return a; default: switch (a = a && a.$$typeof, a) { case k: case h: case l: case q: case p: case g: return a; default: return r; } } case c: return r; } } } reactIs_production_min.ContextConsumer = h; reactIs_production_min.ContextProvider = g; reactIs_production_min.Element = b; reactIs_production_min.ForwardRef = l; reactIs_production_min.Fragment = d; reactIs_production_min.Lazy = q; reactIs_production_min.Memo = p; reactIs_production_min.Portal = c; reactIs_production_min.Profiler = f; reactIs_production_min.StrictMode = e; reactIs_production_min.Suspense = m; reactIs_production_min.SuspenseList = n; reactIs_production_min.isAsyncMode = function () { return !1; }; reactIs_production_min.isConcurrentMode = function () { return !1; }; reactIs_production_min.isContextConsumer = function (a) { return v(a) === h; }; reactIs_production_min.isContextProvider = function (a) { return v(a) === g; }; reactIs_production_min.isElement = function (a) { return "object" === typeof a && null !== a && a.$$typeof === b; }; reactIs_production_min.isForwardRef = function (a) { return v(a) === l; }; reactIs_production_min.isFragment = function (a) { return v(a) === d; }; reactIs_production_min.isLazy = function (a) { return v(a) === q; }; reactIs_production_min.isMemo = function (a) { return v(a) === p; }; reactIs_production_min.isPortal = function (a) { return v(a) === c; }; reactIs_production_min.isProfiler = function (a) { return v(a) === f; }; reactIs_production_min.isStrictMode = function (a) { return v(a) === e; }; reactIs_production_min.isSuspense = function (a) { return v(a) === m; }; reactIs_production_min.isSuspenseList = function (a) { return v(a) === n; }; reactIs_production_min.isValidElementType = function (a) { return "string" === typeof a || "function" === typeof a || a === d || a === f || a === e || a === m || a === n || a === t || "object" === typeof a && null !== a && (a.$$typeof === q || a.$$typeof === p || a.$$typeof === g || a.$$typeof === h || a.$$typeof === l || a.$$typeof === u || void 0 !== a.getModuleId) ? !0 : !1; }; reactIs_production_min.typeOf = v; return reactIs_production_min; } { reactIs.exports = requireReactIs_production_min(); } var reactIsExports = reactIs.exports; const toArray = (children) => { let result = []; React.Children.forEach(children, child => { if (isNil$3(child)) { return; } if (reactIsExports.isFragment(child)) { result = result.concat(toArray(child.props.children)); } else { result.push(child); } }); return result; }; const REACT_PRIVATE_PROPS = ['children', 'hooks', 'ref']; const EVENT_TYPE = { ...vtable.TABLE_EVENT_TYPE, ...vtable.PIVOT_TABLE_EVENT_TYPE, ...vtable.PIVOT_CHART_EVENT_TYPE }; const TABLE_EVENTS = { onClickCell: EVENT_TYPE.CLICK_CELL, onDblClickCell: EVENT_TYPE.DBLCLICK_CELL, onMouseDownCell: EVENT_TYPE.MOUSEDOWN_CELL, onMouseUpCell: EVENT_TYPE.MOUSEUP_CELL, onSelectedCell: EVENT_TYPE.SELECTED_CELL, onSelectedClear: EVENT_TYPE.SELECTED_CLEAR, onKeyDown: EVENT_TYPE.KEYDOWN, onMouseEnterTable: EVENT_TYPE.MOUSEENTER_TABLE, onMouseLeaveTable: EVENT_TYPE.MOUSELEAVE_TABLE, onMouseDownTable: EVENT_TYPE.MOUSEDOWN_TABLE, onMouseMoveCell: EVENT_TYPE.MOUSEMOVE_CELL, onMouseMoveTable: EVENT_TYPE.MOUSEMOVE_TABLE, onMouseEnterCell: EVENT_TYPE.MOUSEENTER_CELL, onMouseLeaveCell: EVENT_TYPE.MOUSELEAVE_CELL, onContextMenuCell: EVENT_TYPE.CONTEXTMENU_CELL, onResizeColumn: EVENT_TYPE.RESIZE_COLUMN, onResizeColumnEnd: EVENT_TYPE.RESIZE_COLUMN_END, onResizeRow: EVENT_TYPE.RESIZE_ROW, onResizeRowEnd: EVENT_TYPE.RESIZE_ROW_END, onChangeHeaderPositionStart: EVENT_TYPE.CHANGE_HEADER_POSITION_START, onChangeHeaderPosition: EVENT_TYPE.CHANGE_HEADER_POSITION, onChangeHeaderPositionFail: EVENT_TYPE.CHANGE_HEADER_POSITION_FAIL, onSortClick: EVENT_TYPE.SORT_CLICK, onAfterSort: EVENT_TYPE.AFTER_SORT, onFreezeClick: EVENT_TYPE.FREEZE_CLICK, onScroll: EVENT_TYPE.SCROLL, onScrollHorizontalEnd: EVENT_TYPE.SCROLL_HORIZONTAL_END, onScrollVerticalEnd: EVENT_TYPE.SCROLL_VERTICAL_END, onDropdownMenuClick: EVENT_TYPE.DROPDOWN_MENU_CLICK, onMouseOverChartSymbol: EVENT_TYPE.MOUSEOVER_CHART_SYMBOL, onDragSelectEnd: EVENT_TYPE.DRAG_SELECT_END, onCopyData: EVENT_TYPE.COPY_DATA, onDropdownIconClick: EVENT_TYPE.DROPDOWN_ICON_CLICK, onDropdownMenuClear: EVENT_TYPE.DROPDOWN_MENU_CLEAR, onTreeHierarchyStateChange: EVENT_TYPE.TREE_HIERARCHY_STATE_CHANGE, onShowMenu: EVENT_TYPE.SHOW_MENU, onHideMenu: EVENT_TYPE.HIDE_MENU, onIconClick: EVENT_TYPE.ICON_CLICK, onLegendItemClick: EVENT_TYPE.LEGEND_ITEM_CLICK, onLegendItemHover: EVENT_TYPE.LEGEND_ITEM_HOVER, onLegendItemUnHover: EVENT_TYPE.LEGEND_ITEM_UNHOVER, onLegendChange: EVENT_TYPE.LEGEND_CHANGE, onMouseEnterAxis: EVENT_TYPE.MOUSEENTER_AXIS, onMouseLeaveAxis: EVENT_TYPE.MOUSELEAVE_AXIS, onCheckboxStateChange: EVENT_TYPE.CHECKBOX_STATE_CHANGE, onRadioStateChange: EVENT_TYPE.RADIO_STATE_CHANGE, onSwitchStateChange: EVENT_TYPE.SWITCH_STATE_CHANGE, onAfterRender: EVENT_TYPE.AFTER_RENDER, onInitialized: EVENT_TYPE.INITIALIZED, onChangeCellValue: EVENT_TYPE.CHANGE_CELL_VALUE, onDragFillHandleEnd: EVENT_TYPE.DRAG_FILL_HANDLE_END, onMousedownFillHandle: EVENT_TYPE.MOUSEDOWN_FILL_HANDLE, onDblclickFillHandle: EVENT_TYPE.DBLCLICK_FILL_HANDLE, onPivotSortClick: EVENT_TYPE.PIVOT_SORT_CLICK, onDrillMenuClick: EVENT_TYPE.DRILLMENU_CLICK, onVChartEventType: EVENT_TYPE.VCHART_EVENT_TYPE, onChangCellValue: EVENT_TYPE.CHANGE_CELL_VALUE, onEmptyTipClick: EVENT_TYPE.EMPTY_TIP_CLICK, onEmptyTipDblClick: EVENT_TYPE.EMPTY_TIP_DBLCLICK, onButtonClick: EVENT_TYPE.BUTTON_CLICK, onBeforeCacheChartImage: EVENT_TYPE.BEFORE_CACHE_CHART_IMAGE, onPastedData: EVENT_TYPE.PASTED_DATA }; const TABLE_EVENTS_KEYS = Object.keys(TABLE_EVENTS); const findEventProps = (props, supportedEvents = TABLE_EVENTS) => { const result = {}; Object.keys(props).forEach(key => { if (supportedEvents[key] && props[key]) { result[key] = props[key]; } }); return result; }; const bindEventsToTable = (table, newProps, prevProps, supportedEvents = TABLE_EVENTS) => { if ((!newProps && !prevProps) || !table) { return false; } const prevEventProps = prevProps ? findEventProps(prevProps, supportedEvents) : null; const newEventProps = newProps ? findEventProps(newProps, supportedEvents) : null; if (prevEventProps) { Object.keys(prevEventProps).forEach(eventKey => { if (!newEventProps || !newEventProps[eventKey] || newEventProps[eventKey] !== prevEventProps[eventKey]) { table.off(supportedEvents[eventKey], prevProps[eventKey]); } }); } if (newEventProps) { Object.keys(newEventProps).forEach(eventKey => { if (!prevEventProps || !prevEventProps[eventKey] || prevEventProps[eventKey] !== newEventProps[eventKey]) { table.on(supportedEvents[eventKey], newEventProps[eventKey]); } }); } return true; }; class Generator { static GenAutoIncrementId() { return Generator.auto_increment_id++; } } Generator.auto_increment_id = 0; class ContainerModule { constructor(registry) { this.id = Generator.GenAutoIncrementId(), this.registry = registry; } } const NAMED_TAG = "named"; const INJECT_TAG = "inject"; const MULTI_INJECT_TAG = "multi_inject"; const TAGGED = "inversify:tagged"; const PARAM_TYPES = "inversify:paramtypes"; class Metadata { constructor(key, value) { this.key = key, this.value = value; } toString() { return this.key === NAMED_TAG ? `named: ${String(this.value).toString()} ` : `tagged: { key:${this.key.toString()}, value: ${String(this.value)} }`; } } var Reflect$1 = (function (Reflect) { var target; return function (exporter) { const supportsSymbol = "function" == typeof Symbol, toPrimitiveSymbol = supportsSymbol && void 0 !== Symbol.toPrimitive ? Symbol.toPrimitive : "@@toPrimitive", functionPrototype = (Object.getPrototypeOf(Function)), _Map = ("object" == typeof process && process.env && process.env.REFLECT_METADATA_USE_MAP_POLYFILL, Map), Metadata = (new WeakMap()); function defineMetadata(metadataKey, metadataValue, target, propertyKey) { if (!IsObject(target)) throw new TypeError(); return OrdinaryDefineOwnMetadata(metadataKey, metadataValue, target, propertyKey); } function hasMetadata(metadataKey, target, propertyKey) { if (!IsObject(target)) throw new TypeError(); return IsUndefined(propertyKey) || (propertyKey = ToPropertyKey(propertyKey)), OrdinaryHasMetadata(metadataKey, target, propertyKey); } function hasOwnMetadata(metadataKey, target, propertyKey) { if (!IsObject(target)) throw new TypeError(); return IsUndefined(propertyKey) || (propertyKey = ToPropertyKey(propertyKey)), OrdinaryHasOwnMetadata(metadataKey, target, propertyKey); } function getMetadata(metadataKey, target, propertyKey) { if (!IsObject(target)) throw new TypeError(); return IsUndefined(propertyKey) || (propertyKey = ToPropertyKey(propertyKey)), OrdinaryGetMetadata(metadataKey, target, propertyKey); } function GetOrCreateMetadataMap(O, P, Create) { let targetMetadata = Metadata.get(O); if (IsUndefined(targetMetadata)) { if (!Create) return; targetMetadata = new _Map(), Metadata.set(O, targetMetadata); } let metadataMap = targetMetadata.get(P); if (IsUndefined(metadataMap)) { if (!Create) return; metadataMap = new _Map(), targetMetadata.set(P, metadataMap); } return metadataMap; } function OrdinaryHasMetadata(MetadataKey, O, P) { if (OrdinaryHasOwnMetadata(MetadataKey, O, P)) return !0; const parent = OrdinaryGetPrototypeOf(O); return !IsNull(parent) && OrdinaryHasMetadata(MetadataKey, parent, P); } function OrdinaryHasOwnMetadata(MetadataKey, O, P) { const metadataMap = GetOrCreateMetadataMap(O, P, !1); return !IsUndefined(metadataMap) && ToBoolean(metadataMap.has(MetadataKey)); } function OrdinaryGetMetadata(MetadataKey, O, P) { if (OrdinaryHasOwnMetadata(MetadataKey, O, P)) return OrdinaryGetOwnMetadata(MetadataKey, O, P); const parent = OrdinaryGetPrototypeOf(O); return IsNull(parent) ? void 0 : OrdinaryGetMetadata(MetadataKey, parent, P); } function OrdinaryGetOwnMetadata(MetadataKey, O, P) { const metadataMap = GetOrCreateMetadataMap(O, P, !1); if (!IsUndefined(metadataMap)) return metadataMap.get(MetadataKey); } function OrdinaryDefineOwnMetadata(MetadataKey, MetadataValue, O, P) { GetOrCreateMetadataMap(O, P, !0).set(MetadataKey, MetadataValue); } function Type(x) { if (null === x) return 1; switch (typeof x) { case "undefined": return 0; case "boolean": return 2; case "string": return 3; case "symbol": return 4; case "number": return 5; case "object": return null === x ? 1 : 6; default: return 6; } } function IsUndefined(x) { return void 0 === x; } function IsNull(x) { return null === x; } function IsSymbol(x) { return "symbol" == typeof x; } function IsObject(x) { return "object" == typeof x ? null !== x : "function" == typeof x; } function ToPrimitive(input, PreferredType) { switch (Type(input)) { case 0: case 1: case 2: case 3: case 4: case 5: return input; } const hint = 3 === PreferredType ? "string" : 5 === PreferredType ? "number" : "default", exoticToPrim = GetMethod(input, toPrimitiveSymbol); if (void 0 !== exoticToPrim) { const result = exoticToPrim.call(input, hint); if (IsObject(result)) throw new TypeError(); return result; } return OrdinaryToPrimitive(input, "default" === hint ? "number" : hint); } function OrdinaryToPrimitive(O, hint) { if ("string" === hint) { const toString_1 = O.toString; if (IsCallable(toString_1)) { const result = toString_1.call(O); if (!IsObject(result)) return result; } const valueOf = O.valueOf; if (IsCallable(valueOf)) { const result = valueOf.call(O); if (!IsObject(result)) return result; } } else { const valueOf = O.valueOf; if (IsCallable(valueOf)) { const result = valueOf.call(O); if (!IsObject(result)) return result; } const toString_2 = O.toString; if (IsCallable(toString_2)) { const result = toString_2.call(O); if (!IsObject(result)) return result; } } throw new TypeError(); } function ToBoolean(argument) { return !!argument; } function ToString(argument) { return "" + argument; } function ToPropertyKey(argument) { const key = ToPrimitive(argument, 3); return IsSymbol(key) ? key : ToString(key); } function IsCallable(argument) { return "function" == typeof argument; } function GetMethod(V, P) { const func = V[P]; if (null != func) { if (!IsCallable(func)) throw new TypeError(); return func; } } function OrdinaryGetPrototypeOf(O) { const proto = Object.getPrototypeOf(O); if ("function" != typeof O || O === functionPrototype) return proto; if (proto !== functionPrototype) return proto; const prototype = O.prototype, prototypeProto = prototype && Object.getPrototypeOf(prototype); if (null == prototypeProto || prototypeProto === Object.prototype) return proto; const constructor = prototypeProto.constructor; return "function" != typeof constructor || constructor === O ? proto : constructor; } exporter("defineMetadata", defineMetadata), exporter("hasMetadata", hasMetadata), exporter("hasOwnMetadata", hasOwnMetadata), exporter("getMetadata", getMetadata); }((target = Reflect, function (key, value) { "function" != typeof target[key] && Object.defineProperty(target, key, { configurable: !0, writable: !0, value: value }); })), Reflect; })({}); function _tagParameterOrProperty(metadataKey, annotationTarget, key, metadata) { const metadatas = [metadata]; let paramsOrPropertiesMetadata = {}; Reflect$1.hasOwnMetadata(metadataKey, annotationTarget) && (paramsOrPropertiesMetadata = Reflect$1.getMetadata(metadataKey, annotationTarget)); let paramOrPropertyMetadata = paramsOrPropertiesMetadata[key]; void 0 === paramOrPropertyMetadata && (paramOrPropertyMetadata = []), paramOrPropertyMetadata.push(...metadatas), paramsOrPropertiesMetadata[key] = paramOrPropertyMetadata, Reflect$1.defineMetadata(metadataKey, paramsOrPropertiesMetadata, annotationTarget); } function tagParameter(annotationTarget, parameterName, parameterIndex, metadata) { _tagParameterOrProperty(TAGGED, annotationTarget, parameterIndex.toString(), metadata); } function createTaggedDecorator(metadata) { return (target, targetKey, indexOrPropertyDescriptor) => { tagParameter(target, targetKey, indexOrPropertyDescriptor, metadata); }; } function injectBase(metadataKey) { return serviceIdentifier => (target, targetKey, indexOrPropertyDescriptor) => createTaggedDecorator(new Metadata(metadataKey, serviceIdentifier))(target, targetKey, indexOrPropertyDescriptor); } const inject = injectBase(INJECT_TAG); function injectable() { return function (target) { return Reflect$1.defineMetadata(PARAM_TYPES, null, target), target; }; } function named(name) { return createTaggedDecorator(new Metadata(NAMED_TAG, name)); } const BindingScopeEnum = { Singleton: "Singleton", Transient: "Transient" }, BindingTypeEnum = { ConstantValue: "ConstantValue", Constructor: "Constructor", DynamicValue: "DynamicValue", Factory: "Factory", Function: "Function", Instance: "Instance", Invalid: "Invalid", Provider: "Provider" }; class Binding { constructor(serviceIdentifier, scope) { this.id = Generator.GenAutoIncrementId(), this.activated = !1, this.serviceIdentifier = serviceIdentifier, this.scope = scope, this.type = BindingTypeEnum.Invalid, this.constraint = request => !0, this.implementationType = null, this.cache = null, this.factory = null, this.provider = null, this.dynamicValue = null; } clone() { const clone = new Binding(this.serviceIdentifier, this.scope); return clone.activated = clone.scope === BindingScopeEnum.Singleton && this.activated, clone.implementationType = this.implementationType, clone.dynamicValue = this.dynamicValue, clone.scope = this.scope, clone.type = this.type, clone.provider = this.provider, clone.constraint = this.constraint, clone.cache = this.cache, clone; } } class MetadataReader { getConstructorMetadata(constructorFunc) { return { compilerGeneratedMetadata: Reflect$1.getMetadata(PARAM_TYPES, constructorFunc), userGeneratedMetadata: Reflect$1.getMetadata(TAGGED, constructorFunc) || {} }; } getPropertiesMetadata(constructorFunc) { throw new Error("暂未实现"); } } const taggedConstraint = key => value => { const constraint = request => { if (null == request) return !1; if (request.key === key && request.value === value) return !0; if (null == request.constructorArgsMetadata) return !1; const constructorArgsMetadata = request.constructorArgsMetadata; for (let i = 0; i < constructorArgsMetadata.length; i++) if (constructorArgsMetadata[i].key === key && constructorArgsMetadata[i].value === value) return !0; return !1; }; return constraint.metaData = new Metadata(key, value), constraint; }; const namedConstraint = taggedConstraint(NAMED_TAG); class BindingInSyntax { constructor(binding) { this._binding = binding; } inRequestScope() { throw new Error("暂未实现"); } inSingletonScope() { return this._binding.scope = BindingScopeEnum.Singleton, this; } inTransientScope() { return this._binding.scope = BindingScopeEnum.Transient, this; } whenTargetNamed(name) { return this._binding.constraint = namedConstraint(name), this; } } class BindingToSyntax { constructor(binding) { this._binding = binding; } to(constructor) { return this._binding.type = BindingTypeEnum.Instance, this._binding.implementationType = constructor, new BindingInSyntax(this._binding); } toSelf() { const self = this._binding.serviceIdentifier; return this.to(self); } toDynamicValue(func) { return this._binding.type = BindingTypeEnum.DynamicValue, this._binding.cache = null, this._binding.dynamicValue = func, this._binding.implementationType = null, new BindingInSyntax(this._binding); } toConstantValue(value) { return this._binding.type = BindingTypeEnum.ConstantValue, this._binding.cache = value, this._binding.dynamicValue = null, this._binding.implementationType = null, this._binding.scope = BindingScopeEnum.Singleton, new BindingInSyntax(this._binding); } toFactory(factory) { return this._binding.type = BindingTypeEnum.Factory, this._binding.factory = factory, this._binding.scope = BindingScopeEnum.Singleton, new BindingInSyntax(this._binding); } toService(service) { this.toDynamicValue(context => context.container.get(service)); } } class Container { constructor(containerOptions) { const options = containerOptions || {}; options.defaultScope = options.defaultScope || BindingScopeEnum.Transient, this.options = options, this.id = Generator.GenAutoIncrementId(), this._bindingDictionary = new Map(), this._metadataReader = new MetadataReader(); } load(module) { const containerModuleHelpers = this._getContainerModuleHelpersFactory()(module.id); module.registry(containerModuleHelpers.bindFunction, containerModuleHelpers.unbindFunction, containerModuleHelpers.isboundFunction, containerModuleHelpers.rebindFunction); } get(serviceIdentifier) { const getArgs = this._getNotAllArgs(serviceIdentifier, !1); return this._get(getArgs); } getAll(serviceIdentifier) { const getArgs = this._getAllArgs(serviceIdentifier); return this._get(getArgs); } getTagged(serviceIdentifier, key, value) { const getArgs = this._getNotAllArgs(serviceIdentifier, !1, key, value); return this._get(getArgs); } getNamed(serviceIdentifier, named) { return this.getTagged(serviceIdentifier, NAMED_TAG, named); } isBound(serviceIdentifier) { return this._bindingDictionary.has(serviceIdentifier); } bind(serviceIdentifier) { const scope = this.options.defaultScope, binding = new Binding(serviceIdentifier, scope), list = this._bindingDictionary.get(serviceIdentifier) || []; return list.push(binding), this._bindingDictionary.set(serviceIdentifier, list), new BindingToSyntax(binding); } unbind(serviceIdentifier) { this._bindingDictionary.delete(serviceIdentifier); } rebind(serviceIdentifier) { return this.unbind(serviceIdentifier), this.bind(serviceIdentifier); } _getContainerModuleHelpersFactory() { const setModuleId = (bindingToSyntax, moduleId) => { bindingToSyntax._binding.moduleId = moduleId; }, getBindFunction = moduleId => serviceIdentifier => { const bindingToSyntax = this.bind(serviceIdentifier); return setModuleId(bindingToSyntax, moduleId), bindingToSyntax; }, getUnbindFunction = () => serviceIdentifier => this.unbind(serviceIdentifier), getIsboundFunction = () => serviceIdentifier => this.isBound(serviceIdentifier), getRebindFunction = moduleId => serviceIdentifier => { const bindingToSyntax = this.rebind(serviceIdentifier); return setModuleId(bindingToSyntax, moduleId), bindingToSyntax; }; return mId => ({ bindFunction: getBindFunction(mId), isboundFunction: getIsboundFunction(), rebindFunction: getRebindFunction(mId), unbindFunction: getUnbindFunction(), unbindAsyncFunction: serviceIdentifier => null }); } _getNotAllArgs(serviceIdentifier, isMultiInject, key, value) { return { avoidConstraints: !1, isMultiInject: isMultiInject, serviceIdentifier: serviceIdentifier, key: key, value: value }; } _getAllArgs(serviceIdentifier) { return { avoidConstraints: !0, isMultiInject: !0, serviceIdentifier: serviceIdentifier }; } _get(getArgs) { const result = []; return this._bindingDictionary.get(getArgs.serviceIdentifier).filter(b => b.constraint(getArgs)).forEach(binding => { result.push(this._resolveFromBinding(binding)); }), getArgs.isMultiInject || 1 !== result.length ? result : result[0]; } _getChildRequest(binding) { const constr = binding.implementationType, { userGeneratedMetadata: userGeneratedMetadata } = this._metadataReader.getConstructorMetadata(constr), keys = Object.keys(userGeneratedMetadata), arr = []; for (let i = 0; i < keys.length; i++) { const constructorArgsMetadata = userGeneratedMetadata[i], targetMetadataMap = {}; constructorArgsMetadata.forEach(md => { targetMetadataMap[md.key] = md.value; }); const metadata = { inject: targetMetadataMap[INJECT_TAG], multiInject: targetMetadataMap[MULTI_INJECT_TAG] }, injectIdentifier = metadata.inject || metadata.multiInject, target = { serviceIdentifier: injectIdentifier, constructorArgsMetadata: constructorArgsMetadata }, bindings = (this._bindingDictionary.get(injectIdentifier) || []).filter(b => b.constraint(target)); if (bindings.length) { const request = { injectIdentifier: injectIdentifier, metadata: constructorArgsMetadata, bindings: bindings }; arr.push(request); } } return arr; } _resolveFromBinding(binding) { const result = this._getResolvedFromBinding(binding); return this._saveToScope(binding, result), result; } _getResolvedFromBinding(binding) { let result; switch (binding.type) { case BindingTypeEnum.ConstantValue: case BindingTypeEnum.Function: result = binding.cache; break; case BindingTypeEnum.Instance: result = this._resolveInstance(binding, binding.implementationType); break; default: result = binding.dynamicValue({ container: this }); } return result; } _resolveInstance(binding, constr) { if (binding.activated) return binding.cache; const childRequests = this._getChildRequest(binding); return this._createInstance(constr, childRequests); } _createInstance(constr, childRequests) { if (childRequests.length) { return new constr(...this._resolveRequests(childRequests)); } return new constr(); } _resolveRequests(childRequests) { return childRequests.map(request => requ