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,GAAW,CAAC,UAAU,CAAC,GAAG;YAAS,cAAc;iBAAd,UAAc,EAAd,qBAAc,EAAd,IAAc;gBAAd,yBAAc;;YAChD,sDAAsD;YACtD,IAAI,MAAM,CAAC;YAEX,IAAI,eAAe,EAAE;gBACnB,MAAM,GAAG,eAAe,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;aAC5C;YACD,IAAI,WAAW,KAAK,eAAe,EAAE;gBACnC,MAAM,GAAG,WAAW,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;aACxC;YAED,OAAO,MAAM,CAAC;QAChB,CAAC,CAAC;KACH;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,UAAU;IACxB,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import * as React from 'react';\nimport { Async } from './Async';\nimport { EventGroup } from './EventGroup';\nimport { IDisposable } from './IDisposable';\nimport { ISettingsMap } from './warn/warn';\nimport { warnConditionallyRequiredProps } from './warn/warnConditionallyRequiredProps';\nimport { warnMutuallyExclusive } from './warn/warnMutuallyExclusive';\nimport { warnDeprecations } from './warn/warnDeprecations';\nimport { IRefObject } from './createRef';\nimport { IBaseProps } from './BaseComponent.types';\n\n/**\n * BaseComponent class, which provides basic helpers for all components.\n *\n * @public\n * {@docCategory BaseComponent}\n *\n * @deprecated Do not use. We are moving away from class component.\n */\nexport class BaseComponent<TProps extends IBaseProps = {}, TState = {}> extends React.Component<TProps, TState> {\n  /**\n   * @deprecated Use React's error boundaries instead.\n   */\n  // eslint-disable-next-line @typescript-eslint/no-explicit-any\n  public static onError: (errorMessage?: string, ex?: any) => void;\n\n  /**\n   * Controls whether the componentRef prop will be resolved by this component instance. If you are\n   * implementing a passthrough (higher-order component), you would set this to false and pass through\n   * the props to the inner component, allowing it to resolve the componentRef.\n   */\n  protected _skipComponentRefResolution: boolean;\n\n  private __async: Async;\n  private __events: EventGroup;\n  private __disposables: IDisposable[] | null;\n  private __resolves: { [name: string]: (ref: React.ReactNode) => React.ReactNode };\n  private __className: string;\n\n  /**\n   * BaseComponent constructor\n   * @param props - The props for the component.\n   * @param context - The context for the component.\n   */\n  // eslint-disable-next-line @typescript-eslint/no-explicit-any\n  constructor(props: TProps, context?: any) {\n    super(props, context);\n\n    // eslint-disable-next-line deprecation/deprecation\n    _makeAllSafe(this, BaseComponent.prototype, [\n      'componentDidMount',\n      'shouldComponentUpdate',\n      'getSnapshotBeforeUpdate',\n      'render',\n      'componentDidUpdate',\n      'componentWillUnmount',\n    ]);\n  }\n\n  /**\n   * When the component receives props, make sure the componentRef is updated.\n   */\n  public componentDidUpdate(prevProps: TProps, prevState: TState): void {\n    this._updateComponentRef(prevProps, this.props);\n  }\n\n  /**\n   * When the component has mounted, update the componentRef.\n   */\n  public componentDidMount(): void {\n    this._setComponentRef(this.props.componentRef, this);\n  }\n\n  /**\n   * If we have disposables, dispose them automatically on unmount.\n   */\n  public componentWillUnmount(): void {\n    this._setComponentRef(this.props.componentRef, null);\n\n    if (this.__disposables) {\n      for (let i = 0, len = this._disposables.length; i < len; i++) {\n        let disposable = this.__disposables[i];\n\n        if (disposable.dispose) {\n          disposable.dispose();\n        }\n      }\n      this.__disposables = null;\n    }\n  }\n\n  /**\n   * Gets the object's class name.\n   */\n  public get className(): string {\n    if (!this.__className) {\n      let funcNameRegex = /function (.{1,})\\(/;\n      let results = funcNameRegex.exec(this.constructor.toString());\n\n      this.__className = results && results.length > 1 ? results[1] : '';\n    }\n\n    return this.__className;\n  }\n\n  /**\n   * Allows subclasses to push things to this._disposables to be auto disposed.\n   */\n  protected get _disposables(): IDisposable[] {\n    if (!this.__disposables) {\n      this.__disposables = [];\n    }\n    return this.__disposables;\n  }\n\n  /**\n   * Gets the async instance associated with the component, created on demand. The async instance gives\n   * subclasses a way to execute setTimeout/setInterval async calls safely, where the callbacks\n   * will be cleared/ignored automatically after unmounting. The helpers within the async object also\n   * preserve the this pointer so that you don't need to \"bind\" the callbacks.\n   */\n  protected get _async(): Async {\n    if (!this.__async) {\n      this.__async = new Async(this);\n      this._disposables.push(this.__async);\n    }\n\n    return this.__async;\n  }\n\n  /**\n   * Gets the event group instance assocaited with the component, created on demand. The event instance\n   * provides on/off methods for listening to DOM (or regular javascript object) events. The event callbacks\n   * will be automatically disconnected after unmounting. The helpers within the events object also\n   * preserve the this reference so that you don't need to \"bind\" the callbacks.\n   */\n  protected get _events(): EventGroup {\n    if (!this.__events) {\n      this.__events = new EventGroup(this);\n      this._disposables.push(this.__events);\n    }\n\n    return this.__events;\n  }\n\n  /**\n   * Helper to return a memoized ref resolver function.\n   * @param refName - Name of the member to assign the ref to.\n   * @returns A function instance keyed from the given refname.\n   * @deprecated Use `createRef` from React.createRef.\n   */\n  protected _resolveRef(refName: string): (ref: React.ReactNode) => React.ReactNode {\n    if (!this.__resolves) {\n      this.__resolves = {};\n    }\n\n    if (!this.__resolves[refName]) {\n      this.__resolves[refName] = (ref: React.ReactNode) => {\n        // eslint-disable-next-line @typescript-eslint/no-explicit-any\n        return ((this as any)[refName] = ref);\n      };\n    }\n\n    return this.__resolves[refName];\n  }\n\n  /**\n   * Updates the componentRef (by calling it with \"this\" when necessary.)\n   */\n  protected _updateComponentRef(currentProps: IBaseProps, newProps: IBaseProps = {}): void {\n    // currentProps *should* always be defined, but verify that just in case a subclass is manually\n    // calling a lifecycle method with no parameters (which has happened) or other odd usage.\n    if (currentProps && newProps && currentProps.componentRef !== newProps.componentRef) {\n      this._setComponentRef(currentProps.componentRef, null);\n      this._setComponentRef(newProps.componentRef, this);\n    }\n  }\n\n  /**\n   * Warns when a deprecated props are being used.\n   *\n   * @param deprecationMap - The map of deprecations, where key is the prop name and the value is\n   * either null or a replacement prop name.\n   */\n  protected _warnDeprecations(deprecationMap: ISettingsMap<TProps>): void {\n    warnDeprecations(this.className, this.props, deprecationMap);\n  }\n\n  /**\n   * Warns when props which are mutually exclusive with each other are both used.\n   *\n   * @param mutuallyExclusiveMap - The map of mutually exclusive props.\n   */\n  protected _warnMutuallyExclusive(mutuallyExclusiveMap: ISettingsMap<TProps>): void {\n    warnMutuallyExclusive(this.className, this.props, mutuallyExclusiveMap);\n  }\n\n  /**\n   * Warns when props are required if a condition is met.\n   *\n   * @param requiredProps - The name of the props that are required when the condition is met.\n   * @param conditionalPropName - The name of the prop that the condition is based on.\n   * @param condition - Whether the condition is met.\n   */\n  protected _warnConditionallyRequiredProps(\n    requiredProps: string[],\n    conditionalPropName: string,\n    condition: boolean,\n  ): void {\n    warnConditionallyRequiredProps(this.className, this.props, requiredProps, conditionalPropName, condition);\n  }\n\n  private _setComponentRef<TRefInterface>(\n    ref: IRefObject<TRefInterface> | undefined,\n    value: TRefInterface | null,\n  ): void {\n    if (!this._skipComponentRefResolution && ref) {\n      if (typeof ref === 'function') {\n        ref(value);\n      }\n\n      if (typeof ref === 'object') {\n        // eslint-disable-next-line @typescript-eslint/no-explicit-any\n        (ref as any).current = value;\n      }\n    }\n  }\n}\n\n/**\n * Helper to override a given method with a wrapper method that can try/catch the original, but also\n * ensures that the BaseComponent's methods are called before the subclass's. This ensures that\n * componentWillUnmount in the base is called and that things in the _disposables array are disposed.\n */\n// eslint-disable-next-line deprecation/deprecation\nfunction _makeAllSafe(obj: BaseComponent<{}, {}>, prototype: Object, methodNames: string[]): void {\n  for (let i = 0, len = methodNames.length; i < len; i++) {\n    _makeSafe(obj, prototype, methodNames[i]);\n  }\n}\n\n// eslint-disable-next-line deprecation/deprecation\nfunction _makeSafe(obj: BaseComponent<{}, {}>, prototype: Object, methodName: string): void {\n  /* eslint-disable @typescript-eslint/no-explicit-any */\n  let classMethod = (obj as any)[methodName];\n  let prototypeMethod = (prototype as any)[methodName];\n\n  if (classMethod || prototypeMethod) {\n    (obj as any)[methodName] = function(...args: any[]): any {\n      /* eslint-enable @typescript-eslint/no-explicit-any */\n      let retVal;\n\n      if (prototypeMethod) {\n        retVal = prototypeMethod.apply(this, args);\n      }\n      if (classMethod !== prototypeMethod) {\n        retVal = classMethod.apply(this, args);\n      }\n\n      return retVal;\n    };\n  }\n}\n\n/**\n * Simple constant function for returning null, used to render empty templates in JSX.\n *\n * @public\n */\nexport function nullRender(): JSX.Element | null {\n  return null;\n}\n"]}