@wiajs/core 1.1.31 → 1.1.33

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.33
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.33
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.33
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.33
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.33
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.33
3
3
  * (c) 2015-2025 Sibyl Yu and contributors
4
4
  * Released under the MIT License.
5
5
  */
@@ -16,7 +16,62 @@ 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
+ // 处理 style 对象
33
+ if (attrs.style && typeof attrs.style === 'object') {
34
+ const styleArray = [];
35
+ for (const [key, value] of Object.entries(attrs.style)) {
36
+ if (value == null) continue;
37
+
38
+ // 转换驼峰式属性为CSS属性(backgroundColor -> background-color)
39
+ const cssProp = key.replace(/[A-Z]/g, m => `-${m.toLowerCase()}`);
40
+
41
+ // 处理数值属性(添加px单位)
42
+ let cssValue = value;
43
+ if (typeof value === 'number' &&
44
+ // 这些属性不需要单位
45
+ !['zIndex', 'opacity', 'fontWeight', 'flex', 'order', 'zoom'].includes(key)) {
46
+ cssValue = `${value}px`;
47
+ }
48
+
49
+ styleArray.push(`${cssProp}:${cssValue}`);
50
+ }
51
+ attrsArray.push(`style="${styleArray.join(';')}"`);
52
+ delete attrs.style;
53
+ }
54
+
55
+ // 处理其他属性
56
+ for (const [key, value] of Object.entries(attrs)) {
57
+ // 跳过特殊处理的属性
58
+ if (key === 'children' || key === 'className' || key === 'htmlFor') continue;
59
+
60
+ // 处理布尔属性(如 disabled, checked 等)
61
+ if (typeof value === 'boolean') {
62
+ if (value) {
63
+ attrsArray.push(key);
64
+ }
65
+ }
66
+ // 处理动态值属性
67
+ else if (value != null) {
68
+ attrsArray.push(`${key}="${value}"`);
69
+ }
70
+ }
71
+
72
+ const attrsString = attrsArray.join(' ');
73
+
74
+ /* const attrsString = Object.keys(attrs)
20
75
  .map(attr => {
21
76
  if (attr[0] === '_') {
22
77
  if (attrs[attr]) return attr.replace('_', '');
@@ -26,18 +81,29 @@ function jsx(tag, {children, ...props} = {}) {
26
81
  })
27
82
  .filter(attr => !!attr)
28
83
  .join(' ');
29
-
30
- if (['path', 'img', 'circle', 'polygon', 'line', 'input'].indexOf(tag) >= 0)
84
+ */
85
+ // 自闭合标签处理
86
+ const voidElements = ['input', 'img', 'br', 'hr', 'meta', 'link', 'area', 'base', 'col', 'embed', 'param', 'source', 'track', 'wbr', 'path', 'circle', 'polygon', 'line', 'rect', 'ellipse', 'use', 'stop'];
87
+ if (voidElements.includes(tag))
31
88
  R = `<${tag} ${attrsString} />`.trim();
32
89
  else {
33
90
  const childrenContent = Array.isArray(children)
34
91
  ? children
35
- .filter(c => !!c)
36
- .map(c => (Array.isArray(c) ? c.join('') : c))
92
+ .filter(c => c != null) // 只过滤 null/undefined
93
+ .map(c => {
94
+ if (Array.isArray(c)) return c.join('');
95
+
96
+ // 特殊处理布尔值(不渲染)
97
+ if (typeof c === 'boolean') return '';
98
+
99
+ return c;
100
+ })
37
101
  .join('')
38
- : children;
102
+ : children != null
103
+ ? (typeof children === 'boolean' ? '' : children)
104
+ : '';
39
105
 
40
- R = `<${tag} ${attrsString}>${childrenContent ?? ''}</${tag}>`.trim();
106
+ R = `<${tag} ${attrsString}>${childrenContent}</${tag}>`.trim();
41
107
  }
42
108
  }
43
109
 
@@ -47,12 +113,18 @@ function jsx(tag, {children, ...props} = {}) {
47
113
  function Fragment({children} = {}) {
48
114
  const R = Array.isArray(children)
49
115
  ? children
50
- .filter(c => !!c)
51
- .map(c => (Array.isArray(c) ? c.join('') : c))
116
+ .filter(c => c != null) // 只过滤 null/undefined
117
+ .map(c => {
118
+ if (Array.isArray(c)) return c.join('');
119
+ if (typeof c === 'boolean') return '';
120
+ return c;
121
+ })
52
122
  .join('')
53
- : children;
123
+ : children != null
124
+ ? (typeof children === 'boolean' ? '' : children)
125
+ : '';
54
126
 
55
- return R ?? '';
127
+ return R;
56
128
  }
57
129
 
58
130
  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.33",
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
  /**