@wsxjs/wsx-core 0.0.6 → 0.0.7
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/LICENSE +21 -0
- package/dist/index.js +15 -0
- package/dist/index.mjs +15 -0
- package/package.json +46 -46
- package/src/light-component.ts +25 -2
- package/types/wsx-types.d.ts +4 -2
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 WSX Framework Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.js
CHANGED
|
@@ -721,9 +721,24 @@ var LightComponent = class extends HTMLElement {
|
|
|
721
721
|
return;
|
|
722
722
|
}
|
|
723
723
|
this.innerHTML = "";
|
|
724
|
+
if (this.config.styles) {
|
|
725
|
+
const styleName = this.config.styleName || this.constructor.name;
|
|
726
|
+
const styleElement = document.createElement("style");
|
|
727
|
+
styleElement.setAttribute("data-wsx-light-component", styleName);
|
|
728
|
+
styleElement.textContent = this.config.styles;
|
|
729
|
+
this.appendChild(styleElement);
|
|
730
|
+
}
|
|
724
731
|
try {
|
|
725
732
|
const content = this.render();
|
|
726
733
|
this.appendChild(content);
|
|
734
|
+
if (this.config.styles && this.children.length > 1) {
|
|
735
|
+
const styleElement = this.querySelector(
|
|
736
|
+
`style[data-wsx-light-component="${this.config.styleName || this.constructor.name}"]`
|
|
737
|
+
);
|
|
738
|
+
if (styleElement && styleElement !== this.firstChild) {
|
|
739
|
+
this.insertBefore(styleElement, this.firstChild);
|
|
740
|
+
}
|
|
741
|
+
}
|
|
727
742
|
} catch (error) {
|
|
728
743
|
logger3.error(`[${this.constructor.name}] Error in rerender:`, error);
|
|
729
744
|
this.renderError(error);
|
package/dist/index.mjs
CHANGED
|
@@ -490,9 +490,24 @@ var LightComponent = class extends HTMLElement {
|
|
|
490
490
|
return;
|
|
491
491
|
}
|
|
492
492
|
this.innerHTML = "";
|
|
493
|
+
if (this.config.styles) {
|
|
494
|
+
const styleName = this.config.styleName || this.constructor.name;
|
|
495
|
+
const styleElement = document.createElement("style");
|
|
496
|
+
styleElement.setAttribute("data-wsx-light-component", styleName);
|
|
497
|
+
styleElement.textContent = this.config.styles;
|
|
498
|
+
this.appendChild(styleElement);
|
|
499
|
+
}
|
|
493
500
|
try {
|
|
494
501
|
const content = this.render();
|
|
495
502
|
this.appendChild(content);
|
|
503
|
+
if (this.config.styles && this.children.length > 1) {
|
|
504
|
+
const styleElement = this.querySelector(
|
|
505
|
+
`style[data-wsx-light-component="${this.config.styleName || this.constructor.name}"]`
|
|
506
|
+
);
|
|
507
|
+
if (styleElement && styleElement !== this.firstChild) {
|
|
508
|
+
this.insertBefore(styleElement, this.firstChild);
|
|
509
|
+
}
|
|
510
|
+
}
|
|
496
511
|
} catch (error) {
|
|
497
512
|
logger3.error(`[${this.constructor.name}] Error in rerender:`, error);
|
|
498
513
|
this.renderError(error);
|
package/package.json
CHANGED
|
@@ -1,49 +1,49 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
},
|
|
14
|
-
"./jsx-runtime": {
|
|
15
|
-
"types": "./types/jsx-runtime.d.ts",
|
|
16
|
-
"import": "./dist/jsx-runtime.mjs",
|
|
17
|
-
"require": "./dist/jsx-runtime.js"
|
|
18
|
-
}
|
|
2
|
+
"name": "@wsxjs/wsx-core",
|
|
3
|
+
"version": "0.0.7",
|
|
4
|
+
"description": "Core WSX Framework - Web Components with JSX syntax",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.mjs",
|
|
7
|
+
"types": "./types/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./types/index.d.ts",
|
|
11
|
+
"import": "./dist/index.mjs",
|
|
12
|
+
"require": "./dist/index.js"
|
|
19
13
|
},
|
|
20
|
-
"
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
"!**/__tests__",
|
|
25
|
-
"!**/test"
|
|
26
|
-
],
|
|
27
|
-
"scripts": {
|
|
28
|
-
"build": "tsup src/index.ts src/jsx.ts src/jsx-runtime.ts --format cjs,esm",
|
|
29
|
-
"build:dev": "NODE_ENV=development tsup src/index.ts src/jsx.ts src/jsx-runtime.ts --format cjs,esm --sourcemap",
|
|
30
|
-
"dev": "NODE_ENV=development tsup src/index.ts src/jsx.ts src/jsx-runtime.ts --format cjs,esm --watch --sourcemap",
|
|
31
|
-
"test": "jest",
|
|
32
|
-
"typecheck": "tsc --noEmit",
|
|
33
|
-
"clean": "rm -rf dist"
|
|
34
|
-
},
|
|
35
|
-
"keywords": [
|
|
36
|
-
"web-components",
|
|
37
|
-
"jsx",
|
|
38
|
-
"typescript",
|
|
39
|
-
"custom-elements"
|
|
40
|
-
],
|
|
41
|
-
"devDependencies": {
|
|
42
|
-
"tsup": "^8.0.0",
|
|
43
|
-
"typescript": "^5.0.0",
|
|
44
|
-
"@types/node": "^20.0.0"
|
|
45
|
-
},
|
|
46
|
-
"peerDependencies": {
|
|
47
|
-
"typescript": ">=4.7.0"
|
|
14
|
+
"./jsx-runtime": {
|
|
15
|
+
"types": "./types/jsx-runtime.d.ts",
|
|
16
|
+
"import": "./dist/jsx-runtime.mjs",
|
|
17
|
+
"require": "./dist/jsx-runtime.js"
|
|
48
18
|
}
|
|
49
|
-
}
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"dist",
|
|
22
|
+
"src",
|
|
23
|
+
"types",
|
|
24
|
+
"!**/__tests__",
|
|
25
|
+
"!**/test"
|
|
26
|
+
],
|
|
27
|
+
"keywords": [
|
|
28
|
+
"web-components",
|
|
29
|
+
"jsx",
|
|
30
|
+
"typescript",
|
|
31
|
+
"custom-elements"
|
|
32
|
+
],
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"tsup": "^8.0.0",
|
|
35
|
+
"typescript": "^5.0.0",
|
|
36
|
+
"@types/node": "^20.0.0"
|
|
37
|
+
},
|
|
38
|
+
"peerDependencies": {
|
|
39
|
+
"typescript": ">=4.7.0"
|
|
40
|
+
},
|
|
41
|
+
"scripts": {
|
|
42
|
+
"build": "tsup src/index.ts src/jsx.ts src/jsx-runtime.ts --format cjs,esm",
|
|
43
|
+
"build:dev": "NODE_ENV=development tsup src/index.ts src/jsx.ts src/jsx-runtime.ts --format cjs,esm --sourcemap",
|
|
44
|
+
"dev": "NODE_ENV=development tsup src/index.ts src/jsx.ts src/jsx-runtime.ts --format cjs,esm --watch --sourcemap",
|
|
45
|
+
"test": "jest",
|
|
46
|
+
"typecheck": "tsc --noEmit",
|
|
47
|
+
"clean": "rm -rf dist"
|
|
48
|
+
}
|
|
49
|
+
}
|
package/src/light-component.ts
CHANGED
|
@@ -187,13 +187,36 @@ export abstract class LightComponent extends HTMLElement {
|
|
|
187
187
|
return;
|
|
188
188
|
}
|
|
189
189
|
|
|
190
|
-
//
|
|
190
|
+
// 清空现有内容(包括样式元素)
|
|
191
191
|
this.innerHTML = "";
|
|
192
192
|
|
|
193
|
-
//
|
|
193
|
+
// 重新应用样式(必须在内容之前添加,确保样式优先)
|
|
194
|
+
if (this.config.styles) {
|
|
195
|
+
const styleName = this.config.styleName || this.constructor.name;
|
|
196
|
+
// 直接创建并添加样式元素,不检查是否存在(因为 innerHTML = "" 已经清空了)
|
|
197
|
+
const styleElement = document.createElement("style");
|
|
198
|
+
styleElement.setAttribute("data-wsx-light-component", styleName);
|
|
199
|
+
styleElement.textContent = this.config.styles;
|
|
200
|
+
// 使用 prepend 或 insertBefore 确保样式在第一个位置
|
|
201
|
+
// 由于 innerHTML = "" 后 firstChild 是 null,使用 appendChild 然后调整顺序
|
|
202
|
+
this.appendChild(styleElement);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// 重新渲染JSX内容
|
|
194
206
|
try {
|
|
195
207
|
const content = this.render();
|
|
196
208
|
this.appendChild(content);
|
|
209
|
+
|
|
210
|
+
// 确保样式元素在内容之前(如果样式存在)
|
|
211
|
+
if (this.config.styles && this.children.length > 1) {
|
|
212
|
+
const styleElement = this.querySelector(
|
|
213
|
+
`style[data-wsx-light-component="${this.config.styleName || this.constructor.name}"]`
|
|
214
|
+
);
|
|
215
|
+
if (styleElement && styleElement !== this.firstChild) {
|
|
216
|
+
// 将样式元素移到第一个位置
|
|
217
|
+
this.insertBefore(styleElement, this.firstChild);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
197
220
|
} catch (error) {
|
|
198
221
|
logger.error(`[${this.constructor.name}] Error in rerender:`, error);
|
|
199
222
|
this.renderError(error);
|
package/types/wsx-types.d.ts
CHANGED
|
@@ -2,10 +2,12 @@
|
|
|
2
2
|
* WSX TypeScript 声明文件
|
|
3
3
|
* 支持 JSX 语法和其他 WSX 特性
|
|
4
4
|
*/
|
|
5
|
-
|
|
5
|
+
import { WebComponent, LightComponent } from "../src/index";
|
|
6
6
|
// WSX 文件支持 - 将 .wsx 文件视为 TypeScript 模块
|
|
7
|
+
// 标准类型声明:支持 WebComponent 和 LightComponent
|
|
7
8
|
declare module "*.wsx" {
|
|
8
|
-
|
|
9
|
+
// Allow any class that extends WebComponent or LightComponent
|
|
10
|
+
const Component: new (...args: unknown[]) => WebComponent | LightComponent;
|
|
9
11
|
export default Component;
|
|
10
12
|
}
|
|
11
13
|
|