@wiajs/core 1.1.31 → 1.1.32

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/core.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * wia core v1.1.31
2
+ * wia core v1.1.32
3
3
  * (c) 2015-2025 Sibyl Yu and contributors
4
4
  * Released under the MIT License.
5
5
  */
package/dist/core.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * wia core v1.1.31
2
+ * wia core v1.1.32
3
3
  * (c) 2015-2025 Sibyl Yu and contributors
4
4
  * Released under the MIT License.
5
5
  */
package/dist/core.min.js CHANGED
@@ -1,10 +1,10 @@
1
1
  /*!
2
- * wia core v1.1.31
2
+ * wia core v1.1.32
3
3
  * (c) 2015-2025 Sibyl Yu and contributors
4
4
  * Released under the MIT License.
5
5
  */
6
6
  /*!
7
- * wia core v1.1.31
7
+ * wia core v1.1.32
8
8
  * (c) 2015-2025 Sibyl Yu and contributors
9
9
  * Released under the MIT License.
10
10
  */
package/dist/core.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * wia core v1.1.31
2
+ * wia core v1.1.32
3
3
  * (c) 2015-2025 Sibyl Yu and contributors
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * wia core v1.1.31
2
+ * wia core v1.1.32
3
3
  * (c) 2015-2025 Sibyl Yu and contributors
4
4
  * Released under the MIT License.
5
5
  */
@@ -16,7 +16,39 @@ function jsx(tag, {children, ...props} = {}) {
16
16
  if (typeof tag === 'function') R = tag({children, ...props});
17
17
  else if (typeof tag === 'string') {
18
18
  const attrs = props || {};
19
- const attrsString = Object.keys(attrs)
19
+ const attrsArray = [];
20
+
21
+ // 特殊处理 className 和 htmlFor
22
+ if (attrs.className) {
23
+ attrsArray.push(`class="${attrs.className}"`);
24
+ delete attrs.className;
25
+ }
26
+
27
+ if (attrs.htmlFor) {
28
+ attrsArray.push(`for="${attrs.htmlFor}"`);
29
+ delete attrs.htmlFor;
30
+ }
31
+
32
+ // 处理其他属性
33
+ for (const [key, value] of Object.entries(attrs)) {
34
+ // 跳过特殊处理的属性
35
+ if (key === 'children' || key === 'className' || key === 'htmlFor') continue;
36
+
37
+ // 处理布尔属性(如 disabled, checked 等)
38
+ if (typeof value === 'boolean') {
39
+ if (value) {
40
+ attrsArray.push(key);
41
+ }
42
+ }
43
+ // 处理动态值属性
44
+ else if (value != null) {
45
+ attrsArray.push(`${key}="${value}"`);
46
+ }
47
+ }
48
+
49
+ const attrsString = attrsArray.join(' ');
50
+
51
+ /* const attrsString = Object.keys(attrs)
20
52
  .map(attr => {
21
53
  if (attr[0] === '_') {
22
54
  if (attrs[attr]) return attr.replace('_', '');
@@ -26,18 +58,20 @@ function jsx(tag, {children, ...props} = {}) {
26
58
  })
27
59
  .filter(attr => !!attr)
28
60
  .join(' ');
29
-
30
- if (['path', 'img', 'circle', 'polygon', 'line', 'input'].indexOf(tag) >= 0)
61
+ */
62
+ // 自闭合标签处理
63
+ const voidElements = ['input', 'img', 'br', 'hr', 'meta', 'link', 'area', 'base', 'col', 'embed', 'param', 'source', 'track', 'wbr', 'path', 'circle', 'polygon', 'line', 'rect', 'ellipse', 'use', 'stop'];
64
+ if (voidElements.includes(tag))
31
65
  R = `<${tag} ${attrsString} />`.trim();
32
66
  else {
33
67
  const childrenContent = Array.isArray(children)
34
68
  ? children
35
- .filter(c => !!c)
69
+ .filter(c => c != null)
36
70
  .map(c => (Array.isArray(c) ? c.join('') : c))
37
71
  .join('')
38
- : children;
72
+ : children || '';
39
73
 
40
- R = `<${tag} ${attrsString}>${childrenContent ?? ''}</${tag}>`.trim();
74
+ R = `<${tag} ${attrsString}>${childrenContent}</${tag}>`.trim();
41
75
  }
42
76
  }
43
77
 
@@ -47,12 +81,12 @@ function jsx(tag, {children, ...props} = {}) {
47
81
  function Fragment({children} = {}) {
48
82
  const R = Array.isArray(children)
49
83
  ? children
50
- .filter(c => !!c)
84
+ .filter(c => c != null)
51
85
  .map(c => (Array.isArray(c) ? c.join('') : c))
52
86
  .join('')
53
- : children;
87
+ : children || '';
54
88
 
55
- return R ?? '';
89
+ return R;
56
90
  }
57
91
 
58
92
  var Fragment_1 = jsxRuntime.Fragment = Fragment;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wiajs/core",
3
- "version": "1.1.31",
3
+ "version": "1.1.32",
4
4
  "description": "wia app core package",
5
5
  "main": "./dist/core.cjs",
6
6
  "module": "./dist/core.mjs",
package/util/tool.js CHANGED
@@ -130,43 +130,47 @@ function newFileName(len) {
130
130
 
131
131
  /**
132
132
  * 比较方法,用于对象数组排序,常用于数据表排序
133
- * @param {*} k 对象属性key
134
- * @param {*} asc 升序、降序,默认升序
135
- * @param {*} type 类型auto, number、datetime、string,缺省 auto
133
+ * @param {string} k 对象属性key
134
+ * @param {boolean} desc 升序、降序,默认升序
135
+ * @param {string} type 类型auto, number、date、string,缺省 auto
136
+ * @param {string} [sub] 子对象
136
137
  */
137
- function compareObj(k, desc, type) {
138
- return function (o1, o2) {
139
- let R = 0;
140
- try {
141
- let v1 = o1[k];
142
- let v2 = o2[k];
143
- // 数字、日期字符串,按数字、日期排序
144
- if ($.isStr(v1) || $.isStr(v2)) {
145
- // 金额可能有千字分隔符,需替换
146
- if (type.toLowerCase() === 'number') {
147
- v1 = v1.replaceAll(',', '');
148
- v2 = v2.replaceAll(',', '');
149
- }
150
-
151
- if ($.isDateStr(v1) && $.isDateStr(v2)) {
152
- v1 = Date.parse(v1);
153
- v2 = Date.parse(v2);
154
- } else if ($.isNumStr(v1) && $.isNumStr(v2)) {
155
- v1 = Number(v1);
156
- v2 = Number(v2);
157
- }
158
- }
159
-
160
- if (v1 < v2) {
161
- R = desc ? 1 : -1;
162
- } else if (v1 > v2) {
163
- R = desc ? -1 : 1;
164
- }
165
- } catch(ex) {
166
- console.log('compareObj exp:', ex.message);
167
- }
168
- return R;
169
- };
138
+ function compareObj(k, desc, type, sub) {
139
+ return (o1, o2) => {
140
+ let R = 0
141
+ try {
142
+ let v1 = sub ? o1[sub][k] : o1[k]
143
+ let v2 = sub ? o2[sub][k] : o2[k]
144
+
145
+ // log({v1, v2, type}, 'compareObj')
146
+
147
+ if (typeof v1 === 'string' || typeof v2 === 'string') {
148
+ // 数字、日期字符串,按数字、日期排序
149
+ // 金额可能有千字分隔符,需替换
150
+ if (type.toLowerCase() === 'number') {
151
+ if (typeof v1 === 'string') {
152
+ v1 = v1.replaceAll(',', '').replaceAll(/null|-|^$/g, '0')
153
+ v1 = Number(v1)
154
+ }
155
+ if (typeof v2 === 'string') {
156
+ v2 = v2.replaceAll(',', '').replaceAll(/null|-|^$/g, '0')
157
+ v2 = Number(v2)
158
+ }
159
+ } else if (type.toLowerCase() === 'date') {
160
+ v1 = Date.parse(v1)
161
+ v2 = Date.parse(v2)
162
+ }
163
+ }
164
+
165
+ if (v1 < v2) R = desc ? 1 : -1
166
+ else if (v1 > v2) R = desc ? -1 : 1
167
+
168
+ // log({v1, v2, R}, 'compareObj')
169
+ } catch (ex) {
170
+ console.log('compareObj exp:', ex.message)
171
+ }
172
+ return R
173
+ }
170
174
  }
171
175
 
172
176
  /**