@wsxjs/wsx-core 0.0.12 → 0.0.13

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.js CHANGED
@@ -1206,7 +1206,91 @@ function deriveTagName(className, prefix) {
1206
1206
  }
1207
1207
 
1208
1208
  // src/reactive-decorator.ts
1209
- function state(target, propertyKey) {
1209
+ function state(targetOrContext, propertyKey) {
1210
+ let propertyName;
1211
+ if (typeof targetOrContext === "object" && targetOrContext !== null && "kind" in targetOrContext && "name" in targetOrContext) {
1212
+ const context = targetOrContext;
1213
+ propertyName = typeof context.name === "string" ? context.name : context.name.toString();
1214
+ } else {
1215
+ if (typeof propertyKey === "string" || typeof propertyKey === "symbol") {
1216
+ propertyName = typeof propertyKey === "string" ? propertyKey : propertyKey.toString();
1217
+ } else {
1218
+ propertyName = String(propertyKey);
1219
+ }
1220
+ }
1221
+ console.warn(
1222
+ `[WSX] @state decorator is using runtime fallback. Property "${propertyName}" will work but with reduced performance.
1223
+
1224
+ To fix this and enable compile-time processing, please:
1225
+ 1. Install @wsxjs/wsx-vite-plugin: npm install @wsxjs/wsx-vite-plugin
1226
+ 2. Configure it in vite.config.ts:
1227
+ import { wsx } from '@wsxjs/wsx-vite-plugin';
1228
+ export default defineConfig({ plugins: [wsx()] });
1229
+ 3. Configure TypeScript (recommended: use @wsxjs/wsx-tsconfig):
1230
+ npm install --save-dev @wsxjs/wsx-tsconfig
1231
+ Then in tsconfig.json: { "extends": "@wsxjs/wsx-tsconfig/tsconfig.base.json" }
1232
+ Or manually: { "compilerOptions": { "experimentalDecorators": true, "useDefineForClassFields": false } }
1233
+
1234
+ See: https://github.com/wsxjs/wsxjs#setup for more details.`
1235
+ );
1236
+ if (typeof targetOrContext === "object" && targetOrContext !== null && "kind" in targetOrContext && "name" in targetOrContext) {
1237
+ const context = targetOrContext;
1238
+ if (context.kind !== "field") {
1239
+ const nameStr = typeof context.name === "string" ? context.name : context.name.toString();
1240
+ throw new Error(
1241
+ `@state decorator can only be used on class fields, not ${context.kind}. Property: "${nameStr}"`
1242
+ );
1243
+ }
1244
+ if (context.addInitializer) {
1245
+ context.addInitializer(function() {
1246
+ if (!this || typeof this.reactive !== "function" || typeof this.useState !== "function") {
1247
+ throw new Error(
1248
+ `@state decorator runtime fallback: Component does not extend WebComponent or LightComponent. Property "${propertyName}" cannot be made reactive.
1249
+
1250
+ The @state decorator can only be used in classes that extend WebComponent or LightComponent. Please ensure your component class extends one of these base classes.`
1251
+ );
1252
+ }
1253
+ let initialValue = void 0;
1254
+ if (context.access?.get) {
1255
+ try {
1256
+ initialValue = context.access.get();
1257
+ } catch {
1258
+ initialValue = this[propertyName];
1259
+ }
1260
+ } else {
1261
+ initialValue = this[propertyName];
1262
+ }
1263
+ const isObject = initialValue !== null && initialValue !== void 0 && (typeof initialValue === "object" || Array.isArray(initialValue));
1264
+ if (isObject) {
1265
+ let reactiveValue = this.reactive(initialValue);
1266
+ Object.defineProperty(this, propertyName, {
1267
+ get: () => reactiveValue,
1268
+ set: (newValue) => {
1269
+ if (newValue !== null && newValue !== void 0 && (typeof newValue === "object" || Array.isArray(newValue))) {
1270
+ reactiveValue = this.reactive(newValue);
1271
+ this.scheduleRerender();
1272
+ } else {
1273
+ reactiveValue = newValue;
1274
+ this.scheduleRerender();
1275
+ }
1276
+ },
1277
+ enumerable: true,
1278
+ configurable: true
1279
+ });
1280
+ } else {
1281
+ const [getState, setState] = this.useState(propertyName, initialValue);
1282
+ Object.defineProperty(this, propertyName, {
1283
+ get: getState,
1284
+ set: setState,
1285
+ enumerable: true,
1286
+ configurable: true
1287
+ });
1288
+ }
1289
+ });
1290
+ }
1291
+ return context;
1292
+ }
1293
+ const target = targetOrContext;
1210
1294
  let normalizedPropertyKey;
1211
1295
  if (typeof propertyKey === "string" || typeof propertyKey === "symbol") {
1212
1296
  normalizedPropertyKey = propertyKey;
package/dist/index.mjs CHANGED
@@ -973,7 +973,91 @@ function deriveTagName(className, prefix) {
973
973
  }
974
974
 
975
975
  // src/reactive-decorator.ts
976
- function state(target, propertyKey) {
976
+ function state(targetOrContext, propertyKey) {
977
+ let propertyName;
978
+ if (typeof targetOrContext === "object" && targetOrContext !== null && "kind" in targetOrContext && "name" in targetOrContext) {
979
+ const context = targetOrContext;
980
+ propertyName = typeof context.name === "string" ? context.name : context.name.toString();
981
+ } else {
982
+ if (typeof propertyKey === "string" || typeof propertyKey === "symbol") {
983
+ propertyName = typeof propertyKey === "string" ? propertyKey : propertyKey.toString();
984
+ } else {
985
+ propertyName = String(propertyKey);
986
+ }
987
+ }
988
+ console.warn(
989
+ `[WSX] @state decorator is using runtime fallback. Property "${propertyName}" will work but with reduced performance.
990
+
991
+ To fix this and enable compile-time processing, please:
992
+ 1. Install @wsxjs/wsx-vite-plugin: npm install @wsxjs/wsx-vite-plugin
993
+ 2. Configure it in vite.config.ts:
994
+ import { wsx } from '@wsxjs/wsx-vite-plugin';
995
+ export default defineConfig({ plugins: [wsx()] });
996
+ 3. Configure TypeScript (recommended: use @wsxjs/wsx-tsconfig):
997
+ npm install --save-dev @wsxjs/wsx-tsconfig
998
+ Then in tsconfig.json: { "extends": "@wsxjs/wsx-tsconfig/tsconfig.base.json" }
999
+ Or manually: { "compilerOptions": { "experimentalDecorators": true, "useDefineForClassFields": false } }
1000
+
1001
+ See: https://github.com/wsxjs/wsxjs#setup for more details.`
1002
+ );
1003
+ if (typeof targetOrContext === "object" && targetOrContext !== null && "kind" in targetOrContext && "name" in targetOrContext) {
1004
+ const context = targetOrContext;
1005
+ if (context.kind !== "field") {
1006
+ const nameStr = typeof context.name === "string" ? context.name : context.name.toString();
1007
+ throw new Error(
1008
+ `@state decorator can only be used on class fields, not ${context.kind}. Property: "${nameStr}"`
1009
+ );
1010
+ }
1011
+ if (context.addInitializer) {
1012
+ context.addInitializer(function() {
1013
+ if (!this || typeof this.reactive !== "function" || typeof this.useState !== "function") {
1014
+ throw new Error(
1015
+ `@state decorator runtime fallback: Component does not extend WebComponent or LightComponent. Property "${propertyName}" cannot be made reactive.
1016
+
1017
+ The @state decorator can only be used in classes that extend WebComponent or LightComponent. Please ensure your component class extends one of these base classes.`
1018
+ );
1019
+ }
1020
+ let initialValue = void 0;
1021
+ if (context.access?.get) {
1022
+ try {
1023
+ initialValue = context.access.get();
1024
+ } catch {
1025
+ initialValue = this[propertyName];
1026
+ }
1027
+ } else {
1028
+ initialValue = this[propertyName];
1029
+ }
1030
+ const isObject = initialValue !== null && initialValue !== void 0 && (typeof initialValue === "object" || Array.isArray(initialValue));
1031
+ if (isObject) {
1032
+ let reactiveValue = this.reactive(initialValue);
1033
+ Object.defineProperty(this, propertyName, {
1034
+ get: () => reactiveValue,
1035
+ set: (newValue) => {
1036
+ if (newValue !== null && newValue !== void 0 && (typeof newValue === "object" || Array.isArray(newValue))) {
1037
+ reactiveValue = this.reactive(newValue);
1038
+ this.scheduleRerender();
1039
+ } else {
1040
+ reactiveValue = newValue;
1041
+ this.scheduleRerender();
1042
+ }
1043
+ },
1044
+ enumerable: true,
1045
+ configurable: true
1046
+ });
1047
+ } else {
1048
+ const [getState, setState] = this.useState(propertyName, initialValue);
1049
+ Object.defineProperty(this, propertyName, {
1050
+ get: getState,
1051
+ set: setState,
1052
+ enumerable: true,
1053
+ configurable: true
1054
+ });
1055
+ }
1056
+ });
1057
+ }
1058
+ return context;
1059
+ }
1060
+ const target = targetOrContext;
977
1061
  let normalizedPropertyKey;
978
1062
  if (typeof propertyKey === "string" || typeof propertyKey === "symbol") {
979
1063
  normalizedPropertyKey = propertyKey;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wsxjs/wsx-core",
3
- "version": "0.0.12",
3
+ "version": "0.0.13",
4
4
  "description": "Core WSX Framework - Web Components with JSX syntax",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -51,7 +51,7 @@ interface DecoratorContext {
51
51
  export function state(
52
52
  targetOrContext: unknown | DecoratorContext,
53
53
  propertyKey?: string | symbol | unknown
54
- ): void | DecoratorContext {
54
+ ): unknown {
55
55
  /**
56
56
  * @state decorator supports both:
57
57
  * 1. Compile-time processing by Babel plugin (preferred) - decorator is removed at compile time