@wiajs/core 1.2.1 → 1.2.3

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/.oxfmtrc.jsonc ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ // https://unpkg.com/oxfmt@0.35.0/configuration_schema.json
3
+ "$schema": "../../node_modules/oxfmt/configuration_schema.json",
4
+ "printWidth": 120,
5
+ "semi": false, // 强制去除分号,保持 JS/TS 的现代感与简洁
6
+ "singleQuote": true, // 推荐使用单引号,视觉干扰比双引号少
7
+ "arrowParens": "avoid",
8
+ "bracketSameLine": true,
9
+ "bracketSpacing": false, // 去除对象字面量中的空格,保持紧凑
10
+ "jsxBracketSameLine": true,
11
+ "jsxSingleQuote": true,
12
+ "trailingComma": "es5", // 去除尾逗号,保持代码简洁
13
+ // 导入排序:极度紧凑
14
+ "sortImports": {
15
+ "newlinesBetween": false, // 核心:去除不同组导入之间的空行,压缩垂直空间
16
+ "groups": ["builtin", "external", "internal", "parent", "sibling", "index"],
17
+ "caseSensitive": false,
18
+ },
19
+ // Package.json 排序:工程标准化
20
+ "sortPackageJson": {
21
+ "sortScripts": true, // 必须:脚本有序化,方便维护
22
+ },
23
+ // 3. Tailwind 类名排序:样式一致性
24
+ "sortTailwindcss": {
25
+ // 1. 覆盖所有类名可能出现的逻辑场景
26
+ "functions": ["clsx", "cn", "cva", "twMerge", "tw"],
27
+ // 2. 适配所有可能的属性(如某些库使用的 tw 属性)
28
+ "attributes": ["class", "className", "tw"],
29
+ // 3. 保持紧凑:自动去重,自动压缩空格
30
+ "preserveDuplicates": false,
31
+ "preserveWhitespace": false,
32
+ // 4. 如果是 Tailwind v4,指向你的 CSS 入口
33
+ // "stylesheet": "src/index.css"
34
+ },
35
+ "ignorePatterns": [
36
+ "apps/",
37
+ "assets/",
38
+ "dist/",
39
+ "docs/_layouts/",
40
+ "node_modules/",
41
+ "patches/",
42
+ "pnpm-lock.yaml/",
43
+ "Swabble/",
44
+ "vendor/",
45
+ "**/*.min.js",
46
+ ],
47
+ }
package/.oxlintrc.json ADDED
@@ -0,0 +1,78 @@
1
+ {
2
+ "$schema": "../../node_modules/oxlint/configuration_schema.json",
3
+ "plugins": ["unicorn", "typescript", "oxc", "react"],
4
+ "env": {
5
+ "browser": true,
6
+ "node": true,
7
+ "es2022": true
8
+ },
9
+ "categories": {
10
+ "correctness": "error", // 代码正确性相关的规则,必须修复
11
+ "perf": "error", // 性能相关的规则,建议修复
12
+ "suspicious": "error", // 可能存在问题的代码模式,建议修复
13
+ "pedantic": "off", // 推荐设为 off:避免因为琐碎的规则干扰开发流程。
14
+ "style": "off", // 代码风格相关的规则,保持一致性,建议修复
15
+ "restriction": "off" // 可能限制开发者的规则,视项目需求开启
16
+ },
17
+ "extends": ["recommended"],
18
+ "rules": {
19
+ // --- 代码风格 ---
20
+ "curly": ["error", "multi-or-nest"], // 紧凑风格:单行不加大括号,多行嵌套才加
21
+ "eqeqeq": ["error", "always", {"null": "ignore"}], // 强制全等,但允许对 null 进行模糊匹配
22
+ "no-var": "error",
23
+ "prefer-const": "error",
24
+ "no-debugger": "off", // 开发阶段允许 debugger
25
+
26
+ /* --- 兼容旧版项目中的特殊处理 --- */
27
+ "no-console": "off", // 开发阶段允许 console
28
+ "eslint-plugin-unicorn/prefer-array-find": "off", // .filter()[0]
29
+ "eslint/no-shadow": "off", // 局部变量覆盖外层变量名
30
+ "eslint/no-await-in-loop": "off", // 循环中的 await
31
+ "eslint/no-new": "off",
32
+ "eslint/no-unmodified-loop-condition": "error", // 防止死循环
33
+ "typescript/no-unnecessary-boolean-literal-compare": "off", // 禁止不必要的布尔比较
34
+ "typescript/no-unsafe-type-assertion": "off", // as 给 TS 留一点“逃生舱”
35
+ "typescript/no-extraneous-class": "off", // 只包含静态成员的类
36
+ "typescript/no-explicit-any": "warn", // 禁止使用 any 类型
37
+
38
+ /* --- 性能与现代语法优化 (Unicorn & OXC) --- */
39
+ "oxc/no-accumulating-spread": "off", // 允许在迭代中使用解构(平衡性能与可读性)
40
+ "oxc/no-async-endpoint-handlers": "warn", // 异步后端处理函数中可能的未捕获错误
41
+ "oxc/no-map-spread": "off", // .map() 回调中直接返回解构的对象
42
+ "unicorn/consistent-function-scoping": "off", // 函数提升到最外层
43
+ "unicorn/prefer-module": "off", // 强制使用 ES 模块
44
+ "unicorn/require-post-message-target-origin": "warn", // 基本的安全防范
45
+ "unicorn/prefer-array-to-sorted": "off", // 数组排序时直接调用 .sort(),不需要先创建新数组
46
+ "unicorn/no-array-sort": "off", // 允许使用 .sort(),性能更好
47
+ "object-shorthand": ["warn", "always"], // 强制对象简写,保持代码紧凑
48
+ "arrow-body-style": ["warn", "as-needed"], // 只有必要时才写 return,缩短函数长度
49
+
50
+ /* --- React 适配 --- */
51
+ "react/jsx-no-undef": "error",
52
+ "react/react-in-jsx-scope": "off", // 现代 React (Next.js/Bun) 不需要 import React
53
+ "react/jsx-key": "error",
54
+
55
+ /* --- 变量管理 --- */
56
+ "no-unused-vars": [
57
+ "warn",
58
+ {
59
+ "vars": "local",
60
+ "args": "after-used",
61
+ "argsIgnorePattern": "^_", // 允许下划线开头的未用参数
62
+ "ignoreRestSiblings": true
63
+ }
64
+ ]
65
+ },
66
+ // 排除检查的文件/目录
67
+ "ignorePatterns": [
68
+ "**/node_modules/**",
69
+ "**/dist/**",
70
+ "**/build/**",
71
+ "**/vendor/**",
72
+ "**/assets/**",
73
+ "**/*.min.js",
74
+ "pnpm-lock.yaml",
75
+ "yarn.lock",
76
+ "package-lock.json"
77
+ ]
78
+ }
package/dist/core.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  /*!
2
- * wia core v1.2.1
3
- * (c) 2015-2025 Sibyl Yu and contributors
2
+ * wia core v1.2.3
3
+ * (c) 2015-2026 Sibyl Yu and contributors
4
4
  * Released under the MIT License.
5
5
  */
6
6
  'use strict';
@@ -2075,6 +2075,228 @@ class Event {
2075
2075
  }
2076
2076
  }
2077
2077
 
2078
+ /*!
2079
+ * wia util v3.4.25
2080
+ * (c) 2018-2024 Yan (Sibyl) Yu and Yuxi (Evan) You and wia/vue contributors
2081
+ * Released under the MIT License.
2082
+ */
2083
+ /**
2084
+ * Created by way on 10/6/16.
2085
+ * Part of the code comes from @vue/shared
2086
+ */
2087
+
2088
+
2089
+ /**
2090
+ * 前端日志输出,封装 console日志,简化代码,支持模块或直接输出
2091
+ * 调用时,描述字符串后置,便于可选缺省,输出时,自带前置,类似 后端pino,保持前后端一致性
2092
+ * m 为模块,fn 为函数名称
2093
+ */
2094
+ class Log {
2095
+ /** @type {string} 模块 */
2096
+ m = ''
2097
+
2098
+ /** @type {string} 函数 */
2099
+ fn = ''
2100
+
2101
+ /**
2102
+ * @param {string} m 模块
2103
+ */
2104
+ constructor(m) {
2105
+ this.m = m;
2106
+ }
2107
+
2108
+ /**
2109
+ * get log desc
2110
+ * 描述字符串后置调用,前置显示
2111
+ * @param {*[]} args
2112
+ * @returns {string}
2113
+ */
2114
+ getDesc(args) {
2115
+ let R = '';
2116
+ try {
2117
+ const _ = this;
2118
+ const { m } = _;
2119
+ let fn = '',
2120
+ desc = '';
2121
+
2122
+ if (args.length > 1) {
2123
+ const last = args.at(-1);
2124
+ if (typeof last === 'object') {
2125
+ ;({ desc, fn } = last);
2126
+ } else if (typeof last === 'string') desc = last;
2127
+ if (desc || fn) {
2128
+ fn = fn || _.fn;
2129
+ _.fn = fn;
2130
+ args.pop();
2131
+ }
2132
+ }
2133
+ fn = fn || _.fn;
2134
+ if (m) desc = `${desc}[${m}${fn ? ':' + fn : ''}]`; // eslint-disable-line
2135
+ R = desc;
2136
+ } catch (e) {
2137
+ console.error(`getDesc exp:${e.message}`);
2138
+ }
2139
+
2140
+ return R
2141
+ }
2142
+
2143
+ /** @param {...any} args - params */
2144
+ log(...args) {
2145
+ const _ = this;
2146
+ const last = args.at(-1);
2147
+ // clear fn
2148
+ if (args.length === 1 && typeof last === 'object' && last.fn) _.fn = '';
2149
+ else {
2150
+ const desc = _.getDesc(args);
2151
+ console.log(desc, ...args);
2152
+ }
2153
+ }
2154
+
2155
+ /** @param {...any} args - params */
2156
+ debug(...args) {
2157
+ const _ = this;
2158
+ const desc = _.getDesc(args);
2159
+ if (desc) console.log(desc, ...args);
2160
+ else console.log(...args);
2161
+ }
2162
+
2163
+ /** @param {...any} args - params */
2164
+ info(...args) {
2165
+ const _ = this;
2166
+ const desc = _.getDesc(args);
2167
+ if (desc) console.info(desc, ...args);
2168
+ else console.log(...args);
2169
+ }
2170
+
2171
+ /** @param {...any} args - params */
2172
+ warn(...args) {
2173
+ const _ = this;
2174
+ const { desc, arg } = _.getDesc(args);
2175
+ if (desc) console.warn(desc, ...arg);
2176
+ else console.log(...args);
2177
+ }
2178
+
2179
+ /** @param {...any} args - params */
2180
+ trace(...args) {
2181
+ const _ = this;
2182
+ const { desc, arg } = _.getDesc(args);
2183
+ if (desc) console.trace(desc, ...arg);
2184
+ else console.trace(...args);
2185
+ }
2186
+
2187
+ /** @param {...any} args - params */
2188
+ error(...args) {
2189
+ const _ = this;
2190
+ const desc = _.getDesc(args);
2191
+ if (desc) console.error(desc, ...args);
2192
+ else console.log(...args);
2193
+ }
2194
+
2195
+ /**
2196
+ * 用于 catch(e) log.err(e)
2197
+ * @param {...any} args - params */
2198
+ err(...args) {
2199
+ const _ = this;
2200
+ const first = args?.[0];
2201
+ if (
2202
+ first instanceof Error ||
2203
+ (first && first.message && first.cause && first.stack)
2204
+ )
2205
+ args[0] = { exp: args[0].message };
2206
+ _.error(...args);
2207
+ }
2208
+ }
2209
+
2210
+ function getDesc(args) {
2211
+ let desc = '';
2212
+ const last = args.at(-1);
2213
+ if (typeof last === 'string') {
2214
+ desc = last;
2215
+ args.pop();
2216
+ }
2217
+ return desc
2218
+ }
2219
+
2220
+ /**
2221
+ * 标准日志输出或构建模块日志类实例,用于模块中带[m:xxx]标记日志输出
2222
+ * 启用 {f:fn} 标记时,需在函数尾部清除f(log({f:''})),否则会溢出到其他函数
2223
+ * @param {...any} args - params
2224
+ * returns {*}
2225
+ */
2226
+ function log(...args) {
2227
+ const last = args.at(-1);
2228
+
2229
+ // 全局日志
2230
+ if (args.length !== 1 || !last?.m) {
2231
+ const desc = getDesc(args);
2232
+ desc ? console.log(desc, ...args) : console.log(...args);
2233
+ return
2234
+ }
2235
+
2236
+ // 唯一 m 属性,则构造新的 log 实例,这种写法,能被jsDoc识别子属性
2237
+ const lg = new Log(last?.m);
2238
+ /** @param {*} args2 */
2239
+ const R = (...args2) => lg.log(...args2);
2240
+ R.debug = lg.debug.bind(lg);
2241
+ R.info = lg.info.bind(lg);
2242
+ R.warn = lg.warn.bind(lg);
2243
+ R.info = lg.info.bind(lg);
2244
+ R.trace = lg.trace.bind(lg);
2245
+ R.error = lg.error.bind(lg);
2246
+ R.err = lg.err.bind(lg);
2247
+
2248
+ return R
2249
+ }
2250
+
2251
+ /**
2252
+ * 用于 catch(e) log.err(e)
2253
+ * @param {...any} args - params */
2254
+ log.err = (...args) => {
2255
+ const desc = getDesc(args);
2256
+ const first = args?.[0];
2257
+ if (
2258
+ first instanceof Error ||
2259
+ (first && first.message && first.cause && first.stack)
2260
+ )
2261
+ args[0] = { exp: args[0].message };
2262
+ desc ? console.error(desc, ...args) : console.error(...args);
2263
+ };
2264
+
2265
+ /**
2266
+ * @param {...any} args - params */
2267
+ log.error = (...args) => {
2268
+ const desc = getDesc(args);
2269
+ desc ? console.error(desc, ...args) : console.error(...args);
2270
+ };
2271
+
2272
+ /**
2273
+ * @param {...any} args - params */
2274
+ log.warn = (...args) => {
2275
+ const desc = getDesc(args);
2276
+ desc ? console.warn(desc, ...args) : console.warn(...args);
2277
+ };
2278
+
2279
+ /**
2280
+ * @param {...any} args - params */
2281
+ log.info = (...args) => {
2282
+ const desc = getDesc(args);
2283
+ desc ? console.info(desc, ...args) : console.info(...args);
2284
+ };
2285
+
2286
+ /**
2287
+ * @param {...any} args - params */
2288
+ log.debug = (...args) => {
2289
+ const desc = getDesc(args);
2290
+ desc ? console.log(desc, ...args) : console.log(...args);
2291
+ };
2292
+
2293
+ /**
2294
+ * @param {...any} args - params */
2295
+ log.trace = (...args) => {
2296
+ const desc = getDesc(args);
2297
+ desc ? console.trace(desc, ...args) : console.trace(...args);
2298
+ };
2299
+
2078
2300
  /**
2079
2301
  * 所有页面从该类继承,并必须实现 load 事件!
2080
2302
  * 事件
@@ -2145,16 +2367,16 @@ class Page extends Event {
2145
2367
  * 在已经加载就绪的视图上操作
2146
2368
  * @param {*} view 页面层的 Dom 对象,已经使用`$(#page-name)`,做了处理
2147
2369
  * @param {*} param go 函数的参数,或 网址中 url 中的参数
2148
- * @param {*} back 是否为回退,A->B, B->A,这种操作属于回退
2370
+ * @param {*} lastPath 前路由的路径,go 函数的参数,或 网址中 url 中的参数
2149
2371
  */
2150
- ready(view, param, back) {
2372
+ ready(view, param, lastPath) {
2151
2373
  // $.assign(this, {page, param, back});
2152
2374
  // $.assign(this.data, param);
2153
2375
  // 隐藏所有模板
2154
2376
  this.init();
2155
- this.emit('local::ready', view, param, back);
2377
+ this.emit('local::ready', view, param, lastPath);
2156
2378
  // 向上触发跨页面事件,存在安全问题
2157
- this.emit('pageReady', this, view, param, back);
2379
+ this.emit('pageReady', this, view, param, lastPath);
2158
2380
  }
2159
2381
 
2160
2382
  /**
@@ -2168,29 +2390,29 @@ class Page extends Event {
2168
2390
 
2169
2391
  // 显示已加载的页面
2170
2392
  // view:页面Dom层,param:参数
2171
- show(view, param) {
2393
+ show(view, param, lastPath) {
2172
2394
  // 隐藏所有模板
2173
2395
  view.qus('[name$=-tp]').hide();
2174
2396
  // 防止空链接,刷新页面
2175
2397
  view.qus('a[href=""]').attr('href', 'javascript:;');
2176
2398
  // this.init();
2177
2399
  if (this.reset) this.reset();
2178
- this.emit('local::show', view, param);
2400
+ this.emit('local::show', view, param, lastPath);
2179
2401
  // 向上触发跨页面事件,存在安全问题
2180
- this.emit('pageShow', this, view, param);
2402
+ this.emit('pageShow', this, view, param, lastPath);
2181
2403
  }
2182
2404
 
2183
2405
  // 回退显示已加载的页面
2184
2406
  // view:页面Dom层,param:参数
2185
- back(view, param) {
2407
+ back(view, param, lastPath) {
2186
2408
  // 隐藏所有模板
2187
2409
  view.qus('[name$=-tp]').hide();
2188
2410
  // 防止空链接,刷新页面
2189
2411
  view.qus('a[href=""]').attr('href', 'javascript:;');
2190
2412
 
2191
- this.emit('local::back', view, param);
2413
+ this.emit('local::back', view, param, lastPath);
2192
2414
  // 向上触发跨页面事件,存在安全问题
2193
- this.emit('pageBack', this, view, param);
2415
+ this.emit('pageBack', this, view, param, lastPath);
2194
2416
  }
2195
2417
 
2196
2418
  change(view, param, lastParam) {
@@ -2212,6 +2434,77 @@ class Page extends Event {
2212
2434
  }
2213
2435
  }
2214
2436
 
2437
+ /**
2438
+ * 页面工厂函数
2439
+ * 自动处理类的继承、日志注入、生命周期事件绑定
2440
+ * @param {Object} def - 页面默认配置
2441
+ * @param {Object} hooks - 业务钩子函数集合 { init, bind, show... }
2442
+ */
2443
+ function page(def, hooks = {}) {
2444
+ // 自动根据配置创建当前页面的专属日志实例
2445
+ const _log = log({m: `${def.name}`});
2446
+
2447
+ return class extends Page {
2448
+ constructor(opts = {}) {
2449
+ const opt = {...def, ...opts};
2450
+ super(opt.app, opt.name, opt.title);
2451
+ this.opt = opt;
2452
+
2453
+ // ✨ 魔法 1:利用 page.js 内置的 Event 机制,全自动挂载无侵入日志!
2454
+ this.on('local::load', param => _log({param}, 'load'));
2455
+ this.on('local::ready', (v, param, lastPath) => _log({v, param, lastPath, id: this.id}, 'ready'));
2456
+ this.on('local::show', (v, param, lastPath) => _log({v, param, lastPath, id: this.id}, 'show'));
2457
+ this.on('local::change', (v, param, lastParam) => _log({v, param, lastParam}, 'change'));
2458
+ this.on('local::back', (v, param, lastPath) => _log({v, param, lastPath, id: this.id}, 'back'));
2459
+ this.on('local::hide', v => _log({v, id: this.id}, 'hide'));
2460
+ this.on('local::unload', v => _log({v, id: this.id}, 'unload'));
2461
+ }
2462
+
2463
+ // 映射其他生命周期到业务 hooks
2464
+ load(param) {
2465
+ super.load(param);
2466
+ if (hooks.load) hooks.load({param, pg: this, log: _log});
2467
+ }
2468
+
2469
+ // ✨ 魔法 2:统一调度业务代码的 init 和 bind,提供优雅的上下文
2470
+ async ready(v, param, lastPath) {
2471
+ super.ready(v, param, lastPath);
2472
+
2473
+ // 组装上下文对象供业务使用
2474
+ const ctx = {v, pg: this, param, lastPath, log: _log};
2475
+
2476
+ // 自动按顺序执行业务层的初始化和事件绑定
2477
+ if (hooks.init) await hooks.init(ctx);
2478
+ if (hooks.bind) hooks.bind(ctx);
2479
+ }
2480
+
2481
+ show(v, param, lastPath) {
2482
+ super.show(v, param, lastPath);
2483
+ if (hooks.show) hooks.show({v, pg: this, param, lastPath, log: _log});
2484
+ }
2485
+
2486
+ change(v, param, lastParam) {
2487
+ super.change(v, param, lastParam);
2488
+ if (hooks.change) hooks.change({v, pg: this, param, lastParam, log: _log});
2489
+ }
2490
+
2491
+ back(v, param, lastPath) {
2492
+ super.back(v, param, lastPath);
2493
+ if (hooks.back) hooks.back({v, pg: this, param, lastPath, log: _log});
2494
+ }
2495
+
2496
+ hide(v, param) {
2497
+ super.hide(v, param);
2498
+ if (hooks.hide) hooks.hide({v, pg: this, param, log: _log});
2499
+ }
2500
+
2501
+ unload(v) {
2502
+ super.unload(v);
2503
+ if (hooks.unload) hooks.unload({v, pg: this, log: _log});
2504
+ }
2505
+ }
2506
+ }
2507
+
2215
2508
  /**
2216
2509
  * Wia app、router等继承类,通过模块化扩展类功能
2217
2510
  * 使用 use 装载,注解可能完成类似功能
@@ -4420,3 +4713,4 @@ exports.Support = Support;
4420
4713
  exports.Utils = Utils;
4421
4714
  exports.jsx = jsx;
4422
4715
  exports.loadModule = loadModule;
4716
+ exports.page = page;