@wsxjs/wsx-base-components 0.0.7 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +2 -2
- package/dist/index.js +1289 -708
- package/package.json +4 -4
- package/src/ColorPicker.wsx +0 -2
- package/src/ReactiveCounter.wsx +19 -32
- package/src/SimpleReactiveDemo.wsx +6 -5
- package/src/ThemeSwitcher.wsx +0 -2
- package/src/XyButton.wsx +0 -2
- package/src/XyButtonGroup.wsx +0 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wsxjs/wsx-base-components",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.8",
|
|
4
4
|
"description": "Base UI components built with WSX Framework",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"!**/test"
|
|
19
19
|
],
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@wsxjs/wsx-core": "0.0.
|
|
21
|
+
"@wsxjs/wsx-core": "0.0.8"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"@typescript-eslint/eslint-plugin": "^8.37.0",
|
|
@@ -28,8 +28,8 @@
|
|
|
28
28
|
"tsup": "^8.0.0",
|
|
29
29
|
"typescript": "^5.0.0",
|
|
30
30
|
"vite": "^5.4.19",
|
|
31
|
-
"@wsxjs/
|
|
32
|
-
"@wsxjs/
|
|
31
|
+
"@wsxjs/wsx-vite-plugin": "0.0.8",
|
|
32
|
+
"@wsxjs/eslint-plugin-wsx": "0.0.8"
|
|
33
33
|
},
|
|
34
34
|
"keywords": [
|
|
35
35
|
"wsx",
|
package/src/ColorPicker.wsx
CHANGED
|
@@ -10,7 +10,6 @@
|
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
import { WebComponent, autoRegister, createLogger } from "@wsxjs/wsx-core";
|
|
13
|
-
import styles from "./ColorPicker.css?inline";
|
|
14
13
|
import {
|
|
15
14
|
handleCSSVariables,
|
|
16
15
|
setDefaultColorCache,
|
|
@@ -89,7 +88,6 @@ export default class ColorPicker extends WebComponent {
|
|
|
89
88
|
|
|
90
89
|
constructor(config: ColorPickerConfig = {}) {
|
|
91
90
|
super({
|
|
92
|
-
styles,
|
|
93
91
|
styleName: "base-color-picker",
|
|
94
92
|
...config,
|
|
95
93
|
});
|
package/src/ReactiveCounter.wsx
CHANGED
|
@@ -6,47 +6,36 @@
|
|
|
6
6
|
* - 自动重渲染:状态变化时无需手动调用 rerender()
|
|
7
7
|
* - 批量更新:多个状态变化会被合并为一次重渲染
|
|
8
8
|
* - 原生性能:基于浏览器 Proxy API,零运行时开销
|
|
9
|
+
* - 使用 @state 装饰器:自动初始化响应式状态
|
|
9
10
|
*/
|
|
10
11
|
|
|
11
|
-
import {
|
|
12
|
-
import styles from "./ReactiveCounter.css?inline";
|
|
12
|
+
import { WebComponent, state, autoRegister, createLogger } from "@wsxjs/wsx-core";
|
|
13
13
|
|
|
14
14
|
const logger = createLogger("ReactiveCounter");
|
|
15
15
|
|
|
16
16
|
@autoRegister({ tagName: "reactive-counter" })
|
|
17
|
-
export default class ReactiveCounter extends
|
|
18
|
-
//
|
|
19
|
-
private state =
|
|
17
|
+
export default class ReactiveCounter extends WebComponent {
|
|
18
|
+
// 使用 @state 装饰器 - 自动初始化为响应式状态
|
|
19
|
+
@state private state = {
|
|
20
20
|
count: 0,
|
|
21
21
|
step: 1,
|
|
22
22
|
message: "Hello WSX Reactive!",
|
|
23
23
|
isRunning: false,
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// 使用 useState API - 类似 React 的 useState
|
|
27
|
-
private themeState = this.useState("theme", "light");
|
|
28
|
-
private historyState = this.useState("history", [] as number[]);
|
|
24
|
+
};
|
|
29
25
|
|
|
30
|
-
|
|
31
|
-
private
|
|
32
|
-
private
|
|
33
|
-
private setHistory = this.historyState[1];
|
|
26
|
+
// 使用 @state 装饰器 - 基本类型自动使用 useState
|
|
27
|
+
@state private theme = "light";
|
|
28
|
+
@state private history: number[] = [];
|
|
34
29
|
|
|
35
30
|
constructor() {
|
|
36
|
-
super(
|
|
37
|
-
styles,
|
|
38
|
-
debug: true, // 启用调试模式
|
|
39
|
-
});
|
|
31
|
+
super();
|
|
40
32
|
|
|
41
33
|
logger.info("ReactiveCounter initialized");
|
|
42
34
|
}
|
|
43
35
|
|
|
44
36
|
render() {
|
|
45
|
-
const theme = this.getTheme();
|
|
46
|
-
const history = this.getHistory();
|
|
47
|
-
|
|
48
37
|
return (
|
|
49
|
-
<div class={`reactive-counter theme-${theme}`}>
|
|
38
|
+
<div class={`reactive-counter theme-${this.theme}`}>
|
|
50
39
|
<div class="header">
|
|
51
40
|
<h3>🔄 Reactive Counter</h3>
|
|
52
41
|
<p class="subtitle">{this.state.message}</p>
|
|
@@ -109,7 +98,7 @@ export default class ReactiveCounter extends ReactiveWebComponent {
|
|
|
109
98
|
<div class="theme-controls">
|
|
110
99
|
<label>
|
|
111
100
|
Theme:
|
|
112
|
-
<select value={theme} onChange={this.handleThemeChange}>
|
|
101
|
+
<select value={this.theme} onChange={this.handleThemeChange}>
|
|
113
102
|
<option value="light">Light</option>
|
|
114
103
|
<option value="dark">Dark</option>
|
|
115
104
|
<option value="blue">Blue</option>
|
|
@@ -126,11 +115,11 @@ export default class ReactiveCounter extends ReactiveWebComponent {
|
|
|
126
115
|
/>
|
|
127
116
|
</div>
|
|
128
117
|
|
|
129
|
-
{history.length > 0 && (
|
|
118
|
+
{this.history.length > 0 && (
|
|
130
119
|
<div class="history">
|
|
131
120
|
<h4>History (last 10):</h4>
|
|
132
121
|
<div class="history-list">
|
|
133
|
-
{history.slice(-10).map((value, index) => (
|
|
122
|
+
{this.history.slice(-10).map((value, index) => (
|
|
134
123
|
<span key={index} class="history-item">
|
|
135
124
|
{value}
|
|
136
125
|
</span>
|
|
@@ -149,9 +138,8 @@ export default class ReactiveCounter extends ReactiveWebComponent {
|
|
|
149
138
|
{JSON.stringify(
|
|
150
139
|
{
|
|
151
140
|
state: this.state,
|
|
152
|
-
theme: this.
|
|
153
|
-
historyLength: this.
|
|
154
|
-
stateSnapshot: this.getStateSnapshot(),
|
|
141
|
+
theme: this.theme,
|
|
142
|
+
historyLength: this.history.length,
|
|
155
143
|
},
|
|
156
144
|
null,
|
|
157
145
|
2
|
|
@@ -186,7 +174,7 @@ export default class ReactiveCounter extends ReactiveWebComponent {
|
|
|
186
174
|
|
|
187
175
|
private handleThemeChange = (event: Event) => {
|
|
188
176
|
const select = event.target as HTMLSelectElement;
|
|
189
|
-
this.
|
|
177
|
+
this.theme = select.value;
|
|
190
178
|
};
|
|
191
179
|
|
|
192
180
|
private handleMessageChange = (event: Event) => {
|
|
@@ -219,12 +207,11 @@ export default class ReactiveCounter extends ReactiveWebComponent {
|
|
|
219
207
|
}
|
|
220
208
|
|
|
221
209
|
private addToHistory(value: number) {
|
|
222
|
-
|
|
223
|
-
this.setHistory([...history, value]);
|
|
210
|
+
this.history = [...this.history, value];
|
|
224
211
|
}
|
|
225
212
|
|
|
226
213
|
private clearHistory = () => {
|
|
227
|
-
this.
|
|
214
|
+
this.history = [];
|
|
228
215
|
};
|
|
229
216
|
|
|
230
217
|
protected onConnected(): void {
|
|
@@ -2,19 +2,20 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* 简单的响应式演示组件
|
|
4
4
|
* 展示 WSX 响应式状态系统的基本功能
|
|
5
|
+
* 使用 @state 装饰器自动初始化响应式状态
|
|
5
6
|
*/
|
|
6
7
|
|
|
7
|
-
import {
|
|
8
|
+
import { WebComponent, state, autoRegister, createLogger } from "@wsxjs/wsx-core";
|
|
8
9
|
|
|
9
10
|
const logger = createLogger("SimpleReactiveDemo");
|
|
10
11
|
|
|
11
12
|
@autoRegister({ tagName: "simple-reactive-demo" })
|
|
12
|
-
export default class SimpleReactiveDemo extends
|
|
13
|
-
//
|
|
14
|
-
private state =
|
|
13
|
+
export default class SimpleReactiveDemo extends WebComponent {
|
|
14
|
+
// 使用 @state 装饰器 - 自动初始化为响应式状态
|
|
15
|
+
@state private state = {
|
|
15
16
|
count: 0,
|
|
16
17
|
message: "Click the button!",
|
|
17
|
-
}
|
|
18
|
+
};
|
|
18
19
|
|
|
19
20
|
constructor() {
|
|
20
21
|
super();
|
package/src/ThemeSwitcher.wsx
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/** @jsxImportSource @wsxjs/wsx-core */
|
|
2
2
|
|
|
3
3
|
import { WebComponent, autoRegister } from "@wsxjs/wsx-core";
|
|
4
|
-
import styles from "./ThemeSwitcher.css?inline";
|
|
5
4
|
|
|
6
5
|
@autoRegister({ tagName: "theme-switcher" })
|
|
7
6
|
export default class ThemeSwitcher extends WebComponent {
|
|
@@ -9,7 +8,6 @@ export default class ThemeSwitcher extends WebComponent {
|
|
|
9
8
|
|
|
10
9
|
constructor() {
|
|
11
10
|
super({
|
|
12
|
-
styles,
|
|
13
11
|
styleName: "theme-switcher",
|
|
14
12
|
});
|
|
15
13
|
|
package/src/XyButton.wsx
CHANGED
|
@@ -11,7 +11,6 @@
|
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
import { WebComponent, autoRegister } from "@wsxjs/wsx-core";
|
|
14
|
-
import styles from "./XyButton.css?inline";
|
|
15
14
|
|
|
16
15
|
export interface XyButtonConfig {
|
|
17
16
|
disabled?: boolean;
|
|
@@ -71,7 +70,6 @@ export default class XyButton extends WebComponent {
|
|
|
71
70
|
|
|
72
71
|
constructor(config: XyButtonConfig = {}) {
|
|
73
72
|
super({
|
|
74
|
-
styles,
|
|
75
73
|
styleName: "xy-button",
|
|
76
74
|
...config,
|
|
77
75
|
});
|
package/src/XyButtonGroup.wsx
CHANGED
|
@@ -7,7 +7,6 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import { WebComponent, autoRegister } from "@wsxjs/wsx-core";
|
|
10
|
-
import styles from "./XyButtonGroup.css?inline";
|
|
11
10
|
|
|
12
11
|
export interface XyButtonGroupConfig {
|
|
13
12
|
disabled?: boolean;
|
|
@@ -23,7 +22,6 @@ export default class XyButtonGroup extends WebComponent {
|
|
|
23
22
|
|
|
24
23
|
constructor(config: XyButtonGroupConfig = {}) {
|
|
25
24
|
super({
|
|
26
|
-
styles,
|
|
27
25
|
styleName: "xy-button-group",
|
|
28
26
|
...config,
|
|
29
27
|
});
|