hy-dispatch-ui-v3 0.2.1 → 0.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/es/components/appConfigProvider/appConfigProvider.vue.mjs +3 -1
- package/es/components/appDatePicker/appDatePicker.vue.mjs +57 -3
- package/es/components/appDatePicker/index.mjs +2 -1
- package/es/components/appForm/cpns/appFormItem.vue.mjs +37 -7
- package/es/components/appForm/js/useAppForm.mjs +5 -40
- package/es/components/appIcon/appIcon.vue.mjs +5 -1
- package/es/components/appInput/appInput.vue.mjs +17 -15
- package/es/components/appInput/index.mjs +2 -1
- package/es/components/appSearch/cpns/appSearchItem.vue.mjs +33 -3
- package/es/components/appSearch/js/index.mjs +1 -1
- package/es/components/appSearch/js/useAppSearch.mjs +9 -39
- package/es/components/appTimePicker/appTimePicker.vue.mjs +154 -0
- package/es/components/appTimePicker/index.mjs +7 -0
- package/es/components/appTimePicker/style/appTimePicker.scss +0 -0
- package/es/components/appTree/appTree.vue.mjs +11 -8
- package/es/components/appTree/config/tree-config.mjs +33 -0
- package/es/components/appTree/js/index.mjs +10 -12
- package/es/components/appVideoPlayer/appVideoPlayer.vue.mjs +6 -6
- package/es/components/index.mjs +3 -2
- package/es/hooks/index.mjs +1 -0
- package/es/hooks/useEnsureHyIcon.mjs +12 -0
- package/es/hooks/useGlobalConfig.mjs +5 -0
- package/es/index.mjs +4 -2
- package/es/locale/en.mjs +21 -11
- package/es/locale/zh_CN.mjs +21 -11
- package/es/static/_sprite.js +33 -0
- package/es/static/hy-svg-icons/ai.js +30 -0
- package/es/static/hy-svg-icons/batch.js +8 -0
- package/es/static/hy-svg-icons.js +10 -10
- package/es/static/index.js +2 -2
- package/es/static/protocolcheck.js +109 -85
- package/es/static/vite-plugin-hy-svg-icons.js +240 -0
- package/es/utils/date.mjs +1 -0
- package/es/utils/handler.mjs +2 -2
- package/es/version.mjs +1 -1
- package/lib/components/appConfigProvider/appConfigProvider.vue.js +3 -1
- package/lib/components/appDatePicker/appDatePicker.vue.js +56 -2
- package/lib/components/appDatePicker/index.js +2 -0
- package/lib/components/appForm/cpns/appFormItem.vue.js +38 -8
- package/lib/components/appForm/js/useAppForm.js +5 -40
- package/lib/components/appIcon/appIcon.vue.js +4 -0
- package/lib/components/appInput/appInput.vue.js +17 -15
- package/lib/components/appInput/index.js +2 -0
- package/lib/components/appSearch/cpns/appSearchItem.vue.js +34 -4
- package/lib/components/appSearch/js/index.js +1 -1
- package/lib/components/appSearch/js/useAppSearch.js +9 -39
- package/lib/components/appTimePicker/appTimePicker.vue.js +158 -0
- package/lib/components/appTimePicker/index.js +13 -0
- package/lib/components/appTimePicker/style/appTimePicker.scss +0 -0
- package/lib/components/appTree/appTree.vue.js +10 -7
- package/lib/components/appTree/config/tree-config.js +37 -0
- package/lib/components/appTree/js/index.js +10 -12
- package/lib/components/appVideoPlayer/appVideoPlayer.vue.js +6 -6
- package/lib/components/index.js +13 -8
- package/lib/hooks/index.js +3 -0
- package/lib/hooks/useEnsureHyIcon.js +15 -0
- package/lib/hooks/useGlobalConfig.js +5 -0
- package/lib/index.js +16 -8
- package/lib/locale/en.js +21 -11
- package/lib/locale/zh_CN.js +21 -11
- package/lib/static/_sprite.js +33 -0
- package/lib/static/hy-svg-icons/ai.js +30 -0
- package/lib/static/hy-svg-icons/batch.js +8 -0
- package/lib/static/hy-svg-icons.js +10 -12
- package/lib/static/index.js +2 -5
- package/lib/static/protocolcheck.js +109 -87
- package/lib/static/vite-plugin-hy-svg-icons.js +240 -0
- package/lib/utils/date.js +1 -0
- package/lib/utils/handler.js +2 -2
- package/lib/version.js +1 -1
- package/package.json +3 -3
package/lib/static/index.js
CHANGED
|
@@ -1,39 +1,38 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
(function (f) {
|
|
1
|
+
;(function (f) {
|
|
4
2
|
if (typeof exports === 'object' && typeof module !== 'undefined') {
|
|
5
|
-
module.exports = f()
|
|
3
|
+
module.exports = f()
|
|
6
4
|
} else if (typeof define === 'function' && define.amd) {
|
|
7
|
-
define([], f)
|
|
5
|
+
define([], f)
|
|
8
6
|
} else {
|
|
9
|
-
var g
|
|
7
|
+
var g
|
|
10
8
|
if (typeof window !== 'undefined') {
|
|
11
|
-
g = window
|
|
9
|
+
g = window
|
|
12
10
|
} else if (typeof global !== 'undefined') {
|
|
13
|
-
g = global
|
|
11
|
+
g = global
|
|
14
12
|
} else if (typeof self !== 'undefined') {
|
|
15
|
-
g = self
|
|
13
|
+
g = self
|
|
16
14
|
} else {
|
|
17
|
-
g = this
|
|
15
|
+
g = this
|
|
18
16
|
}
|
|
19
|
-
g.protocolCheck = f()
|
|
17
|
+
g.protocolCheck = f()
|
|
20
18
|
}
|
|
21
19
|
})(function () {
|
|
20
|
+
var define, module, exports
|
|
22
21
|
return (function e(t, n, r) {
|
|
23
22
|
function s(o, u) {
|
|
24
23
|
if (!n[o]) {
|
|
25
24
|
if (!t[o]) {
|
|
26
|
-
var a = typeof require == 'function' && require
|
|
27
|
-
if (!u && a) return a(o,
|
|
28
|
-
if (i) return i(o,
|
|
29
|
-
var f = new Error("Cannot find module '" + o + "'")
|
|
25
|
+
var a = typeof require == 'function' && require
|
|
26
|
+
if (!u && a) return a(o, !0)
|
|
27
|
+
if (i) return i(o, !0)
|
|
28
|
+
var f = new Error("Cannot find module '" + o + "'")
|
|
30
29
|
throw ((f.code = 'MODULE_NOT_FOUND'), f)
|
|
31
30
|
}
|
|
32
|
-
var l = (n[o] = { exports: {} })
|
|
31
|
+
var l = (n[o] = { exports: {} })
|
|
33
32
|
t[o][0].call(
|
|
34
33
|
l.exports,
|
|
35
34
|
function (e) {
|
|
36
|
-
var n = t[o][1][e]
|
|
35
|
+
var n = t[o][1][e]
|
|
37
36
|
return s(n ? n : e)
|
|
38
37
|
},
|
|
39
38
|
l,
|
|
@@ -42,141 +41,164 @@
|
|
|
42
41
|
t,
|
|
43
42
|
n,
|
|
44
43
|
r
|
|
45
|
-
)
|
|
44
|
+
)
|
|
46
45
|
}
|
|
47
46
|
return n[o].exports
|
|
48
47
|
}
|
|
49
|
-
var i = typeof require == 'function' && require
|
|
50
|
-
for (var o = 0; o < r.length; o++) s(r[o])
|
|
48
|
+
var i = typeof require == 'function' && require
|
|
49
|
+
for (var o = 0; o < r.length; o++) s(r[o])
|
|
51
50
|
return s
|
|
52
51
|
})(
|
|
53
52
|
{
|
|
54
53
|
1: [
|
|
55
|
-
function (require, module, exports
|
|
54
|
+
function (require, module, exports) {
|
|
56
55
|
function _registerEvent(target, eventType, cb) {
|
|
57
56
|
if (target.addEventListener) {
|
|
58
|
-
target.addEventListener(eventType, cb)
|
|
57
|
+
target.addEventListener(eventType, cb)
|
|
59
58
|
return {
|
|
60
59
|
remove: function () {
|
|
61
|
-
target.removeEventListener(eventType, cb)
|
|
60
|
+
target.removeEventListener(eventType, cb)
|
|
62
61
|
},
|
|
63
62
|
}
|
|
64
63
|
} else {
|
|
65
|
-
target.attachEvent(eventType, cb)
|
|
64
|
+
target.attachEvent(eventType, cb)
|
|
66
65
|
return {
|
|
67
66
|
remove: function () {
|
|
68
|
-
target.detachEvent(eventType, cb)
|
|
67
|
+
target.detachEvent(eventType, cb)
|
|
69
68
|
},
|
|
70
69
|
}
|
|
71
70
|
}
|
|
72
71
|
}
|
|
73
72
|
|
|
74
73
|
function _createHiddenIframe(target, uri) {
|
|
75
|
-
var iframe = document.createElement('iframe')
|
|
76
|
-
iframe.src = uri
|
|
77
|
-
iframe.id = 'hiddenIframe'
|
|
78
|
-
iframe.style.display = 'none'
|
|
79
|
-
target.appendChild(iframe)
|
|
74
|
+
var iframe = document.createElement('iframe')
|
|
75
|
+
iframe.src = uri
|
|
76
|
+
iframe.id = 'hiddenIframe'
|
|
77
|
+
iframe.style.display = 'none'
|
|
78
|
+
target.appendChild(iframe)
|
|
80
79
|
|
|
81
80
|
return iframe
|
|
82
81
|
}
|
|
83
82
|
|
|
84
83
|
function openUriWithHiddenFrame(uri, failCb, successCb) {
|
|
85
84
|
var timeout = setTimeout(function () {
|
|
86
|
-
failCb()
|
|
87
|
-
handler.remove()
|
|
88
|
-
}, 1000)
|
|
85
|
+
failCb()
|
|
86
|
+
handler.remove()
|
|
87
|
+
}, 1000)
|
|
89
88
|
|
|
90
|
-
var iframe = document.querySelector('#hiddenIframe')
|
|
89
|
+
var iframe = document.querySelector('#hiddenIframe')
|
|
91
90
|
if (!iframe) {
|
|
92
|
-
iframe = _createHiddenIframe(document.body, 'about:blank')
|
|
91
|
+
iframe = _createHiddenIframe(document.body, 'about:blank')
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
var handler = _registerEvent(window, 'blur', onBlur)
|
|
95
|
+
|
|
96
|
+
function onBlur() {
|
|
97
|
+
clearTimeout(timeout)
|
|
98
|
+
handler.remove()
|
|
99
|
+
successCb()
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
iframe.contentWindow.location.href = uri
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function openUriWithTimeoutHack(uri, failCb, successCb) {
|
|
106
|
+
var timeout = setTimeout(function () {
|
|
107
|
+
failCb()
|
|
108
|
+
handler.remove()
|
|
109
|
+
}, 1000)
|
|
110
|
+
|
|
111
|
+
//handle page running in an iframe (blur must be registered with top level window)
|
|
112
|
+
var target = window
|
|
113
|
+
while (target != target.parent) {
|
|
114
|
+
target = target.parent
|
|
93
115
|
}
|
|
94
116
|
|
|
95
|
-
var handler = _registerEvent(
|
|
117
|
+
var handler = _registerEvent(target, 'blur', onBlur)
|
|
96
118
|
|
|
97
119
|
function onBlur() {
|
|
98
|
-
clearTimeout(timeout)
|
|
99
|
-
handler.remove()
|
|
100
|
-
successCb()
|
|
120
|
+
clearTimeout(timeout)
|
|
121
|
+
handler.remove()
|
|
122
|
+
successCb()
|
|
101
123
|
}
|
|
102
124
|
|
|
103
|
-
|
|
125
|
+
window.location = uri
|
|
104
126
|
}
|
|
105
127
|
|
|
106
128
|
function openUriUsingFirefox(uri, failCb, successCb) {
|
|
107
|
-
var iframe = document.querySelector('#hiddenIframe')
|
|
129
|
+
var iframe = document.querySelector('#hiddenIframe')
|
|
108
130
|
|
|
109
131
|
if (!iframe) {
|
|
110
|
-
iframe = _createHiddenIframe(document.body, 'about:blank')
|
|
132
|
+
iframe = _createHiddenIframe(document.body, 'about:blank')
|
|
111
133
|
}
|
|
112
134
|
|
|
113
135
|
try {
|
|
114
|
-
iframe.contentWindow.location.href = uri
|
|
115
|
-
successCb()
|
|
136
|
+
iframe.contentWindow.location.href = uri
|
|
137
|
+
successCb()
|
|
116
138
|
} catch (e) {
|
|
117
139
|
if (e.name == 'NS_ERROR_UNKNOWN_PROTOCOL') {
|
|
118
|
-
failCb()
|
|
140
|
+
failCb()
|
|
119
141
|
}
|
|
120
142
|
}
|
|
121
143
|
}
|
|
122
144
|
|
|
123
145
|
function openUriUsingIEInOlderWindows(uri, failCb, successCb) {
|
|
124
146
|
if (getInternetExplorerVersion() === 10) {
|
|
125
|
-
openUriUsingIE10InWindows7(uri, failCb, successCb)
|
|
147
|
+
openUriUsingIE10InWindows7(uri, failCb, successCb)
|
|
126
148
|
} else if (
|
|
127
149
|
getInternetExplorerVersion() === 9 ||
|
|
128
150
|
getInternetExplorerVersion() === 11
|
|
129
151
|
) {
|
|
130
|
-
openUriWithHiddenFrame(uri, failCb, successCb)
|
|
152
|
+
openUriWithHiddenFrame(uri, failCb, successCb)
|
|
131
153
|
} else {
|
|
132
|
-
openUriInNewWindowHack(uri, failCb, successCb)
|
|
154
|
+
openUriInNewWindowHack(uri, failCb, successCb)
|
|
133
155
|
}
|
|
134
156
|
}
|
|
135
157
|
|
|
136
158
|
function openUriUsingIE10InWindows7(uri, failCb, successCb) {
|
|
137
|
-
var timeout = setTimeout(failCb, 1000)
|
|
159
|
+
var timeout = setTimeout(failCb, 1000)
|
|
138
160
|
window.addEventListener('blur', function () {
|
|
139
|
-
clearTimeout(timeout)
|
|
140
|
-
successCb()
|
|
141
|
-
})
|
|
161
|
+
clearTimeout(timeout)
|
|
162
|
+
successCb()
|
|
163
|
+
})
|
|
142
164
|
|
|
143
|
-
var iframe = document.querySelector('#hiddenIframe')
|
|
165
|
+
var iframe = document.querySelector('#hiddenIframe')
|
|
144
166
|
if (!iframe) {
|
|
145
|
-
iframe = _createHiddenIframe(document.body, 'about:blank')
|
|
167
|
+
iframe = _createHiddenIframe(document.body, 'about:blank')
|
|
146
168
|
}
|
|
147
169
|
try {
|
|
148
|
-
iframe.contentWindow.location.href = uri
|
|
170
|
+
iframe.contentWindow.location.href = uri
|
|
149
171
|
} catch (e) {
|
|
150
|
-
failCb()
|
|
151
|
-
clearTimeout(timeout)
|
|
172
|
+
failCb()
|
|
173
|
+
clearTimeout(timeout)
|
|
152
174
|
}
|
|
153
175
|
}
|
|
154
176
|
|
|
155
177
|
function openUriInNewWindowHack(uri, failCb, successCb) {
|
|
156
|
-
var myWindow = window.open('', '', 'width=0,height=0')
|
|
178
|
+
var myWindow = window.open('', '', 'width=0,height=0')
|
|
157
179
|
|
|
158
|
-
myWindow.document.write("<iframe src='" + uri + "'></iframe>")
|
|
180
|
+
myWindow.document.write("<iframe src='" + uri + "'></iframe>")
|
|
159
181
|
|
|
160
182
|
setTimeout(function () {
|
|
161
183
|
try {
|
|
162
|
-
myWindow.location.href
|
|
163
|
-
myWindow.setTimeout('window.close()', 1000)
|
|
164
|
-
successCb()
|
|
184
|
+
myWindow.location.href
|
|
185
|
+
myWindow.setTimeout('window.close()', 1000)
|
|
186
|
+
successCb()
|
|
165
187
|
} catch (e) {
|
|
166
|
-
myWindow.close()
|
|
167
|
-
failCb()
|
|
188
|
+
myWindow.close()
|
|
189
|
+
failCb()
|
|
168
190
|
}
|
|
169
|
-
}, 1000)
|
|
191
|
+
}, 1000)
|
|
170
192
|
}
|
|
171
193
|
|
|
172
194
|
function openUriWithMsLaunchUri(uri, failCb, successCb) {
|
|
173
|
-
navigator.msLaunchUri(uri, successCb, failCb)
|
|
195
|
+
navigator.msLaunchUri(uri, successCb, failCb)
|
|
174
196
|
}
|
|
175
197
|
|
|
176
198
|
function checkBrowser() {
|
|
177
199
|
var isOpera =
|
|
178
|
-
!!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0
|
|
179
|
-
var ua = navigator.userAgent.toLowerCase()
|
|
200
|
+
!!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0
|
|
201
|
+
var ua = navigator.userAgent.toLowerCase()
|
|
180
202
|
return {
|
|
181
203
|
isOpera: isOpera,
|
|
182
204
|
isFirefox: typeof InstallTrigger !== 'undefined',
|
|
@@ -189,21 +211,21 @@
|
|
|
189
211
|
/iPad|iPhone|iPod/.test(navigator.userAgent) &&
|
|
190
212
|
!window.MSStream,
|
|
191
213
|
isChrome: !!window.chrome && !isOpera,
|
|
192
|
-
isIE: /*@cc_on!@*/ !!document.documentMode, // At least IE6
|
|
214
|
+
isIE: /*@cc_on!@*/ false || !!document.documentMode, // At least IE6
|
|
193
215
|
}
|
|
194
216
|
}
|
|
195
217
|
|
|
196
218
|
function getInternetExplorerVersion() {
|
|
197
|
-
var rv = -1
|
|
219
|
+
var rv = -1
|
|
198
220
|
if (navigator.appName === 'Microsoft Internet Explorer') {
|
|
199
|
-
var ua = navigator.userAgent
|
|
200
|
-
var re = new RegExp('MSIE ([0-9]{1,}[\.0-9]{0,})')
|
|
201
|
-
if (re.exec(ua) != null) rv = parseFloat(RegExp.$1)
|
|
221
|
+
var ua = navigator.userAgent
|
|
222
|
+
var re = new RegExp('MSIE ([0-9]{1,}[\.0-9]{0,})')
|
|
223
|
+
if (re.exec(ua) != null) rv = parseFloat(RegExp.$1)
|
|
202
224
|
} else if (navigator.appName === 'Netscape') {
|
|
203
|
-
var ua = navigator.userAgent
|
|
204
|
-
var re = new RegExp('Trident/.*rv:([0-9]{1,}[\.0-9]{0,})')
|
|
225
|
+
var ua = navigator.userAgent
|
|
226
|
+
var re = new RegExp('Trident/.*rv:([0-9]{1,}[\.0-9]{0,})')
|
|
205
227
|
if (re.exec(ua) != null) {
|
|
206
|
-
rv = parseFloat(RegExp.$1)
|
|
228
|
+
rv = parseFloat(RegExp.$1)
|
|
207
229
|
}
|
|
208
230
|
}
|
|
209
231
|
return rv
|
|
@@ -211,34 +233,34 @@
|
|
|
211
233
|
|
|
212
234
|
module.exports = function (uri, failCb, successCb, unsupportedCb) {
|
|
213
235
|
function failCallback() {
|
|
214
|
-
failCb && failCb()
|
|
236
|
+
failCb && failCb()
|
|
215
237
|
}
|
|
216
238
|
|
|
217
239
|
function successCallback() {
|
|
218
|
-
successCb && successCb()
|
|
240
|
+
successCb && successCb()
|
|
219
241
|
}
|
|
220
242
|
|
|
221
243
|
if (navigator.msLaunchUri) {
|
|
222
244
|
//for IE and Edge in Win 8 and Win 10
|
|
223
|
-
openUriWithMsLaunchUri(uri, failCb, successCb)
|
|
245
|
+
openUriWithMsLaunchUri(uri, failCb, successCb)
|
|
224
246
|
} else {
|
|
225
|
-
var browser = checkBrowser()
|
|
247
|
+
var browser = checkBrowser()
|
|
226
248
|
|
|
227
249
|
if (browser.isFirefox) {
|
|
228
|
-
openUriUsingFirefox(uri, failCallback, successCallback)
|
|
250
|
+
openUriUsingFirefox(uri, failCallback, successCallback)
|
|
229
251
|
} else if (browser.isChrome || browser.isIOS) {
|
|
230
252
|
// openUriWithTimeoutHack(uri, failCallback, successCallback);
|
|
231
|
-
openUriWithHiddenFrame(uri, failCallback, successCallback)
|
|
253
|
+
openUriWithHiddenFrame(uri, failCallback, successCallback)
|
|
232
254
|
} else if (browser.isIE) {
|
|
233
|
-
openUriUsingIEInOlderWindows(uri, failCallback, successCallback)
|
|
255
|
+
openUriUsingIEInOlderWindows(uri, failCallback, successCallback)
|
|
234
256
|
} else if (browser.isSafari) {
|
|
235
|
-
openUriWithHiddenFrame(uri, failCallback, successCallback)
|
|
257
|
+
openUriWithHiddenFrame(uri, failCallback, successCallback)
|
|
236
258
|
} else {
|
|
237
|
-
unsupportedCb()
|
|
259
|
+
unsupportedCb()
|
|
238
260
|
//not supported, implement please
|
|
239
261
|
}
|
|
240
262
|
}
|
|
241
|
-
}
|
|
263
|
+
}
|
|
242
264
|
},
|
|
243
265
|
{},
|
|
244
266
|
],
|
|
@@ -246,4 +268,4 @@
|
|
|
246
268
|
{},
|
|
247
269
|
[1]
|
|
248
270
|
)(1)
|
|
249
|
-
})
|
|
271
|
+
})
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
|
|
4
|
+
const STATIC_VIRTUAL_ID = 'virtual:hy-svg-icons';
|
|
5
|
+
const REGISTRY_VIRTUAL_ID = 'virtual:hy-svg-icons/registry';
|
|
6
|
+
const STATIC_RESOLVED_ID = '\0' + STATIC_VIRTUAL_ID;
|
|
7
|
+
const REGISTRY_RESOLVED_ID = '\0' + REGISTRY_VIRTUAL_ID;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* 扫描源码里出现的 svg-name 字面量,结合 hy-svg-icons/ 目录下每个图标文件的
|
|
11
|
+
* 顶层 id(形如 'hy-icon-<svg-name>')做白名单匹配,生成两个虚拟模块:
|
|
12
|
+
*
|
|
13
|
+
* virtual:hy-svg-icons — 静态注入:把用到的图标 import + registerSymbol 一次注册进 sprite。
|
|
14
|
+
* virtual:hy-svg-icons/registry — 完整注册表:{ svgName: () => import(iconFile) },用于 AppIcon 动态兜底。
|
|
15
|
+
*
|
|
16
|
+
* 数据源:每个图标一个文件,形如 src/assets/hy-svg-icons/<name>.js
|
|
17
|
+
* export default {
|
|
18
|
+
* id: 'hy-icon-<svg-name>',
|
|
19
|
+
* defs?: `...`,
|
|
20
|
+
* symbol: `...`,
|
|
21
|
+
* }
|
|
22
|
+
*
|
|
23
|
+
* 只有 hy-icon- 前缀是固定的(由 AppIcon 拼接),svg-name 内部结构不做假设。
|
|
24
|
+
*/
|
|
25
|
+
export function hySvgIconsPlugin(options = {}) {
|
|
26
|
+
const {
|
|
27
|
+
dataDir = 'src/assets/hy-svg-icons',
|
|
28
|
+
spriteFile = 'src/assets/hy-svg-icons/_sprite.js',
|
|
29
|
+
scanDirs = ['src'],
|
|
30
|
+
exts = ['vue', 'js', 'ts', 'jsx', 'tsx'],
|
|
31
|
+
idPrefix = 'hy-icon-',
|
|
32
|
+
} = options;
|
|
33
|
+
|
|
34
|
+
let projectRoot = process.cwd();
|
|
35
|
+
let dataDirAbs = '';
|
|
36
|
+
/** svg-name (id 去 hy-icon- 前缀) -> 数据文件绝对路径 */
|
|
37
|
+
let available = new Map();
|
|
38
|
+
/** 数据文件绝对路径集合,用于源码扫描时跳过自己 */
|
|
39
|
+
let dataFilesAbs = new Set();
|
|
40
|
+
let used = new Set();
|
|
41
|
+
let server = null;
|
|
42
|
+
|
|
43
|
+
const extSet = new Set(exts.map((e) => '.' + e));
|
|
44
|
+
const escapedIdPrefix = idPrefix.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
45
|
+
|
|
46
|
+
// 数据文件里的顶层 id:行首缩进 + `id:` + 引号 + hy-icon-XXX + 引号
|
|
47
|
+
// multiline 模式,只匹配"作为对象键"的 id,绕过 SVG 内嵌 id="..." 的干扰
|
|
48
|
+
function makeIdRe() {
|
|
49
|
+
return new RegExp(`^\\s*id:\\s*['"]${escapedIdPrefix}([A-Za-z0-9_-]+)['"]`, 'm');
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// 源码里 svg-name 候选:kebab-case 至少两段(首字符字母)
|
|
53
|
+
function makeNameRe() {
|
|
54
|
+
return /[a-zA-Z][a-zA-Z0-9]*(?:-[a-zA-Z0-9]+)+/g;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async function collectDataFiles() {
|
|
58
|
+
let entries;
|
|
59
|
+
try {
|
|
60
|
+
entries = await fs.readdir(dataDirAbs, { withFileTypes: true });
|
|
61
|
+
} catch {
|
|
62
|
+
return [];
|
|
63
|
+
}
|
|
64
|
+
const out = [];
|
|
65
|
+
for (const entry of entries) {
|
|
66
|
+
if (!entry.isFile()) continue;
|
|
67
|
+
if (!entry.name.endsWith('.js')) continue;
|
|
68
|
+
// 以 _ 开头的当内部文件(如 _sprite.js)
|
|
69
|
+
if (entry.name.startsWith('_')) continue;
|
|
70
|
+
// index.js 保留给未来 re-export,不算图标数据
|
|
71
|
+
if (entry.name === 'index.js') continue;
|
|
72
|
+
out.push(path.join(dataDirAbs, entry.name));
|
|
73
|
+
}
|
|
74
|
+
return out;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
async function loadAvailable() {
|
|
78
|
+
const files = await collectDataFiles();
|
|
79
|
+
dataFilesAbs = new Set(files);
|
|
80
|
+
const map = new Map();
|
|
81
|
+
await Promise.all(
|
|
82
|
+
files.map(async (file) => {
|
|
83
|
+
try {
|
|
84
|
+
const content = await fs.readFile(file, 'utf-8');
|
|
85
|
+
const idRe = makeIdRe();
|
|
86
|
+
const m = idRe.exec(content);
|
|
87
|
+
if (m) map.set(m[1], file);
|
|
88
|
+
} catch {}
|
|
89
|
+
}),
|
|
90
|
+
);
|
|
91
|
+
available = map;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
async function walk(dir, out) {
|
|
95
|
+
let entries;
|
|
96
|
+
try {
|
|
97
|
+
entries = await fs.readdir(dir, { withFileTypes: true });
|
|
98
|
+
} catch {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
for (const entry of entries) {
|
|
102
|
+
if (entry.name === 'node_modules' || entry.name.startsWith('.')) continue;
|
|
103
|
+
const full = path.join(dir, entry.name);
|
|
104
|
+
// 数据源自身不算"使用"
|
|
105
|
+
if (dataFilesAbs.has(full)) continue;
|
|
106
|
+
if (entry.isDirectory()) {
|
|
107
|
+
await walk(full, out);
|
|
108
|
+
} else if (extSet.has(path.extname(entry.name))) {
|
|
109
|
+
out.push(full);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
async function scanUsage() {
|
|
115
|
+
const files = [];
|
|
116
|
+
for (const d of scanDirs) {
|
|
117
|
+
await walk(path.resolve(projectRoot, d), files);
|
|
118
|
+
}
|
|
119
|
+
const found = new Set();
|
|
120
|
+
await Promise.all(
|
|
121
|
+
files.map(async (file) => {
|
|
122
|
+
let content;
|
|
123
|
+
try {
|
|
124
|
+
content = await fs.readFile(file, 'utf-8');
|
|
125
|
+
} catch {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
const nameRe = makeNameRe();
|
|
129
|
+
let m;
|
|
130
|
+
while ((m = nameRe.exec(content))) {
|
|
131
|
+
if (available.has(m[0])) found.add(m[0]);
|
|
132
|
+
}
|
|
133
|
+
}),
|
|
134
|
+
);
|
|
135
|
+
return found;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function toImportPath(absPath) {
|
|
139
|
+
const rel = path.relative(projectRoot, absPath).replace(/\\/g, '/');
|
|
140
|
+
// 一律走 project-root 相对绝对路径(形如 /src/... 或 /node_modules/...)。
|
|
141
|
+
// Vite 把 / 开头的路径当作文件来服务,绕过包 exports 校验;
|
|
142
|
+
// 而裸导入 pkg/sub-path 会强制走 exports 白名单,很多包只暴露聚合入口,个文件用不了。
|
|
143
|
+
return '/' + rel;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function toIdent(svgName) {
|
|
147
|
+
return '__hy_' + svgName.replace(/[^a-zA-Z0-9]/g, '_');
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function buildStaticModule() {
|
|
151
|
+
const names = [...used].filter((n) => available.has(n)).sort();
|
|
152
|
+
if (names.length === 0) return '// no hy-svg-icons used\n';
|
|
153
|
+
const spritePath = toImportPath(path.resolve(projectRoot, spriteFile));
|
|
154
|
+
const lines = [`import { registerSymbol } from '${spritePath}';`];
|
|
155
|
+
for (const name of names) {
|
|
156
|
+
lines.push(`import ${toIdent(name)} from '${toImportPath(available.get(name))}';`);
|
|
157
|
+
}
|
|
158
|
+
for (const name of names) {
|
|
159
|
+
lines.push(`registerSymbol(${toIdent(name)});`);
|
|
160
|
+
}
|
|
161
|
+
lines.push('');
|
|
162
|
+
return lines.join('\n');
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function buildRegistryModule() {
|
|
166
|
+
const names = [...available.keys()].sort();
|
|
167
|
+
if (names.length === 0) return 'export const registry = {};\n';
|
|
168
|
+
const lines = ['export const registry = {'];
|
|
169
|
+
for (const name of names) {
|
|
170
|
+
lines.push(` '${name}': () => import('${toImportPath(available.get(name))}'),`);
|
|
171
|
+
}
|
|
172
|
+
lines.push('};', '');
|
|
173
|
+
return lines.join('\n');
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
async function refresh() {
|
|
177
|
+
await loadAvailable();
|
|
178
|
+
const next = await scanUsage();
|
|
179
|
+
const same =
|
|
180
|
+
next.size === used.size && [...next].every((x) => used.has(x));
|
|
181
|
+
used = next;
|
|
182
|
+
return !same;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
return {
|
|
186
|
+
name: 'vite-plugin-hy-svg-icons',
|
|
187
|
+
enforce: 'pre',
|
|
188
|
+
|
|
189
|
+
configResolved(config) {
|
|
190
|
+
projectRoot = config.root || process.cwd();
|
|
191
|
+
dataDirAbs = path.resolve(projectRoot, dataDir);
|
|
192
|
+
},
|
|
193
|
+
|
|
194
|
+
async buildStart() {
|
|
195
|
+
await refresh();
|
|
196
|
+
},
|
|
197
|
+
|
|
198
|
+
resolveId(id) {
|
|
199
|
+
if (id === STATIC_VIRTUAL_ID) return STATIC_RESOLVED_ID;
|
|
200
|
+
if (id === REGISTRY_VIRTUAL_ID) return REGISTRY_RESOLVED_ID;
|
|
201
|
+
return null;
|
|
202
|
+
},
|
|
203
|
+
|
|
204
|
+
load(id) {
|
|
205
|
+
if (id === STATIC_RESOLVED_ID) return buildStaticModule();
|
|
206
|
+
if (id === REGISTRY_RESOLVED_ID) return buildRegistryModule();
|
|
207
|
+
return null;
|
|
208
|
+
},
|
|
209
|
+
|
|
210
|
+
configureServer(s) {
|
|
211
|
+
server = s;
|
|
212
|
+
},
|
|
213
|
+
|
|
214
|
+
async handleHotUpdate(ctx) {
|
|
215
|
+
const ext = path.extname(ctx.file);
|
|
216
|
+
const inDataDir = ctx.file.startsWith(dataDirAbs + path.sep);
|
|
217
|
+
if (!extSet.has(ext) && !inDataDir) return;
|
|
218
|
+
|
|
219
|
+
const changed = await refresh();
|
|
220
|
+
if (!changed || !server) return;
|
|
221
|
+
|
|
222
|
+
const staticMod = server.moduleGraph.getModuleById(STATIC_RESOLVED_ID);
|
|
223
|
+
const registryMod = server.moduleGraph.getModuleById(REGISTRY_RESOLVED_ID);
|
|
224
|
+
let invalidated = false;
|
|
225
|
+
if (staticMod) {
|
|
226
|
+
server.moduleGraph.invalidateModule(staticMod);
|
|
227
|
+
invalidated = true;
|
|
228
|
+
}
|
|
229
|
+
if (registryMod) {
|
|
230
|
+
server.moduleGraph.invalidateModule(registryMod);
|
|
231
|
+
invalidated = true;
|
|
232
|
+
}
|
|
233
|
+
if (invalidated) {
|
|
234
|
+
server.ws.send({ type: 'full-reload' });
|
|
235
|
+
}
|
|
236
|
+
},
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
export default hySvgIconsPlugin;
|
package/lib/utils/date.js
CHANGED
package/lib/utils/handler.js
CHANGED
|
@@ -74,9 +74,9 @@ function createUniqueId(n) {
|
|
|
74
74
|
}
|
|
75
75
|
return arr[0];
|
|
76
76
|
}
|
|
77
|
-
const withInstall = (comp) => {
|
|
77
|
+
const withInstall = (comp, name) => {
|
|
78
78
|
comp.install = function(app) {
|
|
79
|
-
app.component(comp.name, comp);
|
|
79
|
+
app.component(name || comp.name, comp);
|
|
80
80
|
};
|
|
81
81
|
return comp;
|
|
82
82
|
};
|
package/lib/version.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hy-dispatch-ui-v3",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"module": "es/index.mjs",
|
|
6
6
|
"scripts": {
|
|
@@ -124,8 +124,8 @@
|
|
|
124
124
|
"require": "./lib/static/index.js"
|
|
125
125
|
},
|
|
126
126
|
"./static/*": {
|
|
127
|
-
"import": "./es/static
|
|
128
|
-
"require": "./lib/static
|
|
127
|
+
"import": "./es/static/*",
|
|
128
|
+
"require": "./lib/static/*"
|
|
129
129
|
},
|
|
130
130
|
"./tailwind.css": "./dist/tailwind.css"
|
|
131
131
|
},
|