import{__decorate}from"tslib";import{SuperComponent,wxComponent}from"../common/src/index";import config from"../common/config";import props from"./props";import{configStore}from"./config-store";import themeVarsToCSS from"./utils";const{prefix:prefix}=config,componentName="config-provider";let ConfigProvider=class extends SuperComponent{constructor(){super(...arguments),this.options={multipleSlots:!0},this.externalClasses=[`${prefix}-class`],this.properties=props,this.data={prefix:prefix,classPrefix:`${prefix}-${componentName}`,cssVars:{}},this.observers={"themeVars, globalConfig"(){this.updateConfig()}},this.lifetimes={attached(){this._componentId=`${Date.now()}-${Math.random().toString(36).slice(2)}`,this.initStore(),this.updateConfig()},detached(){this._unsubscribeLocale&&this._unsubscribeLocale(),this._componentId&&configStore.resetPageState(this._componentId)}},this.methods={initStore(){this._unsubscribeLocale=configStore.currentLocale.subscribe(()=>{})},updateConfig(){const{themeVars:e,globalConfig:o}=this.properties;o&&configStore.switchLocale(o,this._componentId),e&&configStore.updateThemeVars(e),this.applyTheme()},applyTheme(){const{themeVars:e}=this.properties,o=themeVarsToCSS(e||{});this.setData({cssVars:o})}}}};ConfigProvider=__decorate([wxComponent()],ConfigProvider);export default ConfigProvider;
|