@wsxjs/wsx-base-components 0.0.6 → 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/package.json CHANGED
@@ -1,57 +1,57 @@
1
1
  {
2
- "name": "@wsxjs/wsx-base-components",
3
- "version": "0.0.6",
4
- "description": "Base UI components built with WSX Framework",
5
- "type": "module",
6
- "main": "./dist/index.cjs",
7
- "module": "./dist/index.js",
8
- "exports": {
9
- ".": {
10
- "import": "./dist/index.js",
11
- "require": "./dist/index.cjs"
12
- }
13
- },
14
- "files": [
15
- "dist",
16
- "src",
17
- "!**/__tests__",
18
- "!**/test"
19
- ],
20
- "scripts": {
21
- "build": "vite build",
22
- "build:dev": "NODE_ENV=development vite build",
23
- "dev": "NODE_ENV=development vite build --watch",
24
- "clean": "rm -rf dist",
25
- "typecheck": "tsc --noEmit",
26
- "lint": "eslint .",
27
- "lint:fix": "eslint . --fix"
28
- },
29
- "dependencies": {
30
- "@wsxjs/wsx-core": "workspace:*"
31
- },
32
- "devDependencies": {
33
- "@wsxjs/eslint-plugin-wsx": "workspace:*",
34
- "@wsxjs/wsx-vite-plugin": "workspace:*",
35
- "@typescript-eslint/eslint-plugin": "^8.37.0",
36
- "@typescript-eslint/parser": "^8.37.0",
37
- "eslint": "^9.31.0",
38
- "http-server": "^14.1.1",
39
- "tsup": "^8.0.0",
40
- "typescript": "^5.0.0",
41
- "vite": "^5.4.19"
42
- },
43
- "keywords": [
44
- "wsx",
45
- "web-components",
46
- "ui-components",
47
- "typescript",
48
- "jsx"
49
- ],
50
- "author": "WSX Framework Team",
51
- "license": "MIT",
52
- "repository": {
53
- "type": "git",
54
- "url": "https://github.com/wsxjs/wsxjs.git",
55
- "directory": "packages/base-components"
2
+ "name": "@wsxjs/wsx-base-components",
3
+ "version": "0.0.8",
4
+ "description": "Base UI components built with WSX Framework",
5
+ "type": "module",
6
+ "main": "./dist/index.cjs",
7
+ "module": "./dist/index.js",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/index.js",
11
+ "require": "./dist/index.cjs"
56
12
  }
57
- }
13
+ },
14
+ "files": [
15
+ "dist",
16
+ "src",
17
+ "!**/__tests__",
18
+ "!**/test"
19
+ ],
20
+ "dependencies": {
21
+ "@wsxjs/wsx-core": "0.0.8"
22
+ },
23
+ "devDependencies": {
24
+ "@typescript-eslint/eslint-plugin": "^8.37.0",
25
+ "@typescript-eslint/parser": "^8.37.0",
26
+ "eslint": "^9.31.0",
27
+ "http-server": "^14.1.1",
28
+ "tsup": "^8.0.0",
29
+ "typescript": "^5.0.0",
30
+ "vite": "^5.4.19",
31
+ "@wsxjs/wsx-vite-plugin": "0.0.8",
32
+ "@wsxjs/eslint-plugin-wsx": "0.0.8"
33
+ },
34
+ "keywords": [
35
+ "wsx",
36
+ "web-components",
37
+ "ui-components",
38
+ "typescript",
39
+ "jsx"
40
+ ],
41
+ "author": "WSX Framework Team",
42
+ "license": "MIT",
43
+ "repository": {
44
+ "type": "git",
45
+ "url": "https://github.com/wsxjs/wsxjs.git",
46
+ "directory": "packages/base-components"
47
+ },
48
+ "scripts": {
49
+ "build": "vite build",
50
+ "build:dev": "NODE_ENV=development vite build",
51
+ "dev": "NODE_ENV=development vite build --watch",
52
+ "clean": "rm -rf dist",
53
+ "typecheck": "tsc --noEmit",
54
+ "lint": "eslint .",
55
+ "lint:fix": "eslint . --fix"
56
+ }
57
+ }
@@ -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
  });
@@ -6,47 +6,36 @@
6
6
  * - 自动重渲染:状态变化时无需手动调用 rerender()
7
7
  * - 批量更新:多个状态变化会被合并为一次重渲染
8
8
  * - 原生性能:基于浏览器 Proxy API,零运行时开销
9
+ * - 使用 @state 装饰器:自动初始化响应式状态
9
10
  */
10
11
 
11
- import { ReactiveWebComponent, autoRegister, createLogger } from "@wsxjs/wsx-core";
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 ReactiveWebComponent {
18
- // 使用响应式对象 - 任何属性变化都会自动触发重渲染
19
- private state = this.reactive({
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
- private getTheme = this.themeState[0];
31
- private setTheme = this.themeState[1];
32
- private getHistory = this.historyState[0];
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.getTheme(),
153
- historyLength: this.getHistory().length,
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.setTheme(select.value);
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
- const history = this.getHistory();
223
- this.setHistory([...history, value]);
210
+ this.history = [...this.history, value];
224
211
  }
225
212
 
226
213
  private clearHistory = () => {
227
- this.setHistory([]);
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 { ReactiveWebComponent, autoRegister, createLogger } from "@wsxjs/wsx-core";
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 ReactiveWebComponent {
13
- // 响应式状态 - 自动触发重渲染
14
- private state = this.reactive({
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();
@@ -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
  });
@@ -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
  });