seeder-st2110-components 1.0.0

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 ADDED
@@ -0,0 +1,1992 @@
1
+ 'use strict';
2
+
3
+ var react = require('react');
4
+ var ahooks = require('ahooks');
5
+ var antd = require('antd');
6
+ var jsxRuntime = require('react/jsx-runtime');
7
+ var icons = require('@ant-design/icons');
8
+ var axios = require('axios');
9
+
10
+ const useHardwareWebSocket = socketUrl => {
11
+ // cpu_percent cpu使用率
12
+ // cpu_freq.current cpu频率
13
+ // mem.percent 内存使用率
14
+ // sensors_temperatures.coretemp[0].current cpu温度
15
+ // gpu_stats[0]["utilization.gpu"] gpu使用率
16
+ // 若机器没有显卡,gpu_stats数组为空
17
+
18
+ const [systemStatus, setSystemStatus] = react.useState();
19
+
20
+ // ## 获取系统资源使用情况
21
+ const {
22
+ latestMessage
23
+ } = ahooks.useWebSocket(socketUrl);
24
+ const handleMessage = react.useCallback(message => {
25
+ try {
26
+ if (message) {
27
+ setSystemStatus(prev => ({
28
+ ...prev,
29
+ ...message,
30
+ lastUpdated: Date.now() // 添加更新时间戳
31
+ }));
32
+ }
33
+ } catch (error) {
34
+ console.error('Message processing error:', error);
35
+ }
36
+ }, []);
37
+
38
+ // 监听消息 如果latestMessage变化,说明有新消息
39
+ react.useEffect(() => {
40
+ if (!latestMessage?.data) return;
41
+ try {
42
+ const parsedMessage = JSON.parse(latestMessage.data);
43
+ handleMessage(parsedMessage);
44
+ } catch (error) {
45
+ console.error('Message parsing error:', error);
46
+ console.debug('Raw message:', latestMessage.data);
47
+ }
48
+ }, [latestMessage?.data, handleMessage]);
49
+ return {
50
+ ps_status: systemStatus
51
+ };
52
+ };
53
+
54
+ const UsageItem = /*#__PURE__*/react.memo(_ref => {
55
+ let {
56
+ iconClass,
57
+ text,
58
+ children,
59
+ ram
60
+ } = _ref;
61
+ const tooltipContent = react.useMemo(() => /*#__PURE__*/jsxRuntime.jsx(antd.Tooltip, {
62
+ title: /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
63
+ children: [/*#__PURE__*/jsxRuntime.jsx("div", {
64
+ children: text
65
+ }), ram && /*#__PURE__*/jsxRuntime.jsxs("div", {
66
+ children: ["Total Memory: ", ram, "GB"]
67
+ })]
68
+ }),
69
+ destroyOnHidden: false,
70
+ children: /*#__PURE__*/jsxRuntime.jsxs(antd.Space, {
71
+ size: 4,
72
+ children: [/*#__PURE__*/jsxRuntime.jsx("i", {
73
+ className: `iconfont ${iconClass} text-xl`
74
+ }), /*#__PURE__*/jsxRuntime.jsx("span", {
75
+ className: "inline-block w-10 text-center",
76
+ children: children
77
+ })]
78
+ })
79
+ }), [text, iconClass, children]);
80
+ return /*#__PURE__*/jsxRuntime.jsxs(antd.Flex, {
81
+ align: "center",
82
+ children: [tooltipContent, /*#__PURE__*/jsxRuntime.jsx(antd.Divider, {
83
+ type: "vertical"
84
+ })]
85
+ });
86
+ });
87
+
88
+ const getTemperature = (supermicro, sensors) => {
89
+ return supermicro?.cpu_temperature ?? sensors?.temperatures?.coretemp?.[0]?.current;
90
+ };
91
+ const useHardwareUsage = ps_status => {
92
+ return react.useMemo(() => {
93
+ if (!ps_status || typeof ps_status !== 'object') return null;
94
+ const {
95
+ cpu_percent,
96
+ sensors_temperatures,
97
+ mem,
98
+ gpu_stats,
99
+ supermicro
100
+ } = ps_status;
101
+ return /*#__PURE__*/jsxRuntime.jsxs("div", {
102
+ className: "flex",
103
+ children: [/*#__PURE__*/jsxRuntime.jsxs(UsageItem, {
104
+ text: "CPU Usage",
105
+ iconClass: "icon-CPU",
106
+ children: [cpu_percent, "%"]
107
+ }), /*#__PURE__*/jsxRuntime.jsxs(UsageItem, {
108
+ text: "CPU Temperature",
109
+ iconClass: "icon-wendu",
110
+ children: [getTemperature(supermicro, sensors_temperatures), "\u2103"]
111
+ }), mem && /*#__PURE__*/jsxRuntime.jsxs(UsageItem, {
112
+ text: "Memory Usage",
113
+ iconClass: "icon-shiyongshuai",
114
+ ram: false,
115
+ children: [mem.percent, "%"]
116
+ }), supermicro?.nic_temperature && /*#__PURE__*/jsxRuntime.jsxs(UsageItem, {
117
+ text: "NIC Temperature",
118
+ iconClass: "icon-wuliwangka",
119
+ children: [supermicro.nic_temperature, "\u2103"]
120
+ }), gpu_stats?.length > 0 && /*#__PURE__*/jsxRuntime.jsx(UsageItem, {
121
+ text: "GPU Usage",
122
+ iconClass: "icon-gpufuwu",
123
+ children: gpu_stats[0]["utilization.gpu"]
124
+ }), supermicro?.gpu_temperature && /*#__PURE__*/jsxRuntime.jsxs(UsageItem, {
125
+ text: "GPU Temperature",
126
+ iconClass: "icon-wendu",
127
+ children: [supermicro.gpu_temperature, "\u2103"]
128
+ })]
129
+ });
130
+ }, [ps_status]);
131
+ };
132
+
133
+ const AuthorizationModal = _ref => {
134
+ let {
135
+ onCancel,
136
+ onOk,
137
+ authData,
138
+ title = 'Register License',
139
+ okText,
140
+ cancelText = 'Ignore',
141
+ width = 600
142
+ } = _ref;
143
+ const {
144
+ message
145
+ } = antd.App.useApp();
146
+ const [code, setCode] = react.useState('');
147
+ const {
148
+ accredit_status: isActivated,
149
+ message: statusMessage = 'Unactivated',
150
+ bios_id: uuid,
151
+ expires_time: expiresTime
152
+ } = authData || {};
153
+ const handleOk = () => {
154
+ const trimmedCode = code.trim();
155
+ if (!trimmedCode) {
156
+ message.error('License key cannot be empty');
157
+ return;
158
+ }
159
+ onOk(trimmedCode);
160
+ };
161
+ const statusAlert = isActivated ? /*#__PURE__*/jsxRuntime.jsx(antd.Alert, {
162
+ message: `${statusMessage}, will expire on ${expiresTime}`,
163
+ type: "success",
164
+ showIcon: true
165
+ }) : /*#__PURE__*/jsxRuntime.jsx(antd.Alert, {
166
+ message: statusMessage,
167
+ type: "warning",
168
+ showIcon: true
169
+ });
170
+ const defaultOkText = isActivated ? "Reactivate" : "Activate Now";
171
+ return /*#__PURE__*/jsxRuntime.jsx(antd.Modal, {
172
+ title: title,
173
+ open: true,
174
+ onCancel: onCancel,
175
+ onOk: handleOk,
176
+ okText: okText || defaultOkText,
177
+ cancelText: cancelText,
178
+ width: width,
179
+ maskClosable: false,
180
+ closable: false,
181
+ cancelButtonProps: {
182
+ disabled: !isActivated
183
+ },
184
+ children: /*#__PURE__*/jsxRuntime.jsxs(antd.Form, {
185
+ name: "auth_form",
186
+ labelCol: {
187
+ span: 6
188
+ },
189
+ wrapperCol: {
190
+ span: 18
191
+ },
192
+ autoComplete: "off",
193
+ children: [/*#__PURE__*/jsxRuntime.jsx("div", {
194
+ style: {
195
+ marginBottom: 16
196
+ },
197
+ children: statusAlert
198
+ }), /*#__PURE__*/jsxRuntime.jsx(antd.Form.Item, {
199
+ label: "Machine Code",
200
+ required: true,
201
+ children: /*#__PURE__*/jsxRuntime.jsx(antd.Input, {
202
+ value: uuid,
203
+ readOnly: true
204
+ })
205
+ }), /*#__PURE__*/jsxRuntime.jsx(antd.Form.Item, {
206
+ label: "License Key",
207
+ required: true,
208
+ children: /*#__PURE__*/jsxRuntime.jsx(antd.Input.TextArea, {
209
+ value: code,
210
+ onChange: e => setCode(e.target.value),
211
+ autoSize: {
212
+ minRows: 6,
213
+ maxRows: 6
214
+ },
215
+ placeholder: "Enter your license key"
216
+ })
217
+ })]
218
+ })
219
+ });
220
+ };
221
+
222
+ const DEFAULT_AUTH = {
223
+ accredit_status: false,
224
+ // 授权状态
225
+ bios_id: '',
226
+ // 主机id
227
+ message: 'Unactivated',
228
+ // 激活信息
229
+ expires_time: '' // 授权到期时间
230
+ };
231
+ const useAuth = options => {
232
+ const {
233
+ fetchAuthInfo,
234
+ authorize,
235
+ defaultAuthData = DEFAULT_AUTH,
236
+ autoShowModal = true
237
+ } = options || {};
238
+ const [messageApi, contextHolder] = antd.message.useMessage();
239
+ const [showModal, setShowModal] = react.useState(false); // 默认隐藏
240
+ const [authData, setAuthData] = react.useState(defaultAuthData);
241
+ const [isRegistered, setIsRegistered] = react.useState(false);
242
+ const [loading, setLoading] = react.useState(false);
243
+ const openModal = react.useCallback(() => setShowModal(true), []);
244
+ const closeModal = react.useCallback(() => setShowModal(false), []);
245
+ react.useEffect(() => {
246
+ async function loadAuthInfo() {
247
+ try {
248
+ setLoading(true);
249
+ const result = await fetchAuthInfo();
250
+ if (result?.commands) {
251
+ const commands = result.commands;
252
+ setAuthData(commands);
253
+ setIsRegistered(commands.accredit_status);
254
+ if (autoShowModal) {
255
+ commands.accredit_status ? closeModal() : openModal();
256
+ }
257
+ }
258
+ } catch (error) {
259
+ console.error('Failed to fetch auth info:', error);
260
+ } finally {
261
+ setLoading(false);
262
+ }
263
+ }
264
+ loadAuthInfo();
265
+ }, [fetchAuthInfo, autoShowModal, openModal, closeModal]);
266
+ const auth = async code => {
267
+ try {
268
+ setLoading(true);
269
+ const result = await authorize({
270
+ type: "accredit_command",
271
+ commands: {
272
+ id: "LICENSE",
273
+ license_data: code
274
+ }
275
+ });
276
+ if (result?.commands) {
277
+ const commands = result.commands;
278
+ // type accredit_message
279
+ if (commands?.accredit_status) {
280
+ setIsRegistered(true);
281
+ setAuthData(commands);
282
+ closeModal();
283
+ } else {
284
+ messageApi.error(commands.ciphertext_status || 'Authorization failed');
285
+ }
286
+ }
287
+ } catch (error) {
288
+ console.error('Authorization error:', error);
289
+ } finally {
290
+ setLoading(false);
291
+ }
292
+ };
293
+ const modal = showModal && /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
294
+ children: [/*#__PURE__*/jsxRuntime.jsx(AuthorizationModal, {
295
+ onOk: auth,
296
+ onCancel: closeModal,
297
+ authData: authData
298
+ }), contextHolder]
299
+ });
300
+ return {
301
+ AuthModal: modal,
302
+ openAuthModal: openModal,
303
+ closeAuthModal: closeModal,
304
+ isRegistered,
305
+ authData,
306
+ loading
307
+ };
308
+ };
309
+
310
+ const useUpgrade = _ref => {
311
+ let {
312
+ menuItems = [],
313
+ onMenuClick,
314
+ downloadFiles,
315
+ upgradeExecute,
316
+ upgradeStatus,
317
+ acceptFileTypes = "application/octet-stream",
318
+ uploadCompleteDelay = 3000,
319
+ statusPollingInterval = 1000
320
+ } = _ref;
321
+ const [isSpinning, setIsSpinning] = react.useState(false);
322
+ const [interval, setInterval] = react.useState(undefined); // 间隔时间,当设置值为 undefined 时会停止计时器
323
+ const inputRef = react.useRef(null);
324
+ const [currentStatus, setCurrentStatus] = react.useState('idle'); // 'idle' | 'uploading' | 'upgrading'
325
+ const isUploadCompleteRef = react.useRef(false); // 安装包上传是否完成
326
+ const [uploadProgress, setUploadProgress] = react.useState(0);
327
+
328
+ // 分别创建独立的取消令牌
329
+ const uploadCancelToken = react.useRef(axios.CancelToken.source());
330
+ const statusCancelToken = react.useRef(axios.CancelToken.source());
331
+ const showLoader = () => setIsSpinning(true);
332
+ const hideLoader = () => setIsSpinning(false);
333
+
334
+ // 构建菜单项 - 确保至少包含download和upload
335
+ const finalMenuItems = react.useMemo(() => {
336
+ const hasDownload = menuItems.some(item => item.key === 'download');
337
+ const hasUpload = menuItems.some(item => item.key === 'upload');
338
+
339
+ // 如果都已经存在,直接返回
340
+ if (hasDownload && hasUpload) {
341
+ return menuItems;
342
+ }
343
+ let finalItems = [...menuItems];
344
+
345
+ // 查找license项的位置
346
+ const licenseIndex = finalItems.findIndex(item => item.key === 'license');
347
+
348
+ // 查找最后一个分隔符的位置(在license之前)
349
+ let insertIndex = finalItems.length;
350
+ let hasPrecedingDivider = false;
351
+ if (licenseIndex !== -1) {
352
+ // 如果找到license,在其前面插入
353
+ insertIndex = licenseIndex;
354
+
355
+ // 检查license前面是否有分隔符
356
+ if (licenseIndex > 0 && finalItems[licenseIndex - 1].type === 'divider') {
357
+ hasPrecedingDivider = true;
358
+ insertIndex = licenseIndex - 1; // 在分隔符前面插入
359
+ }
360
+ } else {
361
+ // 如果没有license,查找最后一个分隔符
362
+ const lastDividerIndex = finalItems.map((item, idx) => item.type === 'divider' ? idx : -1).filter(idx => idx !== -1).pop();
363
+ if (lastDividerIndex !== undefined) {
364
+ insertIndex = lastDividerIndex + 1;
365
+ }
366
+ }
367
+ const itemsToInsert = [];
368
+
369
+ // 添加缺少的download项
370
+ if (!hasDownload) {
371
+ itemsToInsert.push({
372
+ key: "download",
373
+ label: "Download Config File"
374
+ });
375
+ }
376
+
377
+ // 添加缺少的upload项
378
+ if (!hasUpload) {
379
+ itemsToInsert.push({
380
+ key: "upload",
381
+ label: "Software Update"
382
+ });
383
+ }
384
+
385
+ // 在前面插入分隔符(如果还没有且需要插入项)
386
+ if (!hasPrecedingDivider && itemsToInsert.length > 0 && insertIndex > 0) {
387
+ itemsToInsert.unshift({
388
+ type: 'divider'
389
+ });
390
+ }
391
+
392
+ // 在指定位置插入项
393
+ if (itemsToInsert.length > 0) {
394
+ finalItems.splice(insertIndex, 0, ...itemsToInsert);
395
+ }
396
+ return finalItems;
397
+ }, [menuItems]);
398
+ const handleMenuClick = _ref2 => {
399
+ let {
400
+ key
401
+ } = _ref2;
402
+ switch (key) {
403
+ case 'download':
404
+ onDownload();
405
+ return;
406
+ case 'upload':
407
+ onUpload();
408
+ return;
409
+ default:
410
+ // 其他菜单项交给外部回调处理
411
+ if (onMenuClick) {
412
+ onMenuClick(key);
413
+ } else {
414
+ console.warn(`Unknown menu key: ${key} and no onMenuClick provided`);
415
+ }
416
+ }
417
+ };
418
+ const onDownload = async () => {
419
+ if (!downloadFiles) {
420
+ console.error('downloadFiles function is required for download operation');
421
+ antd.message.error('Download functionality not configured');
422
+ return;
423
+ }
424
+ try {
425
+ const res = await downloadFiles();
426
+ if (res.status !== 200) {
427
+ throw new Error(`Unexpected status code: ${res.status}`);
428
+ }
429
+
430
+ // 默认值,兼容接口响应头没有定义文件名
431
+ let fileName = 'config.tar.gz';
432
+ const contentDisposition = res.headers['content-disposition'] || '';
433
+
434
+ // 获取接口响应的content-disposition字段值,以便获取到文件名
435
+ if (contentDisposition) {
436
+ const filenameMatch = contentDisposition.match(/filename\s*=\s*"?([^";]+)"?/i);
437
+ if (filenameMatch?.[1]) {
438
+ fileName = decodeURIComponent(filenameMatch[1]); // 处理编码后的文件名(如 %20 转空格)
439
+ }
440
+ }
441
+
442
+ // 创建并下载文件
443
+ const blob = new Blob([res.data], {
444
+ type: 'application/octet-stream'
445
+ });
446
+ const url = window.URL.createObjectURL(blob);
447
+
448
+ // 下面就是创建一个a标签并触发click事件,来下载该文件
449
+ const link = document.createElement('a');
450
+ link.style.display = 'none';
451
+ link.href = url;
452
+ link.target = '_blank';
453
+ link.download = fileName;
454
+ document.body.appendChild(link);
455
+ link.click();
456
+
457
+ // 最后移除a标签并删除创建的ObjectURL对象,防止内存泄漏
458
+ link.parentNode.removeChild(link);
459
+ window.URL.revokeObjectURL(url);
460
+ } catch (error) {
461
+ console.error('Download failed:', error);
462
+ antd.message.error('Download failed');
463
+ }
464
+ };
465
+ const onUpload = () => {
466
+ if (inputRef?.current) {
467
+ inputRef.current.click();
468
+ }
469
+ };
470
+ const updatePackage = async event => {
471
+ if (!upgradeExecute) {
472
+ console.error('upgradeExecute function is required for upload operation');
473
+ antd.message.error('Upload functionality not configured');
474
+ return;
475
+ }
476
+ try {
477
+ const file = event.target.files?.[0];
478
+ if (!file) return;
479
+ showLoader();
480
+ setCurrentStatus('Uploading...');
481
+ setUploadProgress(0); // 重置进度
482
+
483
+ const formData = new FormData();
484
+ formData.append('file', file);
485
+ isUploadCompleteRef.current = false;
486
+
487
+ // 上传文件(不等待响应)
488
+ upgradeExecute(formData, {
489
+ onUploadProgress: progressEvent => {
490
+ const percentCompleted = Math.round(progressEvent.loaded * 100 / progressEvent.total);
491
+ setUploadProgress(percentCompleted); // 更新进度状态
492
+
493
+ if (percentCompleted === 100) {
494
+ isUploadCompleteRef.current = true;
495
+ // 等待3秒 开始状态轮询
496
+ setTimeout(() => {
497
+ setInterval(statusPollingInterval);
498
+ setCurrentStatus('Upgrading...');
499
+ }, uploadCompleteDelay);
500
+ }
501
+ },
502
+ cancelToken: uploadCancelToken.current.token
503
+ });
504
+
505
+ // 清除文件选择
506
+ if (inputRef.current) inputRef.current.value = "";
507
+ } catch (error) {
508
+ if (!axios.isCancel(error)) {
509
+ console.error("Upload error:", error);
510
+ antd.message.error('Upload failed');
511
+ }
512
+ cancelRequest();
513
+ }
514
+ };
515
+ const fetchUpgradeStatus = async () => {
516
+ if (!upgradeStatus) {
517
+ console.error('upgradeStatus function is required for status checking');
518
+ cancelRequest();
519
+ return;
520
+ }
521
+ try {
522
+ const response = await upgradeStatus({
523
+ cancelToken: statusCancelToken.current.token
524
+ });
525
+ if (response?.status === 200) {
526
+ const {
527
+ code,
528
+ message: statusMessage
529
+ } = response.data;
530
+
531
+ // 状态处理
532
+ switch (code) {
533
+ case 200:
534
+ // 升级成功
535
+ antd.message.success(statusMessage, 2.5, () => {
536
+ cancelRequest();
537
+ window.location.reload();
538
+ });
539
+ break;
540
+ case 201:
541
+ // 升级中
542
+ // code为201时,每隔一秒请求一次。直到请求到其他的code,直接弹出message提示。
543
+ break;
544
+ case 202: // 升级失败
545
+ case 203:
546
+ // 升级异常
547
+ antd.message.error(statusMessage);
548
+ cancelRequest();
549
+ break;
550
+ default:
551
+ break;
552
+ }
553
+ }
554
+ } catch (error) {
555
+ if (axios.isCancel(error)) {
556
+ console.log('Status polling canceled');
557
+ } else {
558
+ console.error('Status check failed:', error);
559
+ // 网络错误时自动重试
560
+ }
561
+ }
562
+ };
563
+ const cancelRequest = () => {
564
+ // 取消状态轮询
565
+ uploadCancelToken.current.cancel('Operation canceled');
566
+ statusCancelToken.current.cancel('Operation canceled');
567
+ uploadCancelToken.current = axios.CancelToken.source();
568
+ statusCancelToken.current = axios.CancelToken.source();
569
+
570
+ // 重置所有状态
571
+ setInterval(undefined);
572
+ setCurrentStatus('idle');
573
+ hideLoader();
574
+ };
575
+
576
+ // 轮询状态
577
+ ahooks.useInterval(fetchUpgradeStatus, interval);
578
+
579
+ // 组件卸载时清理
580
+ react.useEffect(() => {
581
+ return () => {
582
+ uploadCancelToken.current.cancel();
583
+ statusCancelToken.current.cancel();
584
+ };
585
+ }, []);
586
+ const upgradeElement = /*#__PURE__*/jsxRuntime.jsxs("div", {
587
+ children: [/*#__PURE__*/jsxRuntime.jsx(antd.Dropdown, {
588
+ menu: {
589
+ items: finalMenuItems,
590
+ onClick: handleMenuClick
591
+ },
592
+ trigger: ["hover"],
593
+ children: /*#__PURE__*/jsxRuntime.jsx("a", {
594
+ onClick: e => e.preventDefault(),
595
+ children: /*#__PURE__*/jsxRuntime.jsx("i", {
596
+ className: "iconfont icon-liebiao2 text-2xl text-neutral-400"
597
+ })
598
+ })
599
+ }), /*#__PURE__*/jsxRuntime.jsx("input", {
600
+ ref: inputRef,
601
+ type: "file",
602
+ onChange: updatePackage,
603
+ className: "hidden",
604
+ accept: acceptFileTypes
605
+ }), /*#__PURE__*/jsxRuntime.jsx(antd.Spin, {
606
+ spinning: isSpinning,
607
+ indicator: /*#__PURE__*/jsxRuntime.jsx(icons.LoadingOutlined, {
608
+ style: {
609
+ fontSize: 60
610
+ },
611
+ spin: true
612
+ }),
613
+ tip: currentStatus === "Uploading..." ? `${currentStatus} ${uploadProgress}%` : currentStatus,
614
+ size: "large",
615
+ fullscreen: true
616
+ })]
617
+ });
618
+ return [upgradeElement];
619
+ };
620
+
621
+ const useSystemOperations = function () {
622
+ let {
623
+ onPowerOff,
624
+ onRestart,
625
+ confirmTitle = "Confirm",
626
+ cancelText = "No",
627
+ okText = "Yes"
628
+ } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
629
+ const {
630
+ modal: AntdModal
631
+ } = antd.App.useApp();
632
+ const doAction = react.useCallback(action => {
633
+ try {
634
+ AntdModal.confirm({
635
+ icon: /*#__PURE__*/jsxRuntime.jsx(icons.ExclamationCircleFilled, {}),
636
+ title: `${confirmTitle} ${action}?`,
637
+ cancelText,
638
+ okText,
639
+ onOk: () => {
640
+ if (action === 'poweroff' && onPowerOff) {
641
+ onPowerOff();
642
+ } else if (action === 'restart' && onRestart) {
643
+ onRestart();
644
+ }
645
+ }
646
+ });
647
+ } catch (error) {
648
+ console.error(`${action.toUpperCase()} ERROR: `, error);
649
+ }
650
+ }, [AntdModal, confirmTitle, cancelText, okText, onPowerOff, onRestart]);
651
+ const getMenuItems = react.useCallback(() => [{
652
+ key: "poweroff",
653
+ label: "Power Off"
654
+ }, {
655
+ key: "restart",
656
+ label: "Restart"
657
+ }], []);
658
+ const handleMenuClick = react.useCallback(_ref => {
659
+ let {
660
+ key
661
+ } = _ref;
662
+ doAction(key);
663
+ }, [doAction]);
664
+ return {
665
+ menuItems: getMenuItems(),
666
+ handleMenuClick
667
+ };
668
+ };
669
+
670
+ const UpgradeManager = _ref => {
671
+ let {
672
+ menuItems = [],
673
+ onMenuClick,
674
+ downloadFiles,
675
+ upgradeExecute,
676
+ upgradeStatus,
677
+ acceptFileTypes = "application/octet-stream",
678
+ uploadCompleteDelay = 3000,
679
+ statusPollingInterval = 1000,
680
+ children,
681
+ ...dropdownProps
682
+ } = _ref;
683
+ const [upgradeElement] = useUpgrade({
684
+ menuItems,
685
+ onMenuClick,
686
+ downloadFiles,
687
+ upgradeExecute,
688
+ upgradeStatus,
689
+ acceptFileTypes,
690
+ uploadCompleteDelay,
691
+ statusPollingInterval
692
+ });
693
+ if (children) {
694
+ // 提取Dropdown组件和其menu属性
695
+ const dropdownElement = upgradeElement.props.children[0];
696
+ const otherElements = upgradeElement.props.children.slice(1);
697
+ return /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
698
+ children: [/*#__PURE__*/jsxRuntime.jsx(antd.Dropdown, {
699
+ ...dropdownProps,
700
+ ...dropdownElement.props,
701
+ children: children
702
+ }), otherElements]
703
+ });
704
+ }
705
+
706
+ // 如果没有children,直接返回完整的升级元素
707
+ return upgradeElement;
708
+ };
709
+ UpgradeManager.defaultProps = {
710
+ trigger: ["hover"],
711
+ placement: "bottomRight"
712
+ };
713
+
714
+ function getDefaultExportFromCjs (x) {
715
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
716
+ }
717
+
718
+ var propTypes = {exports: {}};
719
+
720
+ var reactIs = {exports: {}};
721
+
722
+ var reactIs_production_min = {};
723
+
724
+ /** @license React v16.13.1
725
+ * react-is.production.min.js
726
+ *
727
+ * Copyright (c) Facebook, Inc. and its affiliates.
728
+ *
729
+ * This source code is licensed under the MIT license found in the
730
+ * LICENSE file in the root directory of this source tree.
731
+ */
732
+
733
+ var hasRequiredReactIs_production_min;
734
+
735
+ function requireReactIs_production_min () {
736
+ if (hasRequiredReactIs_production_min) return reactIs_production_min;
737
+ hasRequiredReactIs_production_min = 1;
738
+ var b="function"===typeof Symbol&&Symbol.for,c=b?Symbol.for("react.element"):60103,d=b?Symbol.for("react.portal"):60106,e=b?Symbol.for("react.fragment"):60107,f=b?Symbol.for("react.strict_mode"):60108,g=b?Symbol.for("react.profiler"):60114,h=b?Symbol.for("react.provider"):60109,k=b?Symbol.for("react.context"):60110,l=b?Symbol.for("react.async_mode"):60111,m=b?Symbol.for("react.concurrent_mode"):60111,n=b?Symbol.for("react.forward_ref"):60112,p=b?Symbol.for("react.suspense"):60113,q=b?
739
+ Symbol.for("react.suspense_list"):60120,r=b?Symbol.for("react.memo"):60115,t=b?Symbol.for("react.lazy"):60116,v=b?Symbol.for("react.block"):60121,w=b?Symbol.for("react.fundamental"):60117,x=b?Symbol.for("react.responder"):60118,y=b?Symbol.for("react.scope"):60119;
740
+ function z(a){if("object"===typeof a&&null!==a){var u=a.$$typeof;switch(u){case c:switch(a=a.type,a){case l:case m:case e:case g:case f:case p:return a;default:switch(a=a&&a.$$typeof,a){case k:case n:case t:case r:case h:return a;default:return u}}case d:return u}}}function A(a){return z(a)===m}reactIs_production_min.AsyncMode=l;reactIs_production_min.ConcurrentMode=m;reactIs_production_min.ContextConsumer=k;reactIs_production_min.ContextProvider=h;reactIs_production_min.Element=c;reactIs_production_min.ForwardRef=n;reactIs_production_min.Fragment=e;reactIs_production_min.Lazy=t;reactIs_production_min.Memo=r;reactIs_production_min.Portal=d;
741
+ reactIs_production_min.Profiler=g;reactIs_production_min.StrictMode=f;reactIs_production_min.Suspense=p;reactIs_production_min.isAsyncMode=function(a){return A(a)||z(a)===l};reactIs_production_min.isConcurrentMode=A;reactIs_production_min.isContextConsumer=function(a){return z(a)===k};reactIs_production_min.isContextProvider=function(a){return z(a)===h};reactIs_production_min.isElement=function(a){return "object"===typeof a&&null!==a&&a.$$typeof===c};reactIs_production_min.isForwardRef=function(a){return z(a)===n};reactIs_production_min.isFragment=function(a){return z(a)===e};reactIs_production_min.isLazy=function(a){return z(a)===t};
742
+ reactIs_production_min.isMemo=function(a){return z(a)===r};reactIs_production_min.isPortal=function(a){return z(a)===d};reactIs_production_min.isProfiler=function(a){return z(a)===g};reactIs_production_min.isStrictMode=function(a){return z(a)===f};reactIs_production_min.isSuspense=function(a){return z(a)===p};
743
+ reactIs_production_min.isValidElementType=function(a){return "string"===typeof a||"function"===typeof a||a===e||a===m||a===g||a===f||a===p||a===q||"object"===typeof a&&null!==a&&(a.$$typeof===t||a.$$typeof===r||a.$$typeof===h||a.$$typeof===k||a.$$typeof===n||a.$$typeof===w||a.$$typeof===x||a.$$typeof===y||a.$$typeof===v)};reactIs_production_min.typeOf=z;
744
+ return reactIs_production_min;
745
+ }
746
+
747
+ var reactIs_development = {};
748
+
749
+ /** @license React v16.13.1
750
+ * react-is.development.js
751
+ *
752
+ * Copyright (c) Facebook, Inc. and its affiliates.
753
+ *
754
+ * This source code is licensed under the MIT license found in the
755
+ * LICENSE file in the root directory of this source tree.
756
+ */
757
+
758
+ var hasRequiredReactIs_development;
759
+
760
+ function requireReactIs_development () {
761
+ if (hasRequiredReactIs_development) return reactIs_development;
762
+ hasRequiredReactIs_development = 1;
763
+
764
+
765
+
766
+ if (process.env.NODE_ENV !== "production") {
767
+ (function() {
768
+
769
+ // The Symbol used to tag the ReactElement-like types. If there is no native Symbol
770
+ // nor polyfill, then a plain number is used for performance.
771
+ var hasSymbol = typeof Symbol === 'function' && Symbol.for;
772
+ var REACT_ELEMENT_TYPE = hasSymbol ? Symbol.for('react.element') : 0xeac7;
773
+ var REACT_PORTAL_TYPE = hasSymbol ? Symbol.for('react.portal') : 0xeaca;
774
+ var REACT_FRAGMENT_TYPE = hasSymbol ? Symbol.for('react.fragment') : 0xeacb;
775
+ var REACT_STRICT_MODE_TYPE = hasSymbol ? Symbol.for('react.strict_mode') : 0xeacc;
776
+ var REACT_PROFILER_TYPE = hasSymbol ? Symbol.for('react.profiler') : 0xead2;
777
+ var REACT_PROVIDER_TYPE = hasSymbol ? Symbol.for('react.provider') : 0xeacd;
778
+ var REACT_CONTEXT_TYPE = hasSymbol ? Symbol.for('react.context') : 0xeace; // TODO: We don't use AsyncMode or ConcurrentMode anymore. They were temporary
779
+ // (unstable) APIs that have been removed. Can we remove the symbols?
780
+
781
+ var REACT_ASYNC_MODE_TYPE = hasSymbol ? Symbol.for('react.async_mode') : 0xeacf;
782
+ var REACT_CONCURRENT_MODE_TYPE = hasSymbol ? Symbol.for('react.concurrent_mode') : 0xeacf;
783
+ var REACT_FORWARD_REF_TYPE = hasSymbol ? Symbol.for('react.forward_ref') : 0xead0;
784
+ var REACT_SUSPENSE_TYPE = hasSymbol ? Symbol.for('react.suspense') : 0xead1;
785
+ var REACT_SUSPENSE_LIST_TYPE = hasSymbol ? Symbol.for('react.suspense_list') : 0xead8;
786
+ var REACT_MEMO_TYPE = hasSymbol ? Symbol.for('react.memo') : 0xead3;
787
+ var REACT_LAZY_TYPE = hasSymbol ? Symbol.for('react.lazy') : 0xead4;
788
+ var REACT_BLOCK_TYPE = hasSymbol ? Symbol.for('react.block') : 0xead9;
789
+ var REACT_FUNDAMENTAL_TYPE = hasSymbol ? Symbol.for('react.fundamental') : 0xead5;
790
+ var REACT_RESPONDER_TYPE = hasSymbol ? Symbol.for('react.responder') : 0xead6;
791
+ var REACT_SCOPE_TYPE = hasSymbol ? Symbol.for('react.scope') : 0xead7;
792
+
793
+ function isValidElementType(type) {
794
+ return typeof type === 'string' || typeof type === 'function' || // Note: its typeof might be other than 'symbol' or 'number' if it's a polyfill.
795
+ type === REACT_FRAGMENT_TYPE || type === REACT_CONCURRENT_MODE_TYPE || type === REACT_PROFILER_TYPE || type === REACT_STRICT_MODE_TYPE || type === REACT_SUSPENSE_TYPE || type === REACT_SUSPENSE_LIST_TYPE || typeof type === 'object' && type !== null && (type.$$typeof === REACT_LAZY_TYPE || type.$$typeof === REACT_MEMO_TYPE || type.$$typeof === REACT_PROVIDER_TYPE || type.$$typeof === REACT_CONTEXT_TYPE || type.$$typeof === REACT_FORWARD_REF_TYPE || type.$$typeof === REACT_FUNDAMENTAL_TYPE || type.$$typeof === REACT_RESPONDER_TYPE || type.$$typeof === REACT_SCOPE_TYPE || type.$$typeof === REACT_BLOCK_TYPE);
796
+ }
797
+
798
+ function typeOf(object) {
799
+ if (typeof object === 'object' && object !== null) {
800
+ var $$typeof = object.$$typeof;
801
+
802
+ switch ($$typeof) {
803
+ case REACT_ELEMENT_TYPE:
804
+ var type = object.type;
805
+
806
+ switch (type) {
807
+ case REACT_ASYNC_MODE_TYPE:
808
+ case REACT_CONCURRENT_MODE_TYPE:
809
+ case REACT_FRAGMENT_TYPE:
810
+ case REACT_PROFILER_TYPE:
811
+ case REACT_STRICT_MODE_TYPE:
812
+ case REACT_SUSPENSE_TYPE:
813
+ return type;
814
+
815
+ default:
816
+ var $$typeofType = type && type.$$typeof;
817
+
818
+ switch ($$typeofType) {
819
+ case REACT_CONTEXT_TYPE:
820
+ case REACT_FORWARD_REF_TYPE:
821
+ case REACT_LAZY_TYPE:
822
+ case REACT_MEMO_TYPE:
823
+ case REACT_PROVIDER_TYPE:
824
+ return $$typeofType;
825
+
826
+ default:
827
+ return $$typeof;
828
+ }
829
+
830
+ }
831
+
832
+ case REACT_PORTAL_TYPE:
833
+ return $$typeof;
834
+ }
835
+ }
836
+
837
+ return undefined;
838
+ } // AsyncMode is deprecated along with isAsyncMode
839
+
840
+ var AsyncMode = REACT_ASYNC_MODE_TYPE;
841
+ var ConcurrentMode = REACT_CONCURRENT_MODE_TYPE;
842
+ var ContextConsumer = REACT_CONTEXT_TYPE;
843
+ var ContextProvider = REACT_PROVIDER_TYPE;
844
+ var Element = REACT_ELEMENT_TYPE;
845
+ var ForwardRef = REACT_FORWARD_REF_TYPE;
846
+ var Fragment = REACT_FRAGMENT_TYPE;
847
+ var Lazy = REACT_LAZY_TYPE;
848
+ var Memo = REACT_MEMO_TYPE;
849
+ var Portal = REACT_PORTAL_TYPE;
850
+ var Profiler = REACT_PROFILER_TYPE;
851
+ var StrictMode = REACT_STRICT_MODE_TYPE;
852
+ var Suspense = REACT_SUSPENSE_TYPE;
853
+ var hasWarnedAboutDeprecatedIsAsyncMode = false; // AsyncMode should be deprecated
854
+
855
+ function isAsyncMode(object) {
856
+ {
857
+ if (!hasWarnedAboutDeprecatedIsAsyncMode) {
858
+ hasWarnedAboutDeprecatedIsAsyncMode = true; // Using console['warn'] to evade Babel and ESLint
859
+
860
+ console['warn']('The ReactIs.isAsyncMode() alias has been deprecated, ' + 'and will be removed in React 17+. Update your code to use ' + 'ReactIs.isConcurrentMode() instead. It has the exact same API.');
861
+ }
862
+ }
863
+
864
+ return isConcurrentMode(object) || typeOf(object) === REACT_ASYNC_MODE_TYPE;
865
+ }
866
+ function isConcurrentMode(object) {
867
+ return typeOf(object) === REACT_CONCURRENT_MODE_TYPE;
868
+ }
869
+ function isContextConsumer(object) {
870
+ return typeOf(object) === REACT_CONTEXT_TYPE;
871
+ }
872
+ function isContextProvider(object) {
873
+ return typeOf(object) === REACT_PROVIDER_TYPE;
874
+ }
875
+ function isElement(object) {
876
+ return typeof object === 'object' && object !== null && object.$$typeof === REACT_ELEMENT_TYPE;
877
+ }
878
+ function isForwardRef(object) {
879
+ return typeOf(object) === REACT_FORWARD_REF_TYPE;
880
+ }
881
+ function isFragment(object) {
882
+ return typeOf(object) === REACT_FRAGMENT_TYPE;
883
+ }
884
+ function isLazy(object) {
885
+ return typeOf(object) === REACT_LAZY_TYPE;
886
+ }
887
+ function isMemo(object) {
888
+ return typeOf(object) === REACT_MEMO_TYPE;
889
+ }
890
+ function isPortal(object) {
891
+ return typeOf(object) === REACT_PORTAL_TYPE;
892
+ }
893
+ function isProfiler(object) {
894
+ return typeOf(object) === REACT_PROFILER_TYPE;
895
+ }
896
+ function isStrictMode(object) {
897
+ return typeOf(object) === REACT_STRICT_MODE_TYPE;
898
+ }
899
+ function isSuspense(object) {
900
+ return typeOf(object) === REACT_SUSPENSE_TYPE;
901
+ }
902
+
903
+ reactIs_development.AsyncMode = AsyncMode;
904
+ reactIs_development.ConcurrentMode = ConcurrentMode;
905
+ reactIs_development.ContextConsumer = ContextConsumer;
906
+ reactIs_development.ContextProvider = ContextProvider;
907
+ reactIs_development.Element = Element;
908
+ reactIs_development.ForwardRef = ForwardRef;
909
+ reactIs_development.Fragment = Fragment;
910
+ reactIs_development.Lazy = Lazy;
911
+ reactIs_development.Memo = Memo;
912
+ reactIs_development.Portal = Portal;
913
+ reactIs_development.Profiler = Profiler;
914
+ reactIs_development.StrictMode = StrictMode;
915
+ reactIs_development.Suspense = Suspense;
916
+ reactIs_development.isAsyncMode = isAsyncMode;
917
+ reactIs_development.isConcurrentMode = isConcurrentMode;
918
+ reactIs_development.isContextConsumer = isContextConsumer;
919
+ reactIs_development.isContextProvider = isContextProvider;
920
+ reactIs_development.isElement = isElement;
921
+ reactIs_development.isForwardRef = isForwardRef;
922
+ reactIs_development.isFragment = isFragment;
923
+ reactIs_development.isLazy = isLazy;
924
+ reactIs_development.isMemo = isMemo;
925
+ reactIs_development.isPortal = isPortal;
926
+ reactIs_development.isProfiler = isProfiler;
927
+ reactIs_development.isStrictMode = isStrictMode;
928
+ reactIs_development.isSuspense = isSuspense;
929
+ reactIs_development.isValidElementType = isValidElementType;
930
+ reactIs_development.typeOf = typeOf;
931
+ })();
932
+ }
933
+ return reactIs_development;
934
+ }
935
+
936
+ var hasRequiredReactIs;
937
+
938
+ function requireReactIs () {
939
+ if (hasRequiredReactIs) return reactIs.exports;
940
+ hasRequiredReactIs = 1;
941
+
942
+ if (process.env.NODE_ENV === 'production') {
943
+ reactIs.exports = requireReactIs_production_min();
944
+ } else {
945
+ reactIs.exports = requireReactIs_development();
946
+ }
947
+ return reactIs.exports;
948
+ }
949
+
950
+ /*
951
+ object-assign
952
+ (c) Sindre Sorhus
953
+ @license MIT
954
+ */
955
+
956
+ var objectAssign;
957
+ var hasRequiredObjectAssign;
958
+
959
+ function requireObjectAssign () {
960
+ if (hasRequiredObjectAssign) return objectAssign;
961
+ hasRequiredObjectAssign = 1;
962
+ /* eslint-disable no-unused-vars */
963
+ var getOwnPropertySymbols = Object.getOwnPropertySymbols;
964
+ var hasOwnProperty = Object.prototype.hasOwnProperty;
965
+ var propIsEnumerable = Object.prototype.propertyIsEnumerable;
966
+
967
+ function toObject(val) {
968
+ if (val === null || val === undefined) {
969
+ throw new TypeError('Object.assign cannot be called with null or undefined');
970
+ }
971
+
972
+ return Object(val);
973
+ }
974
+
975
+ function shouldUseNative() {
976
+ try {
977
+ if (!Object.assign) {
978
+ return false;
979
+ }
980
+
981
+ // Detect buggy property enumeration order in older V8 versions.
982
+
983
+ // https://bugs.chromium.org/p/v8/issues/detail?id=4118
984
+ var test1 = new String('abc'); // eslint-disable-line no-new-wrappers
985
+ test1[5] = 'de';
986
+ if (Object.getOwnPropertyNames(test1)[0] === '5') {
987
+ return false;
988
+ }
989
+
990
+ // https://bugs.chromium.org/p/v8/issues/detail?id=3056
991
+ var test2 = {};
992
+ for (var i = 0; i < 10; i++) {
993
+ test2['_' + String.fromCharCode(i)] = i;
994
+ }
995
+ var order2 = Object.getOwnPropertyNames(test2).map(function (n) {
996
+ return test2[n];
997
+ });
998
+ if (order2.join('') !== '0123456789') {
999
+ return false;
1000
+ }
1001
+
1002
+ // https://bugs.chromium.org/p/v8/issues/detail?id=3056
1003
+ var test3 = {};
1004
+ 'abcdefghijklmnopqrst'.split('').forEach(function (letter) {
1005
+ test3[letter] = letter;
1006
+ });
1007
+ if (Object.keys(Object.assign({}, test3)).join('') !==
1008
+ 'abcdefghijklmnopqrst') {
1009
+ return false;
1010
+ }
1011
+
1012
+ return true;
1013
+ } catch (err) {
1014
+ // We don't expect any of the above to throw, but better to be safe.
1015
+ return false;
1016
+ }
1017
+ }
1018
+
1019
+ objectAssign = shouldUseNative() ? Object.assign : function (target, source) {
1020
+ var from;
1021
+ var to = toObject(target);
1022
+ var symbols;
1023
+
1024
+ for (var s = 1; s < arguments.length; s++) {
1025
+ from = Object(arguments[s]);
1026
+
1027
+ for (var key in from) {
1028
+ if (hasOwnProperty.call(from, key)) {
1029
+ to[key] = from[key];
1030
+ }
1031
+ }
1032
+
1033
+ if (getOwnPropertySymbols) {
1034
+ symbols = getOwnPropertySymbols(from);
1035
+ for (var i = 0; i < symbols.length; i++) {
1036
+ if (propIsEnumerable.call(from, symbols[i])) {
1037
+ to[symbols[i]] = from[symbols[i]];
1038
+ }
1039
+ }
1040
+ }
1041
+ }
1042
+
1043
+ return to;
1044
+ };
1045
+ return objectAssign;
1046
+ }
1047
+
1048
+ /**
1049
+ * Copyright (c) 2013-present, Facebook, Inc.
1050
+ *
1051
+ * This source code is licensed under the MIT license found in the
1052
+ * LICENSE file in the root directory of this source tree.
1053
+ */
1054
+
1055
+ var ReactPropTypesSecret_1;
1056
+ var hasRequiredReactPropTypesSecret;
1057
+
1058
+ function requireReactPropTypesSecret () {
1059
+ if (hasRequiredReactPropTypesSecret) return ReactPropTypesSecret_1;
1060
+ hasRequiredReactPropTypesSecret = 1;
1061
+
1062
+ var ReactPropTypesSecret = 'SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED';
1063
+
1064
+ ReactPropTypesSecret_1 = ReactPropTypesSecret;
1065
+ return ReactPropTypesSecret_1;
1066
+ }
1067
+
1068
+ var has;
1069
+ var hasRequiredHas;
1070
+
1071
+ function requireHas () {
1072
+ if (hasRequiredHas) return has;
1073
+ hasRequiredHas = 1;
1074
+ has = Function.call.bind(Object.prototype.hasOwnProperty);
1075
+ return has;
1076
+ }
1077
+
1078
+ /**
1079
+ * Copyright (c) 2013-present, Facebook, Inc.
1080
+ *
1081
+ * This source code is licensed under the MIT license found in the
1082
+ * LICENSE file in the root directory of this source tree.
1083
+ */
1084
+
1085
+ var checkPropTypes_1;
1086
+ var hasRequiredCheckPropTypes;
1087
+
1088
+ function requireCheckPropTypes () {
1089
+ if (hasRequiredCheckPropTypes) return checkPropTypes_1;
1090
+ hasRequiredCheckPropTypes = 1;
1091
+
1092
+ var printWarning = function() {};
1093
+
1094
+ if (process.env.NODE_ENV !== 'production') {
1095
+ var ReactPropTypesSecret = /*@__PURE__*/ requireReactPropTypesSecret();
1096
+ var loggedTypeFailures = {};
1097
+ var has = /*@__PURE__*/ requireHas();
1098
+
1099
+ printWarning = function(text) {
1100
+ var message = 'Warning: ' + text;
1101
+ if (typeof console !== 'undefined') {
1102
+ console.error(message);
1103
+ }
1104
+ try {
1105
+ // --- Welcome to debugging React ---
1106
+ // This error was thrown as a convenience so that you can use this stack
1107
+ // to find the callsite that caused this warning to fire.
1108
+ throw new Error(message);
1109
+ } catch (x) { /**/ }
1110
+ };
1111
+ }
1112
+
1113
+ /**
1114
+ * Assert that the values match with the type specs.
1115
+ * Error messages are memorized and will only be shown once.
1116
+ *
1117
+ * @param {object} typeSpecs Map of name to a ReactPropType
1118
+ * @param {object} values Runtime values that need to be type-checked
1119
+ * @param {string} location e.g. "prop", "context", "child context"
1120
+ * @param {string} componentName Name of the component for error messages.
1121
+ * @param {?Function} getStack Returns the component stack.
1122
+ * @private
1123
+ */
1124
+ function checkPropTypes(typeSpecs, values, location, componentName, getStack) {
1125
+ if (process.env.NODE_ENV !== 'production') {
1126
+ for (var typeSpecName in typeSpecs) {
1127
+ if (has(typeSpecs, typeSpecName)) {
1128
+ var error;
1129
+ // Prop type validation may throw. In case they do, we don't want to
1130
+ // fail the render phase where it didn't fail before. So we log it.
1131
+ // After these have been cleaned up, we'll let them throw.
1132
+ try {
1133
+ // This is intentionally an invariant that gets caught. It's the same
1134
+ // behavior as without this statement except with a better message.
1135
+ if (typeof typeSpecs[typeSpecName] !== 'function') {
1136
+ var err = Error(
1137
+ (componentName || 'React class') + ': ' + location + ' type `' + typeSpecName + '` is invalid; ' +
1138
+ 'it must be a function, usually from the `prop-types` package, but received `' + typeof typeSpecs[typeSpecName] + '`.' +
1139
+ 'This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.'
1140
+ );
1141
+ err.name = 'Invariant Violation';
1142
+ throw err;
1143
+ }
1144
+ error = typeSpecs[typeSpecName](values, typeSpecName, componentName, location, null, ReactPropTypesSecret);
1145
+ } catch (ex) {
1146
+ error = ex;
1147
+ }
1148
+ if (error && !(error instanceof Error)) {
1149
+ printWarning(
1150
+ (componentName || 'React class') + ': type specification of ' +
1151
+ location + ' `' + typeSpecName + '` is invalid; the type checker ' +
1152
+ 'function must return `null` or an `Error` but returned a ' + typeof error + '. ' +
1153
+ 'You may have forgotten to pass an argument to the type checker ' +
1154
+ 'creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and ' +
1155
+ 'shape all require an argument).'
1156
+ );
1157
+ }
1158
+ if (error instanceof Error && !(error.message in loggedTypeFailures)) {
1159
+ // Only monitor this failure once because there tends to be a lot of the
1160
+ // same error.
1161
+ loggedTypeFailures[error.message] = true;
1162
+
1163
+ var stack = getStack ? getStack() : '';
1164
+
1165
+ printWarning(
1166
+ 'Failed ' + location + ' type: ' + error.message + (stack != null ? stack : '')
1167
+ );
1168
+ }
1169
+ }
1170
+ }
1171
+ }
1172
+ }
1173
+
1174
+ /**
1175
+ * Resets warning cache when testing.
1176
+ *
1177
+ * @private
1178
+ */
1179
+ checkPropTypes.resetWarningCache = function() {
1180
+ if (process.env.NODE_ENV !== 'production') {
1181
+ loggedTypeFailures = {};
1182
+ }
1183
+ };
1184
+
1185
+ checkPropTypes_1 = checkPropTypes;
1186
+ return checkPropTypes_1;
1187
+ }
1188
+
1189
+ /**
1190
+ * Copyright (c) 2013-present, Facebook, Inc.
1191
+ *
1192
+ * This source code is licensed under the MIT license found in the
1193
+ * LICENSE file in the root directory of this source tree.
1194
+ */
1195
+
1196
+ var factoryWithTypeCheckers;
1197
+ var hasRequiredFactoryWithTypeCheckers;
1198
+
1199
+ function requireFactoryWithTypeCheckers () {
1200
+ if (hasRequiredFactoryWithTypeCheckers) return factoryWithTypeCheckers;
1201
+ hasRequiredFactoryWithTypeCheckers = 1;
1202
+
1203
+ var ReactIs = requireReactIs();
1204
+ var assign = requireObjectAssign();
1205
+
1206
+ var ReactPropTypesSecret = /*@__PURE__*/ requireReactPropTypesSecret();
1207
+ var has = /*@__PURE__*/ requireHas();
1208
+ var checkPropTypes = /*@__PURE__*/ requireCheckPropTypes();
1209
+
1210
+ var printWarning = function() {};
1211
+
1212
+ if (process.env.NODE_ENV !== 'production') {
1213
+ printWarning = function(text) {
1214
+ var message = 'Warning: ' + text;
1215
+ if (typeof console !== 'undefined') {
1216
+ console.error(message);
1217
+ }
1218
+ try {
1219
+ // --- Welcome to debugging React ---
1220
+ // This error was thrown as a convenience so that you can use this stack
1221
+ // to find the callsite that caused this warning to fire.
1222
+ throw new Error(message);
1223
+ } catch (x) {}
1224
+ };
1225
+ }
1226
+
1227
+ function emptyFunctionThatReturnsNull() {
1228
+ return null;
1229
+ }
1230
+
1231
+ factoryWithTypeCheckers = function(isValidElement, throwOnDirectAccess) {
1232
+ /* global Symbol */
1233
+ var ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator;
1234
+ var FAUX_ITERATOR_SYMBOL = '@@iterator'; // Before Symbol spec.
1235
+
1236
+ /**
1237
+ * Returns the iterator method function contained on the iterable object.
1238
+ *
1239
+ * Be sure to invoke the function with the iterable as context:
1240
+ *
1241
+ * var iteratorFn = getIteratorFn(myIterable);
1242
+ * if (iteratorFn) {
1243
+ * var iterator = iteratorFn.call(myIterable);
1244
+ * ...
1245
+ * }
1246
+ *
1247
+ * @param {?object} maybeIterable
1248
+ * @return {?function}
1249
+ */
1250
+ function getIteratorFn(maybeIterable) {
1251
+ var iteratorFn = maybeIterable && (ITERATOR_SYMBOL && maybeIterable[ITERATOR_SYMBOL] || maybeIterable[FAUX_ITERATOR_SYMBOL]);
1252
+ if (typeof iteratorFn === 'function') {
1253
+ return iteratorFn;
1254
+ }
1255
+ }
1256
+
1257
+ /**
1258
+ * Collection of methods that allow declaration and validation of props that are
1259
+ * supplied to React components. Example usage:
1260
+ *
1261
+ * var Props = require('ReactPropTypes');
1262
+ * var MyArticle = React.createClass({
1263
+ * propTypes: {
1264
+ * // An optional string prop named "description".
1265
+ * description: Props.string,
1266
+ *
1267
+ * // A required enum prop named "category".
1268
+ * category: Props.oneOf(['News','Photos']).isRequired,
1269
+ *
1270
+ * // A prop named "dialog" that requires an instance of Dialog.
1271
+ * dialog: Props.instanceOf(Dialog).isRequired
1272
+ * },
1273
+ * render: function() { ... }
1274
+ * });
1275
+ *
1276
+ * A more formal specification of how these methods are used:
1277
+ *
1278
+ * type := array|bool|func|object|number|string|oneOf([...])|instanceOf(...)
1279
+ * decl := ReactPropTypes.{type}(.isRequired)?
1280
+ *
1281
+ * Each and every declaration produces a function with the same signature. This
1282
+ * allows the creation of custom validation functions. For example:
1283
+ *
1284
+ * var MyLink = React.createClass({
1285
+ * propTypes: {
1286
+ * // An optional string or URI prop named "href".
1287
+ * href: function(props, propName, componentName) {
1288
+ * var propValue = props[propName];
1289
+ * if (propValue != null && typeof propValue !== 'string' &&
1290
+ * !(propValue instanceof URI)) {
1291
+ * return new Error(
1292
+ * 'Expected a string or an URI for ' + propName + ' in ' +
1293
+ * componentName
1294
+ * );
1295
+ * }
1296
+ * }
1297
+ * },
1298
+ * render: function() {...}
1299
+ * });
1300
+ *
1301
+ * @internal
1302
+ */
1303
+
1304
+ var ANONYMOUS = '<<anonymous>>';
1305
+
1306
+ // Important!
1307
+ // Keep this list in sync with production version in `./factoryWithThrowingShims.js`.
1308
+ var ReactPropTypes = {
1309
+ array: createPrimitiveTypeChecker('array'),
1310
+ bigint: createPrimitiveTypeChecker('bigint'),
1311
+ bool: createPrimitiveTypeChecker('boolean'),
1312
+ func: createPrimitiveTypeChecker('function'),
1313
+ number: createPrimitiveTypeChecker('number'),
1314
+ object: createPrimitiveTypeChecker('object'),
1315
+ string: createPrimitiveTypeChecker('string'),
1316
+ symbol: createPrimitiveTypeChecker('symbol'),
1317
+
1318
+ any: createAnyTypeChecker(),
1319
+ arrayOf: createArrayOfTypeChecker,
1320
+ element: createElementTypeChecker(),
1321
+ elementType: createElementTypeTypeChecker(),
1322
+ instanceOf: createInstanceTypeChecker,
1323
+ node: createNodeChecker(),
1324
+ objectOf: createObjectOfTypeChecker,
1325
+ oneOf: createEnumTypeChecker,
1326
+ oneOfType: createUnionTypeChecker,
1327
+ shape: createShapeTypeChecker,
1328
+ exact: createStrictShapeTypeChecker,
1329
+ };
1330
+
1331
+ /**
1332
+ * inlined Object.is polyfill to avoid requiring consumers ship their own
1333
+ * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
1334
+ */
1335
+ /*eslint-disable no-self-compare*/
1336
+ function is(x, y) {
1337
+ // SameValue algorithm
1338
+ if (x === y) {
1339
+ // Steps 1-5, 7-10
1340
+ // Steps 6.b-6.e: +0 != -0
1341
+ return x !== 0 || 1 / x === 1 / y;
1342
+ } else {
1343
+ // Step 6.a: NaN == NaN
1344
+ return x !== x && y !== y;
1345
+ }
1346
+ }
1347
+ /*eslint-enable no-self-compare*/
1348
+
1349
+ /**
1350
+ * We use an Error-like object for backward compatibility as people may call
1351
+ * PropTypes directly and inspect their output. However, we don't use real
1352
+ * Errors anymore. We don't inspect their stack anyway, and creating them
1353
+ * is prohibitively expensive if they are created too often, such as what
1354
+ * happens in oneOfType() for any type before the one that matched.
1355
+ */
1356
+ function PropTypeError(message, data) {
1357
+ this.message = message;
1358
+ this.data = data && typeof data === 'object' ? data: {};
1359
+ this.stack = '';
1360
+ }
1361
+ // Make `instanceof Error` still work for returned errors.
1362
+ PropTypeError.prototype = Error.prototype;
1363
+
1364
+ function createChainableTypeChecker(validate) {
1365
+ if (process.env.NODE_ENV !== 'production') {
1366
+ var manualPropTypeCallCache = {};
1367
+ var manualPropTypeWarningCount = 0;
1368
+ }
1369
+ function checkType(isRequired, props, propName, componentName, location, propFullName, secret) {
1370
+ componentName = componentName || ANONYMOUS;
1371
+ propFullName = propFullName || propName;
1372
+
1373
+ if (secret !== ReactPropTypesSecret) {
1374
+ if (throwOnDirectAccess) {
1375
+ // New behavior only for users of `prop-types` package
1376
+ var err = new Error(
1377
+ 'Calling PropTypes validators directly is not supported by the `prop-types` package. ' +
1378
+ 'Use `PropTypes.checkPropTypes()` to call them. ' +
1379
+ 'Read more at http://fb.me/use-check-prop-types'
1380
+ );
1381
+ err.name = 'Invariant Violation';
1382
+ throw err;
1383
+ } else if (process.env.NODE_ENV !== 'production' && typeof console !== 'undefined') {
1384
+ // Old behavior for people using React.PropTypes
1385
+ var cacheKey = componentName + ':' + propName;
1386
+ if (
1387
+ !manualPropTypeCallCache[cacheKey] &&
1388
+ // Avoid spamming the console because they are often not actionable except for lib authors
1389
+ manualPropTypeWarningCount < 3
1390
+ ) {
1391
+ printWarning(
1392
+ 'You are manually calling a React.PropTypes validation ' +
1393
+ 'function for the `' + propFullName + '` prop on `' + componentName + '`. This is deprecated ' +
1394
+ 'and will throw in the standalone `prop-types` package. ' +
1395
+ 'You may be seeing this warning due to a third-party PropTypes ' +
1396
+ 'library. See https://fb.me/react-warning-dont-call-proptypes ' + 'for details.'
1397
+ );
1398
+ manualPropTypeCallCache[cacheKey] = true;
1399
+ manualPropTypeWarningCount++;
1400
+ }
1401
+ }
1402
+ }
1403
+ if (props[propName] == null) {
1404
+ if (isRequired) {
1405
+ if (props[propName] === null) {
1406
+ return new PropTypeError('The ' + location + ' `' + propFullName + '` is marked as required ' + ('in `' + componentName + '`, but its value is `null`.'));
1407
+ }
1408
+ return new PropTypeError('The ' + location + ' `' + propFullName + '` is marked as required in ' + ('`' + componentName + '`, but its value is `undefined`.'));
1409
+ }
1410
+ return null;
1411
+ } else {
1412
+ return validate(props, propName, componentName, location, propFullName);
1413
+ }
1414
+ }
1415
+
1416
+ var chainedCheckType = checkType.bind(null, false);
1417
+ chainedCheckType.isRequired = checkType.bind(null, true);
1418
+
1419
+ return chainedCheckType;
1420
+ }
1421
+
1422
+ function createPrimitiveTypeChecker(expectedType) {
1423
+ function validate(props, propName, componentName, location, propFullName, secret) {
1424
+ var propValue = props[propName];
1425
+ var propType = getPropType(propValue);
1426
+ if (propType !== expectedType) {
1427
+ // `propValue` being instance of, say, date/regexp, pass the 'object'
1428
+ // check, but we can offer a more precise error message here rather than
1429
+ // 'of type `object`'.
1430
+ var preciseType = getPreciseType(propValue);
1431
+
1432
+ return new PropTypeError(
1433
+ 'Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + preciseType + '` supplied to `' + componentName + '`, expected ') + ('`' + expectedType + '`.'),
1434
+ {expectedType: expectedType}
1435
+ );
1436
+ }
1437
+ return null;
1438
+ }
1439
+ return createChainableTypeChecker(validate);
1440
+ }
1441
+
1442
+ function createAnyTypeChecker() {
1443
+ return createChainableTypeChecker(emptyFunctionThatReturnsNull);
1444
+ }
1445
+
1446
+ function createArrayOfTypeChecker(typeChecker) {
1447
+ function validate(props, propName, componentName, location, propFullName) {
1448
+ if (typeof typeChecker !== 'function') {
1449
+ return new PropTypeError('Property `' + propFullName + '` of component `' + componentName + '` has invalid PropType notation inside arrayOf.');
1450
+ }
1451
+ var propValue = props[propName];
1452
+ if (!Array.isArray(propValue)) {
1453
+ var propType = getPropType(propValue);
1454
+ return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected an array.'));
1455
+ }
1456
+ for (var i = 0; i < propValue.length; i++) {
1457
+ var error = typeChecker(propValue, i, componentName, location, propFullName + '[' + i + ']', ReactPropTypesSecret);
1458
+ if (error instanceof Error) {
1459
+ return error;
1460
+ }
1461
+ }
1462
+ return null;
1463
+ }
1464
+ return createChainableTypeChecker(validate);
1465
+ }
1466
+
1467
+ function createElementTypeChecker() {
1468
+ function validate(props, propName, componentName, location, propFullName) {
1469
+ var propValue = props[propName];
1470
+ if (!isValidElement(propValue)) {
1471
+ var propType = getPropType(propValue);
1472
+ return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected a single ReactElement.'));
1473
+ }
1474
+ return null;
1475
+ }
1476
+ return createChainableTypeChecker(validate);
1477
+ }
1478
+
1479
+ function createElementTypeTypeChecker() {
1480
+ function validate(props, propName, componentName, location, propFullName) {
1481
+ var propValue = props[propName];
1482
+ if (!ReactIs.isValidElementType(propValue)) {
1483
+ var propType = getPropType(propValue);
1484
+ return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected a single ReactElement type.'));
1485
+ }
1486
+ return null;
1487
+ }
1488
+ return createChainableTypeChecker(validate);
1489
+ }
1490
+
1491
+ function createInstanceTypeChecker(expectedClass) {
1492
+ function validate(props, propName, componentName, location, propFullName) {
1493
+ if (!(props[propName] instanceof expectedClass)) {
1494
+ var expectedClassName = expectedClass.name || ANONYMOUS;
1495
+ var actualClassName = getClassName(props[propName]);
1496
+ return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + actualClassName + '` supplied to `' + componentName + '`, expected ') + ('instance of `' + expectedClassName + '`.'));
1497
+ }
1498
+ return null;
1499
+ }
1500
+ return createChainableTypeChecker(validate);
1501
+ }
1502
+
1503
+ function createEnumTypeChecker(expectedValues) {
1504
+ if (!Array.isArray(expectedValues)) {
1505
+ if (process.env.NODE_ENV !== 'production') {
1506
+ if (arguments.length > 1) {
1507
+ printWarning(
1508
+ 'Invalid arguments supplied to oneOf, expected an array, got ' + arguments.length + ' arguments. ' +
1509
+ 'A common mistake is to write oneOf(x, y, z) instead of oneOf([x, y, z]).'
1510
+ );
1511
+ } else {
1512
+ printWarning('Invalid argument supplied to oneOf, expected an array.');
1513
+ }
1514
+ }
1515
+ return emptyFunctionThatReturnsNull;
1516
+ }
1517
+
1518
+ function validate(props, propName, componentName, location, propFullName) {
1519
+ var propValue = props[propName];
1520
+ for (var i = 0; i < expectedValues.length; i++) {
1521
+ if (is(propValue, expectedValues[i])) {
1522
+ return null;
1523
+ }
1524
+ }
1525
+
1526
+ var valuesString = JSON.stringify(expectedValues, function replacer(key, value) {
1527
+ var type = getPreciseType(value);
1528
+ if (type === 'symbol') {
1529
+ return String(value);
1530
+ }
1531
+ return value;
1532
+ });
1533
+ return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of value `' + String(propValue) + '` ' + ('supplied to `' + componentName + '`, expected one of ' + valuesString + '.'));
1534
+ }
1535
+ return createChainableTypeChecker(validate);
1536
+ }
1537
+
1538
+ function createObjectOfTypeChecker(typeChecker) {
1539
+ function validate(props, propName, componentName, location, propFullName) {
1540
+ if (typeof typeChecker !== 'function') {
1541
+ return new PropTypeError('Property `' + propFullName + '` of component `' + componentName + '` has invalid PropType notation inside objectOf.');
1542
+ }
1543
+ var propValue = props[propName];
1544
+ var propType = getPropType(propValue);
1545
+ if (propType !== 'object') {
1546
+ return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected an object.'));
1547
+ }
1548
+ for (var key in propValue) {
1549
+ if (has(propValue, key)) {
1550
+ var error = typeChecker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret);
1551
+ if (error instanceof Error) {
1552
+ return error;
1553
+ }
1554
+ }
1555
+ }
1556
+ return null;
1557
+ }
1558
+ return createChainableTypeChecker(validate);
1559
+ }
1560
+
1561
+ function createUnionTypeChecker(arrayOfTypeCheckers) {
1562
+ if (!Array.isArray(arrayOfTypeCheckers)) {
1563
+ process.env.NODE_ENV !== 'production' ? printWarning('Invalid argument supplied to oneOfType, expected an instance of array.') : void 0;
1564
+ return emptyFunctionThatReturnsNull;
1565
+ }
1566
+
1567
+ for (var i = 0; i < arrayOfTypeCheckers.length; i++) {
1568
+ var checker = arrayOfTypeCheckers[i];
1569
+ if (typeof checker !== 'function') {
1570
+ printWarning(
1571
+ 'Invalid argument supplied to oneOfType. Expected an array of check functions, but ' +
1572
+ 'received ' + getPostfixForTypeWarning(checker) + ' at index ' + i + '.'
1573
+ );
1574
+ return emptyFunctionThatReturnsNull;
1575
+ }
1576
+ }
1577
+
1578
+ function validate(props, propName, componentName, location, propFullName) {
1579
+ var expectedTypes = [];
1580
+ for (var i = 0; i < arrayOfTypeCheckers.length; i++) {
1581
+ var checker = arrayOfTypeCheckers[i];
1582
+ var checkerResult = checker(props, propName, componentName, location, propFullName, ReactPropTypesSecret);
1583
+ if (checkerResult == null) {
1584
+ return null;
1585
+ }
1586
+ if (checkerResult.data && has(checkerResult.data, 'expectedType')) {
1587
+ expectedTypes.push(checkerResult.data.expectedType);
1588
+ }
1589
+ }
1590
+ var expectedTypesMessage = (expectedTypes.length > 0) ? ', expected one of type [' + expectedTypes.join(', ') + ']': '';
1591
+ return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`' + expectedTypesMessage + '.'));
1592
+ }
1593
+ return createChainableTypeChecker(validate);
1594
+ }
1595
+
1596
+ function createNodeChecker() {
1597
+ function validate(props, propName, componentName, location, propFullName) {
1598
+ if (!isNode(props[propName])) {
1599
+ return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`, expected a ReactNode.'));
1600
+ }
1601
+ return null;
1602
+ }
1603
+ return createChainableTypeChecker(validate);
1604
+ }
1605
+
1606
+ function invalidValidatorError(componentName, location, propFullName, key, type) {
1607
+ return new PropTypeError(
1608
+ (componentName || 'React class') + ': ' + location + ' type `' + propFullName + '.' + key + '` is invalid; ' +
1609
+ 'it must be a function, usually from the `prop-types` package, but received `' + type + '`.'
1610
+ );
1611
+ }
1612
+
1613
+ function createShapeTypeChecker(shapeTypes) {
1614
+ function validate(props, propName, componentName, location, propFullName) {
1615
+ var propValue = props[propName];
1616
+ var propType = getPropType(propValue);
1617
+ if (propType !== 'object') {
1618
+ return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type `' + propType + '` ' + ('supplied to `' + componentName + '`, expected `object`.'));
1619
+ }
1620
+ for (var key in shapeTypes) {
1621
+ var checker = shapeTypes[key];
1622
+ if (typeof checker !== 'function') {
1623
+ return invalidValidatorError(componentName, location, propFullName, key, getPreciseType(checker));
1624
+ }
1625
+ var error = checker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret);
1626
+ if (error) {
1627
+ return error;
1628
+ }
1629
+ }
1630
+ return null;
1631
+ }
1632
+ return createChainableTypeChecker(validate);
1633
+ }
1634
+
1635
+ function createStrictShapeTypeChecker(shapeTypes) {
1636
+ function validate(props, propName, componentName, location, propFullName) {
1637
+ var propValue = props[propName];
1638
+ var propType = getPropType(propValue);
1639
+ if (propType !== 'object') {
1640
+ return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type `' + propType + '` ' + ('supplied to `' + componentName + '`, expected `object`.'));
1641
+ }
1642
+ // We need to check all keys in case some are required but missing from props.
1643
+ var allKeys = assign({}, props[propName], shapeTypes);
1644
+ for (var key in allKeys) {
1645
+ var checker = shapeTypes[key];
1646
+ if (has(shapeTypes, key) && typeof checker !== 'function') {
1647
+ return invalidValidatorError(componentName, location, propFullName, key, getPreciseType(checker));
1648
+ }
1649
+ if (!checker) {
1650
+ return new PropTypeError(
1651
+ 'Invalid ' + location + ' `' + propFullName + '` key `' + key + '` supplied to `' + componentName + '`.' +
1652
+ '\nBad object: ' + JSON.stringify(props[propName], null, ' ') +
1653
+ '\nValid keys: ' + JSON.stringify(Object.keys(shapeTypes), null, ' ')
1654
+ );
1655
+ }
1656
+ var error = checker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret);
1657
+ if (error) {
1658
+ return error;
1659
+ }
1660
+ }
1661
+ return null;
1662
+ }
1663
+
1664
+ return createChainableTypeChecker(validate);
1665
+ }
1666
+
1667
+ function isNode(propValue) {
1668
+ switch (typeof propValue) {
1669
+ case 'number':
1670
+ case 'string':
1671
+ case 'undefined':
1672
+ return true;
1673
+ case 'boolean':
1674
+ return !propValue;
1675
+ case 'object':
1676
+ if (Array.isArray(propValue)) {
1677
+ return propValue.every(isNode);
1678
+ }
1679
+ if (propValue === null || isValidElement(propValue)) {
1680
+ return true;
1681
+ }
1682
+
1683
+ var iteratorFn = getIteratorFn(propValue);
1684
+ if (iteratorFn) {
1685
+ var iterator = iteratorFn.call(propValue);
1686
+ var step;
1687
+ if (iteratorFn !== propValue.entries) {
1688
+ while (!(step = iterator.next()).done) {
1689
+ if (!isNode(step.value)) {
1690
+ return false;
1691
+ }
1692
+ }
1693
+ } else {
1694
+ // Iterator will provide entry [k,v] tuples rather than values.
1695
+ while (!(step = iterator.next()).done) {
1696
+ var entry = step.value;
1697
+ if (entry) {
1698
+ if (!isNode(entry[1])) {
1699
+ return false;
1700
+ }
1701
+ }
1702
+ }
1703
+ }
1704
+ } else {
1705
+ return false;
1706
+ }
1707
+
1708
+ return true;
1709
+ default:
1710
+ return false;
1711
+ }
1712
+ }
1713
+
1714
+ function isSymbol(propType, propValue) {
1715
+ // Native Symbol.
1716
+ if (propType === 'symbol') {
1717
+ return true;
1718
+ }
1719
+
1720
+ // falsy value can't be a Symbol
1721
+ if (!propValue) {
1722
+ return false;
1723
+ }
1724
+
1725
+ // 19.4.3.5 Symbol.prototype[@@toStringTag] === 'Symbol'
1726
+ if (propValue['@@toStringTag'] === 'Symbol') {
1727
+ return true;
1728
+ }
1729
+
1730
+ // Fallback for non-spec compliant Symbols which are polyfilled.
1731
+ if (typeof Symbol === 'function' && propValue instanceof Symbol) {
1732
+ return true;
1733
+ }
1734
+
1735
+ return false;
1736
+ }
1737
+
1738
+ // Equivalent of `typeof` but with special handling for array and regexp.
1739
+ function getPropType(propValue) {
1740
+ var propType = typeof propValue;
1741
+ if (Array.isArray(propValue)) {
1742
+ return 'array';
1743
+ }
1744
+ if (propValue instanceof RegExp) {
1745
+ // Old webkits (at least until Android 4.0) return 'function' rather than
1746
+ // 'object' for typeof a RegExp. We'll normalize this here so that /bla/
1747
+ // passes PropTypes.object.
1748
+ return 'object';
1749
+ }
1750
+ if (isSymbol(propType, propValue)) {
1751
+ return 'symbol';
1752
+ }
1753
+ return propType;
1754
+ }
1755
+
1756
+ // This handles more types than `getPropType`. Only used for error messages.
1757
+ // See `createPrimitiveTypeChecker`.
1758
+ function getPreciseType(propValue) {
1759
+ if (typeof propValue === 'undefined' || propValue === null) {
1760
+ return '' + propValue;
1761
+ }
1762
+ var propType = getPropType(propValue);
1763
+ if (propType === 'object') {
1764
+ if (propValue instanceof Date) {
1765
+ return 'date';
1766
+ } else if (propValue instanceof RegExp) {
1767
+ return 'regexp';
1768
+ }
1769
+ }
1770
+ return propType;
1771
+ }
1772
+
1773
+ // Returns a string that is postfixed to a warning about an invalid type.
1774
+ // For example, "undefined" or "of type array"
1775
+ function getPostfixForTypeWarning(value) {
1776
+ var type = getPreciseType(value);
1777
+ switch (type) {
1778
+ case 'array':
1779
+ case 'object':
1780
+ return 'an ' + type;
1781
+ case 'boolean':
1782
+ case 'date':
1783
+ case 'regexp':
1784
+ return 'a ' + type;
1785
+ default:
1786
+ return type;
1787
+ }
1788
+ }
1789
+
1790
+ // Returns class name of the object, if any.
1791
+ function getClassName(propValue) {
1792
+ if (!propValue.constructor || !propValue.constructor.name) {
1793
+ return ANONYMOUS;
1794
+ }
1795
+ return propValue.constructor.name;
1796
+ }
1797
+
1798
+ ReactPropTypes.checkPropTypes = checkPropTypes;
1799
+ ReactPropTypes.resetWarningCache = checkPropTypes.resetWarningCache;
1800
+ ReactPropTypes.PropTypes = ReactPropTypes;
1801
+
1802
+ return ReactPropTypes;
1803
+ };
1804
+ return factoryWithTypeCheckers;
1805
+ }
1806
+
1807
+ /**
1808
+ * Copyright (c) 2013-present, Facebook, Inc.
1809
+ *
1810
+ * This source code is licensed under the MIT license found in the
1811
+ * LICENSE file in the root directory of this source tree.
1812
+ */
1813
+
1814
+ var factoryWithThrowingShims;
1815
+ var hasRequiredFactoryWithThrowingShims;
1816
+
1817
+ function requireFactoryWithThrowingShims () {
1818
+ if (hasRequiredFactoryWithThrowingShims) return factoryWithThrowingShims;
1819
+ hasRequiredFactoryWithThrowingShims = 1;
1820
+
1821
+ var ReactPropTypesSecret = /*@__PURE__*/ requireReactPropTypesSecret();
1822
+
1823
+ function emptyFunction() {}
1824
+ function emptyFunctionWithReset() {}
1825
+ emptyFunctionWithReset.resetWarningCache = emptyFunction;
1826
+
1827
+ factoryWithThrowingShims = function() {
1828
+ function shim(props, propName, componentName, location, propFullName, secret) {
1829
+ if (secret === ReactPropTypesSecret) {
1830
+ // It is still safe when called from React.
1831
+ return;
1832
+ }
1833
+ var err = new Error(
1834
+ 'Calling PropTypes validators directly is not supported by the `prop-types` package. ' +
1835
+ 'Use PropTypes.checkPropTypes() to call them. ' +
1836
+ 'Read more at http://fb.me/use-check-prop-types'
1837
+ );
1838
+ err.name = 'Invariant Violation';
1839
+ throw err;
1840
+ } shim.isRequired = shim;
1841
+ function getShim() {
1842
+ return shim;
1843
+ } // Important!
1844
+ // Keep this list in sync with production version in `./factoryWithTypeCheckers.js`.
1845
+ var ReactPropTypes = {
1846
+ array: shim,
1847
+ bigint: shim,
1848
+ bool: shim,
1849
+ func: shim,
1850
+ number: shim,
1851
+ object: shim,
1852
+ string: shim,
1853
+ symbol: shim,
1854
+
1855
+ any: shim,
1856
+ arrayOf: getShim,
1857
+ element: shim,
1858
+ elementType: shim,
1859
+ instanceOf: getShim,
1860
+ node: shim,
1861
+ objectOf: getShim,
1862
+ oneOf: getShim,
1863
+ oneOfType: getShim,
1864
+ shape: getShim,
1865
+ exact: getShim,
1866
+
1867
+ checkPropTypes: emptyFunctionWithReset,
1868
+ resetWarningCache: emptyFunction
1869
+ };
1870
+
1871
+ ReactPropTypes.PropTypes = ReactPropTypes;
1872
+
1873
+ return ReactPropTypes;
1874
+ };
1875
+ return factoryWithThrowingShims;
1876
+ }
1877
+
1878
+ /**
1879
+ * Copyright (c) 2013-present, Facebook, Inc.
1880
+ *
1881
+ * This source code is licensed under the MIT license found in the
1882
+ * LICENSE file in the root directory of this source tree.
1883
+ */
1884
+
1885
+ var hasRequiredPropTypes;
1886
+
1887
+ function requirePropTypes () {
1888
+ if (hasRequiredPropTypes) return propTypes.exports;
1889
+ hasRequiredPropTypes = 1;
1890
+ if (process.env.NODE_ENV !== 'production') {
1891
+ var ReactIs = requireReactIs();
1892
+
1893
+ // By explicitly using `prop-types` you are opting into new development behavior.
1894
+ // http://fb.me/prop-types-in-prod
1895
+ var throwOnDirectAccess = true;
1896
+ propTypes.exports = /*@__PURE__*/ requireFactoryWithTypeCheckers()(ReactIs.isElement, throwOnDirectAccess);
1897
+ } else {
1898
+ // By explicitly using `prop-types` you are opting into new production behavior.
1899
+ // http://fb.me/prop-types-in-prod
1900
+ propTypes.exports = /*@__PURE__*/ requireFactoryWithThrowingShims()();
1901
+ }
1902
+ return propTypes.exports;
1903
+ }
1904
+
1905
+ var propTypesExports = /*@__PURE__*/ requirePropTypes();
1906
+ var PropTypes = /*@__PURE__*/getDefaultExportFromCjs(propTypesExports);
1907
+
1908
+ const SystemOperations = _ref => {
1909
+ let {
1910
+ onPowerOff,
1911
+ onRestart,
1912
+ powerOffLabel = "Power Off",
1913
+ restartLabel = "Restart",
1914
+ iconClassName = "iconfont icon-guanji1 text-2xl text-neutral-400",
1915
+ confirmTitle = "Confirm",
1916
+ cancelText = "No",
1917
+ okText = "Yes"
1918
+ } = _ref;
1919
+ const {
1920
+ modal: AntdModal
1921
+ } = antd.App.useApp();
1922
+ const menuItems = [{
1923
+ key: "poweroff",
1924
+ label: powerOffLabel
1925
+ },
1926
+ // {
1927
+ // key: "reboot",
1928
+ // label: rebootLabel, // 硬重启 物理重启
1929
+ // },
1930
+ {
1931
+ key: "restart",
1932
+ label: restartLabel // 软重启 服务重启
1933
+ }];
1934
+ const doAction = action => {
1935
+ try {
1936
+ AntdModal.confirm({
1937
+ icon: /*#__PURE__*/jsxRuntime.jsx(icons.ExclamationCircleFilled, {}),
1938
+ title: `${confirmTitle} ${action}?`,
1939
+ cancelText,
1940
+ okText,
1941
+ onOk: () => {
1942
+ if (action === 'poweroff' && onPowerOff) {
1943
+ onPowerOff();
1944
+ } else if (action === 'restart' && onRestart) {
1945
+ onRestart();
1946
+ }
1947
+ }
1948
+ });
1949
+ } catch (error) {
1950
+ console.error(`${action.toUpperCase()} ERROR: `, error);
1951
+ }
1952
+ };
1953
+ const handleMenuClick = _ref2 => {
1954
+ let {
1955
+ key
1956
+ } = _ref2;
1957
+ doAction(key);
1958
+ };
1959
+ return /*#__PURE__*/jsxRuntime.jsx(antd.Dropdown, {
1960
+ menu: {
1961
+ items: menuItems,
1962
+ onClick: handleMenuClick
1963
+ },
1964
+ trigger: ["hover"],
1965
+ children: /*#__PURE__*/jsxRuntime.jsx("a", {
1966
+ onClick: e => e.preventDefault(),
1967
+ children: /*#__PURE__*/jsxRuntime.jsx("i", {
1968
+ className: iconClassName
1969
+ })
1970
+ })
1971
+ });
1972
+ };
1973
+ SystemOperations.propTypes = {
1974
+ onPowerOff: PropTypes.func,
1975
+ onRestart: PropTypes.func,
1976
+ powerOffLabel: PropTypes.string,
1977
+ restartLabel: PropTypes.string,
1978
+ iconClassName: PropTypes.string,
1979
+ confirmTitle: PropTypes.string,
1980
+ cancelText: PropTypes.string,
1981
+ okText: PropTypes.string
1982
+ };
1983
+
1984
+ exports.AuthorizationModal = AuthorizationModal;
1985
+ exports.SystemOperations = SystemOperations;
1986
+ exports.UpgradeManager = UpgradeManager;
1987
+ exports.useAuth = useAuth;
1988
+ exports.useHardwareUsage = useHardwareUsage;
1989
+ exports.useHardwareWebSocket = useHardwareWebSocket;
1990
+ exports.useSystemOperations = useSystemOperations;
1991
+ exports.useUpgrade = useUpgrade;
1992
+ //# sourceMappingURL=index.js.map