This commit is contained in:
lik
2026-05-28 17:06:18 +08:00
parent a93a75b3c6
commit db0f47d994
582 changed files with 8060 additions and 1781 deletions

View File

@@ -0,0 +1,30 @@
import { SuperComponent } from '../common/src/index';
import { TdConfigProviderProps } from './type';
export interface ConfigProviderProps extends TdConfigProviderProps {
}
export default class ConfigProvider extends SuperComponent {
options: {
multipleSlots: boolean;
};
externalClasses: string[];
properties: TdConfigProviderProps;
data: {
prefix: string;
classPrefix: string;
cssVars: {};
};
_unsubscribeLocale?: () => void;
_componentId?: string;
observers: {
'themeVars, globalConfig'(): void;
};
lifetimes: {
attached(): void;
detached(): void;
};
methods: {
initStore(): void;
updateConfig(): void;
applyTheme(): void;
};
}

View File

@@ -0,0 +1 @@
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;

View File

@@ -0,0 +1 @@
{"component":true,"styleIsolation":"apply-shared"}

View File

@@ -0,0 +1 @@
<wxs src="../common/utils.wxs" module="_"/><view class="{{classPrefix}} class {{prefix}}-class" style="{{_._style([style, customStyle, cssVars])}}"><slot></slot></view>

View File

@@ -0,0 +1 @@
@import '../common/style/index.wxss';

View File

@@ -0,0 +1,16 @@
import ReactiveState from './reactive-state';
export declare type Locale = Record<string, any>;
declare class ConfigStore {
currentLocale: ReactiveState<Locale>;
themeVars: ReactiveState<Record<string, string>>;
private _pageInitFlags;
private _cleanupCallbacks;
private _deepEqual;
switchLocale(locale: Locale, componentId?: string): void;
updateThemeVars(vars: Record<string, string>): void;
private _getOrInitPageFlag;
registerCleanup(componentId: string, cleanup: () => void): void;
resetPageState(componentId?: string): void;
}
export declare const configStore: ConfigStore;
export {};

View File

@@ -0,0 +1 @@
import ReactiveState from"./reactive-state";class ConfigStore{constructor(){this.currentLocale=new ReactiveState({}),this.themeVars=new ReactiveState({}),this._pageInitFlags=new Map,this._cleanupCallbacks=new Map}_deepEqual(e,t){if(e===t)return!0;if(typeof e!=typeof t)return!1;if(null==e||null==t)return e===t;if("object"!=typeof e)return!1;const a=Object.keys(e),r=Object.keys(t);if(a.length!==r.length)return!1;try{const a=JSON.stringify(e);if(a===JSON.stringify(t))return!0}catch(e){}return a.every(a=>this._deepEqual(e[a],t[a]))}switchLocale(e,t){if(!t)return;const a=this._getOrInitPageFlag(t);if(a.locale){(!e||0===Object.keys(e).length)===(0===Object.keys(this.currentLocale.value).length)&&this._deepEqual(e,this.currentLocale.value)||(this.currentLocale.value=e)}else a.locale=!0,this.currentLocale.value=e}updateThemeVars(e){this.themeVars.value=Object.assign(Object.assign({},this.themeVars.value),e)}_getOrInitPageFlag(e){return this._pageInitFlags.has(e)||this._pageInitFlags.set(e,{theme:!1,locale:!1}),this._pageInitFlags.get(e)}registerCleanup(e,t){this._cleanupCallbacks.set(e,t)}resetPageState(e){if(e){this._pageInitFlags.delete(e);const t=this._cleanupCallbacks.get(e);if(t){try{t()}catch(t){console.error(`[ConfigStore] Error during cleanup for ${e}:`,t)}this._cleanupCallbacks.delete(e)}Array.from(this._pageInitFlags.values()).some(e=>e.locale)||(this.currentLocale.value={})}}}export const configStore=new ConfigStore;

View File

@@ -0,0 +1,3 @@
import { TdConfigProviderProps } from './type';
declare const props: TdConfigProviderProps;
export default props;

View File

@@ -0,0 +1 @@
const props={globalConfig:{type:Object},themeVars:{type:Object}};export default props;

View File

@@ -0,0 +1,9 @@
export default class ReactiveState<T> {
private _value;
private _listeners;
constructor(initialValue: T);
get value(): T;
set value(newValue: T);
subscribe(listener: (value: T) => void): () => void;
private _notify;
}

View File

@@ -0,0 +1 @@
export default class ReactiveState{constructor(e){this._listeners=new Set,this._value=e}get value(){return this._value}set value(e){this._value!==e&&(this._value=e,this._notify())}subscribe(e){return this._listeners.add(e),e(this._value),()=>{this._listeners.delete(e)}}_notify(){this._listeners.forEach(e=>{try{e(this._value)}catch(e){console.error("State listener error:",e)}})}}

View File

@@ -0,0 +1,136 @@
import { FormErrorMessage } from '../form/index';
import { ImageProps } from '../image/index';
export interface TdConfigProviderProps {
globalConfig?: {
type: ObjectConstructor;
value?: GlobalConfigProvider;
};
themeVars?: {
type: ObjectConstructor;
value?: object;
};
}
export interface GlobalConfigProvider {
actionSheet?: ActionSheetConfig;
calendar?: CalendarConfig;
cascader?: CascaderConfig;
classPrefix?: string;
dateTimePicker?: DateTimePickerConfig;
dropdownMenu?: DropdownMenuConfig;
guide?: GuideConfig;
picker?: PickerConfig;
pullDownRefresh?: PullDownRefreshConfig;
qrcode?: QRCodeConfig;
rate?: RateConfig;
tabBar?: TabBarConfig;
upload?: UploadConfig;
}
export interface ActionSheetConfig {
cancel?: string;
}
export interface AttachmentsConfig {
status?: {
pending: string;
fail: string;
};
}
export interface CalendarConfig {
confirm?: string;
monthTitle?: string;
months?: string[];
title?: string;
weekdays?: string[];
}
export interface CascaderConfig {
placeholder?: string;
title?: string;
}
export interface ChatActionbarConfig {
actionBar?: {
replay: string;
copy: string;
good: string;
bad: string;
share: string;
quote: string;
};
}
export interface ChatSenderConfig {
placeholder?: string;
sendText?: string;
stopText?: string;
}
export interface ChatThinkingConfig {
status?: {
pending: string;
complete: string;
stop: string;
};
}
export interface DateTimePickerConfig {
cancel?: string;
confirm?: string;
dateLabel?: string;
format?: string;
hourLabel?: string;
minuteLabel?: string;
monthLabel?: string;
secondLabel?: string;
title?: string;
yearLabel?: string;
}
export interface DropdownMenuConfig {
confirm?: string;
reset?: string;
}
export interface FormConfig {
colonText?: string;
errorMessage?: FormErrorMessage;
requiredMark?: boolean;
requiredMarkPosition?: 'left' | 'right';
}
export interface GuideConfig {
back?: string;
finish?: string;
next?: string;
skip?: string;
}
export interface ImageConfig {
errorText?: string;
loadingText?: string;
replaceImageSrc?: (params: ImageProps) => string;
}
export interface InputConfig {
placeholder?: string;
}
export interface PickerConfig {
cancel?: string;
confirm?: string;
}
export interface PullDownRefreshConfig {
loadingTexts?: string[];
}
export interface QRCodeConfig {
expiredText?: string;
refreshText?: string;
scannedText?: string;
}
export interface RateConfig {
noValueText?: string;
valueText?: string;
}
export interface TabBarConfig {
haveMoreNewsAriaLabel?: string;
haveNewsAriaLabel?: string;
moreNewsAriaLabel?: string;
newsAriaLabel?: string;
}
export interface UploadConfig {
progress?: UploadConfigProgress;
}
export interface UploadConfigProgress {
failText?: string;
successText?: string;
uploadingText?: string;
waitingText?: string;
}

View File

@@ -0,0 +1 @@
export{};

View File

@@ -0,0 +1,5 @@
export declare function getComponentLocale<T extends Record<string, any>>(component: any, componentName: string, defaultLocale: T, localePropName?: string): T;
export declare function useConfig(componentName: string): {
getLocale<T extends Record<string, any>>(defaultLocale: T, component: any): T;
subscribeLocale(component: any, callback: (locale: Record<string, any>) => void): () => void;
};

View File

@@ -0,0 +1 @@
import{configStore}from"./config-store";export function getComponentLocale(e,o,t,n){var r;let c={};n&&(c=(null===(r=e.properties)||void 0===r?void 0:r[n])||{});const i=configStore.currentLocale.value,s=i&&i[o]||{};return Object.assign(Object.assign(Object.assign({},t),s),c)}export function useConfig(e){return{getLocale:(o,t)=>getComponentLocale(t,e,o),subscribeLocale:(e,o)=>configStore.currentLocale.subscribe(e=>{o(e)})}}

View File

@@ -0,0 +1 @@
export default function themeVarsToCSS(themeVars: Record<string, string | number>, prefix?: string): Record<string, string>;

View File

@@ -0,0 +1 @@
import{toKebabCase}from"../common/utils";export default function themeVarsToCSS(t,e="--td-"){const o={};return Object.keys(t).forEach(r=>{let s;s=r.startsWith("--")?r:r.includes("-")?`${e}${r}`:`${e}${toKebabCase(r)}`,o[s]=String(t[r])}),o}