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AY,CAAC,MAAM,IAAI,OAAO,YAAY,CAAC,MAAM,KAAK,UAAU,EAAE;4BACpE,YAAY,CAAC,MAAM,GAAG,YAAY,CAAC,MAAM,uBAAM,YAAY,GAAK,cAAc,EAAG,CAAC;yBACnF;wBAED,mFAAmF;wBACnF,IAAI,YAAY,IAAI,YAAY,CAAC,MAAM,EAAE;4BACvC,IACE,KAAI,CAAC,WAAW,CAAC,OAAO,KAAK,YAAY,CAAC,MAAM;gCAChD,KAAI,CAAC,WAAW,CAAC,SAAS,KAAK,cAAc,CAAC,MAAM,EACpD;gCACA,IAAM,YAAY,GAAG,eAAe,CAAC,YAAY,CAAC,MAAM,EAAE,cAAc,CAAC,MAAM,CAAC,CAAC;gCACjF,KAAI,CAAC,WAAW,CAAC,OAAO,GAAG,YAAY,CAAC,MAAM,CAAC;gCAC/C,KAAI,CAAC,WAAW,CAAC,SAAS,GAAG,cAAc,CAAC,MAAM,CAAC;gCACnD,KAAI,CAAC,WAAW,CAAC,MAAM,GAAG,YAAY,CAAC;6BACxC;4BAED,OAAO,oBAAC,iBAAiB,eAAK,YAAY,EAAM,cAAc,IAAE,MAAM,EAAE,KAAI,CAAC,WAAW,CAAC,MAAM,IAAI,CAAC;yBACrG;wBAED,OAAO,oBAAC,iBAAiB,eAAK,YAAY,EAAM,cAAc,EAAI,CAAC;oBACrE,CAAC,CAC0B,CAC9B,CAAC;gBACJ,CAAC;gBAEO,sDAAiB,GAAzB;oBACE,IAAI,CAAC,WAAW,EAAE,CAAC;gBACrB,CAAC;gBACH,iCAAC;YAAD,CAAC,AA1DmB,CAAyC,KAAK,CAAC,SAAS;YAC5D,cAAW,GAAW,YAAY,GAAG,KAAM;eAyD1D,CAAC;QAEF,OAAO,YAAY,CAAC,iBAAiB,EAAE,WAAW,CAAC,CAAC;IACtD,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import * as React from 'react';\nimport { Customizations } from './Customizations';\nimport { hoistStatics } from '../hoistStatics';\nimport { CustomizerContext, ICustomizerContext } from './CustomizerContext';\nimport { concatStyleSets } from '@uifabric/merge-styles';\n\nexport function customizable(\n scope: string,\n fields: string[],\n concatStyles?: boolean,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n): <P>(ComposedComponent: React.ComponentType<P>) => any {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return function customizableFactory<P>(ComposedComponent: React.ComponentType<P>): any {\n const resultClass = class ComponentWithInjectedProps extends React.Component<P, {}> {\n public static displayName: string = 'Customized' + scope;\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n private _styleCache: { default?: any; component?: any; merged?: any } = {};\n\n constructor(props: P) {\n super(props);\n\n this._onSettingChanged = this._onSettingChanged.bind(this);\n }\n\n public componentDidMount(): void {\n Customizations.observe(this._onSettingChanged);\n }\n\n public componentWillUnmount(): void {\n Customizations.unobserve(this._onSettingChanged);\n }\n\n public render(): JSX.Element {\n return (\n <CustomizerContext.Consumer>\n {(context: ICustomizerContext) => {\n const defaultProps = Customizations.getSettings(fields, scope, context.customizations);\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const componentProps = this.props as any;\n\n // If defaultProps.styles is a function, evaluate it before calling concatStyleSets\n if (defaultProps.styles && typeof defaultProps.styles === 'function') {\n defaultProps.styles = defaultProps.styles({ ...defaultProps, ...componentProps });\n }\n\n // If concatStyles is true and custom styles have been defined compute those styles\n if (concatStyles && defaultProps.styles) {\n if (\n this._styleCache.default !== defaultProps.styles ||\n this._styleCache.component !== componentProps.styles\n ) {\n const mergedStyles = concatStyleSets(defaultProps.styles, componentProps.styles);\n this._styleCache.default = defaultProps.styles;\n this._styleCache.component = componentProps.styles;\n this._styleCache.merged = mergedStyles;\n }\n\n return <ComposedComponent {...defaultProps} {...componentProps} styles={this._styleCache.merged} />;\n }\n\n return <ComposedComponent {...defaultProps} {...componentProps} />;\n }}\n </CustomizerContext.Consumer>\n );\n }\n\n private _onSettingChanged(): void {\n this.forceUpdate();\n }\n };\n\n return hoistStatics(ComposedComponent, resultClass);\n };\n}\n"]}
\No newline at end of file