seeder-st2110-components 1.6.0 → 1.6.2
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.css +1 -1
- package/dist/index.esm.js +467 -76
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +525 -133
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/styles/index.less +34 -0
package/dist/index.esm.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { memo, useState, useCallback, useMemo, useEffect, useRef } from 'react';
|
|
1
|
+
import React, { memo, useState, useCallback, useMemo, useEffect, useRef } from 'react';
|
|
2
2
|
import { Tooltip, App, Modal, Form, Input, Alert, message, Dropdown, Spin, Divider, Typography, InputNumber, ConfigProvider, Badge, Switch, Select, List, Empty, Button, Space, Flex, Checkbox, Row, Col } from 'antd';
|
|
3
3
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
4
4
|
import { useWebSocket, useInterval } from 'ahooks';
|
|
@@ -1086,16 +1086,13 @@ const NetworkSettingsModal = _ref2 => {
|
|
|
1086
1086
|
const allSucceeded = results.every(result => result.status === 'fulfilled');
|
|
1087
1087
|
if (allSucceeded) {
|
|
1088
1088
|
handleSuccess();
|
|
1089
|
-
} else {
|
|
1090
|
-
message.error('Some configurations failed to update');
|
|
1091
1089
|
}
|
|
1092
1090
|
} catch (error) {
|
|
1093
1091
|
console.error('Failed to update configurations: ', error);
|
|
1094
|
-
message.error('Failed to update configurations');
|
|
1095
1092
|
} finally {
|
|
1096
1093
|
setSubmitLoading(false);
|
|
1097
1094
|
}
|
|
1098
|
-
}, [form, sections, lanConfigs, st2110Interfaces, updateLanConfig, updateSysConfig, handleSuccess
|
|
1095
|
+
}, [form, sections, lanConfigs, st2110Interfaces, updateLanConfig, updateSysConfig, handleSuccess]);
|
|
1099
1096
|
|
|
1100
1097
|
// 合并默认模态框属性和传入的属性
|
|
1101
1098
|
const mergedModalProps = _objectSpread2({
|
|
@@ -1407,7 +1404,7 @@ const LeftList = /*#__PURE__*/memo(_ref => {
|
|
|
1407
1404
|
showDescription = false,
|
|
1408
1405
|
texts = {
|
|
1409
1406
|
newButton: "New Preset",
|
|
1410
|
-
removeButton: "
|
|
1407
|
+
removeButton: "Delete"
|
|
1411
1408
|
}
|
|
1412
1409
|
} = _ref;
|
|
1413
1410
|
// 动态计算列布局
|
|
@@ -1418,7 +1415,7 @@ const LeftList = /*#__PURE__*/memo(_ref => {
|
|
|
1418
1415
|
className: "list-container",
|
|
1419
1416
|
children: /*#__PURE__*/jsx(List, {
|
|
1420
1417
|
header: /*#__PURE__*/jsxs("div", {
|
|
1421
|
-
className: "grid ".concat(gridColumns, " w-full list-header"),
|
|
1418
|
+
className: "grid ".concat(gridColumns, " gap-2 w-full list-header"),
|
|
1422
1419
|
children: [/*#__PURE__*/jsx("div", {
|
|
1423
1420
|
children: "Name"
|
|
1424
1421
|
}), /*#__PURE__*/jsx("div", {
|
|
@@ -1436,14 +1433,27 @@ const LeftList = /*#__PURE__*/memo(_ref => {
|
|
|
1436
1433
|
},
|
|
1437
1434
|
onClick: () => onSelectPreset(item),
|
|
1438
1435
|
children: /*#__PURE__*/jsxs("div", {
|
|
1439
|
-
className: "grid ".concat(gridColumns, " w-full text-text-normal"),
|
|
1436
|
+
className: "grid ".concat(gridColumns, " gap-2 w-full text-text-normal"),
|
|
1440
1437
|
children: [/*#__PURE__*/jsx("div", {
|
|
1441
|
-
|
|
1442
|
-
children:
|
|
1438
|
+
className: "min-w-0",
|
|
1439
|
+
children: /*#__PURE__*/jsx(Typography.Text, {
|
|
1440
|
+
ellipsis: true,
|
|
1441
|
+
title: item.name,
|
|
1442
|
+
children: item.name || "Untitled Preset"
|
|
1443
|
+
})
|
|
1443
1444
|
}), /*#__PURE__*/jsx("div", {
|
|
1444
|
-
|
|
1445
|
+
className: "min-w-0",
|
|
1446
|
+
children: /*#__PURE__*/jsx(Typography.Text, {
|
|
1447
|
+
ellipsis: true,
|
|
1448
|
+
children: item.create_time
|
|
1449
|
+
})
|
|
1445
1450
|
}), showDescription && /*#__PURE__*/jsx("div", {
|
|
1446
|
-
|
|
1451
|
+
className: "min-w-0",
|
|
1452
|
+
children: /*#__PURE__*/jsx(Typography.Text, {
|
|
1453
|
+
ellipsis: true,
|
|
1454
|
+
title: item.description,
|
|
1455
|
+
children: item.description
|
|
1456
|
+
})
|
|
1447
1457
|
})]
|
|
1448
1458
|
})
|
|
1449
1459
|
}),
|
|
@@ -1459,7 +1469,7 @@ const LeftList = /*#__PURE__*/memo(_ref => {
|
|
|
1459
1469
|
onClick: onAddNew,
|
|
1460
1470
|
className: "p-0 h-auto",
|
|
1461
1471
|
icon: /*#__PURE__*/jsx(PlusOutlined, {}),
|
|
1462
|
-
children: "Create
|
|
1472
|
+
children: "Create New Preset"
|
|
1463
1473
|
})
|
|
1464
1474
|
})
|
|
1465
1475
|
})
|
|
@@ -1475,18 +1485,16 @@ const LeftList = /*#__PURE__*/memo(_ref => {
|
|
|
1475
1485
|
size: "middle",
|
|
1476
1486
|
children: [/*#__PURE__*/jsx(Button, {
|
|
1477
1487
|
type: "default",
|
|
1478
|
-
icon: /*#__PURE__*/jsx(PlusOutlined, {})
|
|
1479
|
-
style:
|
|
1480
|
-
|
|
1481
|
-
},
|
|
1488
|
+
icon: /*#__PURE__*/jsx(PlusOutlined, {})
|
|
1489
|
+
// style={{ padding: "20px 12px" }}
|
|
1490
|
+
,
|
|
1482
1491
|
className: "btn-gray",
|
|
1483
1492
|
onClick: onAddNew,
|
|
1484
1493
|
children: texts.newButton
|
|
1485
1494
|
}), /*#__PURE__*/jsx(Button, {
|
|
1486
|
-
type: "default"
|
|
1487
|
-
style:
|
|
1488
|
-
|
|
1489
|
-
},
|
|
1495
|
+
type: "default"
|
|
1496
|
+
// style={{ padding: "20px 12px" }}
|
|
1497
|
+
,
|
|
1490
1498
|
className: "btn-gray",
|
|
1491
1499
|
onClick: onRemove,
|
|
1492
1500
|
children: texts.removeButton
|
|
@@ -1523,8 +1531,8 @@ const RightDetailForm = /*#__PURE__*/memo(_ref3 => {
|
|
|
1523
1531
|
originalPresetData,
|
|
1524
1532
|
fields = {
|
|
1525
1533
|
name: {
|
|
1526
|
-
label: "
|
|
1527
|
-
placeholder: "
|
|
1534
|
+
label: "Name",
|
|
1535
|
+
placeholder: "Please enter name",
|
|
1528
1536
|
required: true
|
|
1529
1537
|
}
|
|
1530
1538
|
},
|
|
@@ -1532,7 +1540,7 @@ const RightDetailForm = /*#__PURE__*/memo(_ref3 => {
|
|
|
1532
1540
|
loadButton: "Load",
|
|
1533
1541
|
saveButton: "Save"
|
|
1534
1542
|
},
|
|
1535
|
-
presetChanged
|
|
1543
|
+
presetChanged // 作用:在切换选中预设时强制触发 Checkbox 的重新初始化
|
|
1536
1544
|
} = _ref3;
|
|
1537
1545
|
const [initialSelected, setInitialSelected] = useState([]);
|
|
1538
1546
|
const currentSelected = Form.useWatch('category_list', form) || [];
|
|
@@ -1592,32 +1600,40 @@ const RightDetailForm = /*#__PURE__*/memo(_ref3 => {
|
|
|
1592
1600
|
},
|
|
1593
1601
|
children: [/*#__PURE__*/jsx(Form.Item, {
|
|
1594
1602
|
name: "name",
|
|
1595
|
-
label: fields.name.label
|
|
1596
|
-
rules
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
}
|
|
1603
|
+
label: fields.name.label
|
|
1604
|
+
// rules={[
|
|
1605
|
+
// {
|
|
1606
|
+
// required: fields.name.required,
|
|
1607
|
+
// validator: async (_, value) => {
|
|
1608
|
+
// if (!value || value.trim() === '') {
|
|
1609
|
+
// return Promise.reject(new Error('Preset name cannot be empty or spaces only'));
|
|
1610
|
+
// }
|
|
1611
|
+
// }
|
|
1612
|
+
// }
|
|
1613
|
+
// ]}
|
|
1614
|
+
,
|
|
1615
|
+
required: true,
|
|
1604
1616
|
children: /*#__PURE__*/jsx(Input, {
|
|
1605
1617
|
placeholder: fields.name.placeholder,
|
|
1606
1618
|
disabled: isEditing
|
|
1607
1619
|
})
|
|
1608
1620
|
}), hasCategoryList && /*#__PURE__*/jsx(Form.Item, {
|
|
1609
1621
|
name: "category_list",
|
|
1610
|
-
label: fields.category_list.label
|
|
1611
|
-
rules
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
}
|
|
1622
|
+
label: fields.category_list.label
|
|
1623
|
+
// rules={[
|
|
1624
|
+
// {
|
|
1625
|
+
// required: fields.category_list.required,
|
|
1626
|
+
// message: 'Please select at least one category',
|
|
1627
|
+
// validator: (_, value) => {
|
|
1628
|
+
// if (value && value.length > 0) {
|
|
1629
|
+
// return Promise.resolve();
|
|
1630
|
+
// }
|
|
1631
|
+
// return Promise.reject(new Error('Please select at least one category'));
|
|
1632
|
+
// }
|
|
1633
|
+
// }
|
|
1634
|
+
// ]}
|
|
1635
|
+
,
|
|
1636
|
+
required: true,
|
|
1621
1637
|
children: /*#__PURE__*/jsx(Checkbox.Group, {
|
|
1622
1638
|
className: "grid grid-cols-2 gap-2",
|
|
1623
1639
|
onChange: handleCheckboxChange,
|
|
@@ -1633,7 +1649,10 @@ const RightDetailForm = /*#__PURE__*/memo(_ref3 => {
|
|
|
1633
1649
|
children: /*#__PURE__*/jsx(Input.TextArea, {
|
|
1634
1650
|
rows: 4,
|
|
1635
1651
|
placeholder: fields.description.placeholder,
|
|
1636
|
-
disabled: isEditing
|
|
1652
|
+
disabled: isEditing,
|
|
1653
|
+
style: {
|
|
1654
|
+
resize: 'none'
|
|
1655
|
+
}
|
|
1637
1656
|
})
|
|
1638
1657
|
})]
|
|
1639
1658
|
}), isEditing ? /*#__PURE__*/jsx(SubmitButton, _objectSpread2(_objectSpread2({
|
|
@@ -1666,20 +1685,20 @@ const Preset = _ref => {
|
|
|
1666
1685
|
// 字段配置
|
|
1667
1686
|
fields = {
|
|
1668
1687
|
name: {
|
|
1669
|
-
label: "
|
|
1670
|
-
placeholder: "
|
|
1688
|
+
label: "Name",
|
|
1689
|
+
placeholder: "Please enter name",
|
|
1671
1690
|
required: true
|
|
1672
1691
|
}
|
|
1673
1692
|
},
|
|
1674
1693
|
texts = {
|
|
1675
1694
|
title: "Preset Management",
|
|
1676
1695
|
emptyText: "Select a preset from the list to view details",
|
|
1677
|
-
deleteConfirm: "Are you sure to delete preset",
|
|
1696
|
+
deleteConfirm: "Are you sure you want to delete preset",
|
|
1678
1697
|
loadConfirm: "Are you sure you want to load preset",
|
|
1679
1698
|
loadText: "Loading...",
|
|
1680
1699
|
successText: "Success",
|
|
1681
1700
|
newButton: "New Preset",
|
|
1682
|
-
removeButton: "
|
|
1701
|
+
removeButton: "Delete",
|
|
1683
1702
|
loadButton: "Load",
|
|
1684
1703
|
saveButton: "Save"
|
|
1685
1704
|
},
|
|
@@ -1697,16 +1716,19 @@ const Preset = _ref => {
|
|
|
1697
1716
|
const [loading, setLoading] = useState(false);
|
|
1698
1717
|
const [presetChanged, setPresetChanged] = useState(0);
|
|
1699
1718
|
const [form] = Form.useForm();
|
|
1700
|
-
|
|
1701
|
-
// 获取预设列表
|
|
1702
|
-
useEffect(() => {
|
|
1703
|
-
fetchPresetList();
|
|
1704
|
-
}, []);
|
|
1705
1719
|
const fetchPresetList = useCallback(async () => {
|
|
1706
1720
|
try {
|
|
1707
1721
|
const data = await getPresetList();
|
|
1708
1722
|
const presets = (data === null || data === void 0 ? void 0 : data.preset_list) || data || [];
|
|
1709
1723
|
setPresetList(presets);
|
|
1724
|
+
|
|
1725
|
+
// 自动选中第一个预设
|
|
1726
|
+
if (presets.length > 0) {
|
|
1727
|
+
const firstPreset = presets[0];
|
|
1728
|
+
setSelectedPreset(firstPreset);
|
|
1729
|
+
form.setFieldsValue(firstPreset);
|
|
1730
|
+
setPresetChanged(prev => prev + 1);
|
|
1731
|
+
}
|
|
1710
1732
|
} catch (error) {
|
|
1711
1733
|
console.error('Failed to fetch preset list:', error);
|
|
1712
1734
|
}
|
|
@@ -1714,7 +1736,7 @@ const Preset = _ref => {
|
|
|
1714
1736
|
const handleSelectPreset = useCallback(preset => {
|
|
1715
1737
|
setSelectedPreset(preset);
|
|
1716
1738
|
form.setFieldsValue(preset);
|
|
1717
|
-
setPresetChanged(prev => prev + 1);
|
|
1739
|
+
setPresetChanged(prev => prev + 1);
|
|
1718
1740
|
}, [form]);
|
|
1719
1741
|
const handleAddNew = useCallback(() => {
|
|
1720
1742
|
var _fields$category_list;
|
|
@@ -1752,18 +1774,44 @@ const Preset = _ref => {
|
|
|
1752
1774
|
cancelText: 'No',
|
|
1753
1775
|
okText: 'Yes',
|
|
1754
1776
|
onOk: async () => {
|
|
1777
|
+
// 在删除前记录当前选中项的位置
|
|
1778
|
+
const currentIndex = presetList.findIndex(item => isUnsavedPreset ? !item.id : item.id === selectedPreset.id);
|
|
1755
1779
|
if (!isUnsavedPreset) {
|
|
1756
1780
|
await removePreset({
|
|
1757
1781
|
id: selectedPreset.id
|
|
1758
1782
|
});
|
|
1759
1783
|
AntdMessage.success(texts.successText);
|
|
1760
|
-
// 刷新列表
|
|
1761
|
-
await fetchPresetList();
|
|
1762
1784
|
} else {
|
|
1785
|
+
// 移除未保存的预设
|
|
1763
1786
|
setPresetList(prev => prev.filter(item => !!item.id));
|
|
1764
1787
|
}
|
|
1765
1788
|
|
|
1766
|
-
//
|
|
1789
|
+
// 获取删除后的列表
|
|
1790
|
+
const updatedList = isUnsavedPreset ? presetList.filter(item => !!item.id) : await getPresetList().then(data => (data === null || data === void 0 ? void 0 : data.preset_list) || data || []);
|
|
1791
|
+
|
|
1792
|
+
// 更新列表
|
|
1793
|
+
setPresetList(updatedList);
|
|
1794
|
+
if (updatedList.length > 0) {
|
|
1795
|
+
// 计算下一个索引
|
|
1796
|
+
let nextIndex = 0;
|
|
1797
|
+
if (currentIndex > 0) {
|
|
1798
|
+
// 如果删除的不是最后一项
|
|
1799
|
+
if (currentIndex < updatedList.length) {
|
|
1800
|
+
nextIndex = currentIndex; // 保持相同位置
|
|
1801
|
+
} else {
|
|
1802
|
+
nextIndex = updatedList.length - 1; // 选最后一个
|
|
1803
|
+
}
|
|
1804
|
+
}
|
|
1805
|
+
const nextPreset = updatedList[nextIndex];
|
|
1806
|
+
if (nextPreset) {
|
|
1807
|
+
setSelectedPreset(nextPreset);
|
|
1808
|
+
form.setFieldsValue(nextPreset);
|
|
1809
|
+
setPresetChanged(prev => prev + 1);
|
|
1810
|
+
return;
|
|
1811
|
+
}
|
|
1812
|
+
}
|
|
1813
|
+
|
|
1814
|
+
// 列表为空
|
|
1767
1815
|
setSelectedPreset(null);
|
|
1768
1816
|
form.resetFields();
|
|
1769
1817
|
}
|
|
@@ -1771,7 +1819,7 @@ const Preset = _ref => {
|
|
|
1771
1819
|
} catch (error) {
|
|
1772
1820
|
console.error('Failed to delete preset:', error);
|
|
1773
1821
|
}
|
|
1774
|
-
}, [selectedPreset, form, AntdModal, AntdMessage,
|
|
1822
|
+
}, [selectedPreset, form, AntdModal, AntdMessage, texts, removePreset, getPresetList]);
|
|
1775
1823
|
const handleLoadPreset = useCallback(async loadData => {
|
|
1776
1824
|
if (!loadData) return;
|
|
1777
1825
|
|
|
@@ -1827,27 +1875,53 @@ const Preset = _ref => {
|
|
|
1827
1875
|
const handleSave = useCallback(async () => {
|
|
1828
1876
|
setLoading(true);
|
|
1829
1877
|
try {
|
|
1830
|
-
|
|
1831
|
-
|
|
1878
|
+
var _fields$name, _fields$category_list2;
|
|
1879
|
+
const values = await form.getFieldsValue();
|
|
1880
|
+
|
|
1881
|
+
// 验证预设名称
|
|
1882
|
+
if ((_fields$name = fields.name) !== null && _fields$name !== void 0 && _fields$name.required) {
|
|
1883
|
+
if (!values.name || values.name.trim() === '') {
|
|
1884
|
+
AntdMessage.error('Name is required.');
|
|
1885
|
+
return; // 直接返回 不执行
|
|
1886
|
+
}
|
|
1887
|
+
}
|
|
1888
|
+
|
|
1889
|
+
// 验证分类列表
|
|
1890
|
+
if ((_fields$category_list2 = fields.category_list) !== null && _fields$category_list2 !== void 0 && _fields$category_list2.required) {
|
|
1891
|
+
if (!values.category_list || values.category_list.length === 0) {
|
|
1892
|
+
AntdMessage.error('No category selected.');
|
|
1893
|
+
return;
|
|
1894
|
+
}
|
|
1895
|
+
}
|
|
1832
1896
|
await savePreset(values);
|
|
1833
1897
|
AntdMessage.success(texts.successText);
|
|
1898
|
+
const savedPresetName = values.name;
|
|
1899
|
+
|
|
1834
1900
|
// 刷新列表
|
|
1835
|
-
await
|
|
1901
|
+
const data = await getPresetList();
|
|
1902
|
+
const presets = (data === null || data === void 0 ? void 0 : data.preset_list) || data || [];
|
|
1903
|
+
setPresetList(presets);
|
|
1836
1904
|
|
|
1837
|
-
//
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
console.error('Form validation failed:', error.errorFields);
|
|
1905
|
+
// 在刷新后的列表中查找同名的预设
|
|
1906
|
+
const newlySavedPreset = presets.find(item => item.name === savedPresetName);
|
|
1907
|
+
if (newlySavedPreset) {
|
|
1908
|
+
setSelectedPreset(newlySavedPreset);
|
|
1909
|
+
form.setFieldsValue(newlySavedPreset);
|
|
1910
|
+
setPresetChanged(prev => prev + 1);
|
|
1844
1911
|
} else {
|
|
1845
|
-
|
|
1912
|
+
setSelectedPreset(values);
|
|
1846
1913
|
}
|
|
1914
|
+
} catch (error) {
|
|
1915
|
+
console.error('Failed to save preset:', error);
|
|
1847
1916
|
} finally {
|
|
1848
1917
|
setLoading(false);
|
|
1849
1918
|
}
|
|
1850
|
-
}, [form, AntdMessage,
|
|
1919
|
+
}, [form, AntdMessage, texts, savePreset, getPresetList]);
|
|
1920
|
+
|
|
1921
|
+
// 初始化数据
|
|
1922
|
+
useEffect(() => {
|
|
1923
|
+
fetchPresetList();
|
|
1924
|
+
}, [fetchPresetList]);
|
|
1851
1925
|
return /*#__PURE__*/jsx(Modal, {
|
|
1852
1926
|
title: texts.title,
|
|
1853
1927
|
width: width,
|
|
@@ -1913,7 +1987,7 @@ const Preset = _ref => {
|
|
|
1913
1987
|
};
|
|
1914
1988
|
var PresetModal = /*#__PURE__*/memo(Preset);
|
|
1915
1989
|
|
|
1916
|
-
const _excluded = ["menuItems", "onMenuClick", "downloadFiles", "upgradeExecute", "upgradeStatus", "acceptFileTypes", "uploadCompleteDelay", "statusPollingInterval", "children"];
|
|
1990
|
+
const _excluded$1 = ["menuItems", "onMenuClick", "downloadFiles", "upgradeExecute", "upgradeStatus", "acceptFileTypes", "uploadCompleteDelay", "statusPollingInterval", "children"];
|
|
1917
1991
|
const UpgradeManager = _ref => {
|
|
1918
1992
|
let {
|
|
1919
1993
|
menuItems = [],
|
|
@@ -1926,7 +2000,7 @@ const UpgradeManager = _ref => {
|
|
|
1926
2000
|
statusPollingInterval = 1000,
|
|
1927
2001
|
children
|
|
1928
2002
|
} = _ref,
|
|
1929
|
-
dropdownProps = _objectWithoutProperties(_ref, _excluded);
|
|
2003
|
+
dropdownProps = _objectWithoutProperties(_ref, _excluded$1);
|
|
1930
2004
|
const [upgradeElement] = useUpgrade$1({
|
|
1931
2005
|
menuItems,
|
|
1932
2006
|
onMenuClick,
|
|
@@ -3321,7 +3395,9 @@ const CommonHeader = _ref => {
|
|
|
3321
3395
|
getSocketUrl = defaultGetSocketUrl,
|
|
3322
3396
|
logoProps = {},
|
|
3323
3397
|
className = '',
|
|
3324
|
-
style = {}
|
|
3398
|
+
style = {},
|
|
3399
|
+
// 新增插槽
|
|
3400
|
+
leftContent // 左侧额外内容
|
|
3325
3401
|
} = _ref;
|
|
3326
3402
|
const [logo] = useSpaLogo$1(logoProps);
|
|
3327
3403
|
|
|
@@ -3351,7 +3427,7 @@ const CommonHeader = _ref => {
|
|
|
3351
3427
|
},
|
|
3352
3428
|
children: productInfo.version
|
|
3353
3429
|
})]
|
|
3354
|
-
})]
|
|
3430
|
+
}), leftContent]
|
|
3355
3431
|
}), /*#__PURE__*/jsxs(Flex, {
|
|
3356
3432
|
align: "center",
|
|
3357
3433
|
gap: 10,
|
|
@@ -3395,5 +3471,320 @@ CommonHeader.propTypes = {
|
|
|
3395
3471
|
};
|
|
3396
3472
|
var CommonHeader$1 = CommonHeader;
|
|
3397
3473
|
|
|
3398
|
-
|
|
3474
|
+
const _excluded = ["value", "min", "max", "className", "disablePointerLock", "modifierKeys", "decimalPlaces", "onChange", "onDragStart", "onDragEnd", "style"];
|
|
3475
|
+
|
|
3476
|
+
// 默认配置
|
|
3477
|
+
const DEFAULT_DECIMAL_PLACES = 2;
|
|
3478
|
+
|
|
3479
|
+
// src/react/defaults-and-utils.ts
|
|
3480
|
+
// eslint-disable-next-line no-var
|
|
3481
|
+
var defaultModifiers = {
|
|
3482
|
+
default: {
|
|
3483
|
+
multiplier: 1,
|
|
3484
|
+
sensitivity: 1
|
|
3485
|
+
}
|
|
3486
|
+
// ctrlKey: { multiplier: 1, sensitivity: 1 },
|
|
3487
|
+
// shiftKey: { multiplier: 10, sensitivity: 0.5 },
|
|
3488
|
+
// metaKey: { multiplier: 1, sensitivity: 1 },
|
|
3489
|
+
// altKey: { multiplier: 1, sensitivity: 1 }
|
|
3490
|
+
};
|
|
3491
|
+
|
|
3492
|
+
// multiplier: 控制每次鼠标移动时数值变化的基本单位 multiplier: 1- 鼠标移动1像素,值变化1 multiplier: 10- 鼠标移动1像素,值变化10
|
|
3493
|
+
// sensitivity: 控制数值变化的灵敏度 sensitivity: 1- 正常灵敏度 sensitivity: 0.5- 减半灵敏度,需要移动2像素才能产生正常1像素的效果
|
|
3494
|
+
|
|
3495
|
+
// 修改 formatNumber 函数,强制显示1位小数
|
|
3496
|
+
function formatNumber(value) {
|
|
3497
|
+
let decimalPlaces = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_DECIMAL_PLACES;
|
|
3498
|
+
return new Intl.NumberFormat("en-US", {
|
|
3499
|
+
minimumFractionDigits: decimalPlaces,
|
|
3500
|
+
maximumFractionDigits: decimalPlaces,
|
|
3501
|
+
useGrouping: false
|
|
3502
|
+
}).format(value);
|
|
3503
|
+
}
|
|
3504
|
+
function handleArrow(e, multiplier, value) {
|
|
3505
|
+
if (e.key === "ArrowUp") {
|
|
3506
|
+
return value + multiplier;
|
|
3507
|
+
}
|
|
3508
|
+
if (e.key === "ArrowDown") {
|
|
3509
|
+
return value - multiplier;
|
|
3510
|
+
}
|
|
3511
|
+
return value;
|
|
3512
|
+
}
|
|
3513
|
+
|
|
3514
|
+
// eslint-disable-next-line no-var
|
|
3515
|
+
var DragCursor = _ref => {
|
|
3516
|
+
let {
|
|
3517
|
+
cursorPosition
|
|
3518
|
+
} = _ref;
|
|
3519
|
+
return /* @__PURE__ */React.createElement("div", {
|
|
3520
|
+
style: {
|
|
3521
|
+
position: "fixed",
|
|
3522
|
+
left: 0,
|
|
3523
|
+
top: 0,
|
|
3524
|
+
width: "100vw",
|
|
3525
|
+
height: "100vh",
|
|
3526
|
+
pointerEvents: "none"
|
|
3527
|
+
}
|
|
3528
|
+
}, /* @__PURE__ */React.createElement("svg", {
|
|
3529
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
3530
|
+
width: "24",
|
|
3531
|
+
height: "24",
|
|
3532
|
+
viewBox: "0 0 24 24",
|
|
3533
|
+
style: {
|
|
3534
|
+
position: "absolute",
|
|
3535
|
+
left: cursorPosition.x,
|
|
3536
|
+
top: cursorPosition.y,
|
|
3537
|
+
transform: "translate(-50%, -50%)",
|
|
3538
|
+
pointerEvents: "none"
|
|
3539
|
+
}
|
|
3540
|
+
}, /* @__PURE__ */React.createElement("path", {
|
|
3541
|
+
fill: "#000",
|
|
3542
|
+
stroke: "#fff",
|
|
3543
|
+
strokeLinejoin: "round",
|
|
3544
|
+
d: "M6.5 9a.5.5 0 0 0-.8-.4l-4 3a.5.5 0 0 0 0 .8l4 3a.5.5 0 0 0 .8-.4v-1.5h11V15a.5.5 0 0 0 .8.4l4-3a.5.5 0 0 0 0-.8l-4-3a.5.5 0 0 0-.8.4v1.5h-11V9Z",
|
|
3545
|
+
style: {
|
|
3546
|
+
filter: "drop-shadow( 0px 2px 1px rgba(0, 0, 0, .35))"
|
|
3547
|
+
}
|
|
3548
|
+
})));
|
|
3549
|
+
};
|
|
3550
|
+
|
|
3551
|
+
// eslint-disable-next-line no-var
|
|
3552
|
+
var noop = () => {};
|
|
3553
|
+
function DraggableNumberInput(_ref2) {
|
|
3554
|
+
let {
|
|
3555
|
+
value,
|
|
3556
|
+
min,
|
|
3557
|
+
max,
|
|
3558
|
+
className = "",
|
|
3559
|
+
disablePointerLock = false,
|
|
3560
|
+
modifierKeys,
|
|
3561
|
+
decimalPlaces = DEFAULT_DECIMAL_PLACES,
|
|
3562
|
+
onChange = noop,
|
|
3563
|
+
onDragStart = noop,
|
|
3564
|
+
onDragEnd = noop,
|
|
3565
|
+
style
|
|
3566
|
+
} = _ref2,
|
|
3567
|
+
restProps = _objectWithoutProperties(_ref2, _excluded);
|
|
3568
|
+
const inputRef = useRef(null);
|
|
3569
|
+
const [isMouseDown, setIsMouseDown] = useState(false);
|
|
3570
|
+
const [isDragging, setIsDragging] = useState(false);
|
|
3571
|
+
const [localValue, setLocalValue] = useState(() => formatNumber(value, decimalPlaces));
|
|
3572
|
+
const [cursorPosition, setCursorPosition] = useState({
|
|
3573
|
+
x: 0,
|
|
3574
|
+
y: 0
|
|
3575
|
+
});
|
|
3576
|
+
const totalMovement = useRef(0);
|
|
3577
|
+
const startValue = useRef(0);
|
|
3578
|
+
const startX = useRef(0);
|
|
3579
|
+
const currentMultiplier = useRef(1);
|
|
3580
|
+
|
|
3581
|
+
// === 新增:编辑状态跟踪 ===
|
|
3582
|
+
const [isEditing, setIsEditing] = useState(false);
|
|
3583
|
+
const lastExternalValueRef = useRef(value);
|
|
3584
|
+
|
|
3585
|
+
// 修改 formatNumber 调用,传入 decimalPlaces
|
|
3586
|
+
const formatValue = useCallback(val => {
|
|
3587
|
+
return formatNumber(val, decimalPlaces);
|
|
3588
|
+
}, [decimalPlaces]);
|
|
3589
|
+
const constrainedOnChange = useCallback(newValue => {
|
|
3590
|
+
let constrainedValue = newValue;
|
|
3591
|
+
if (typeof min === "number") {
|
|
3592
|
+
constrainedValue = Math.max(min, constrainedValue);
|
|
3593
|
+
}
|
|
3594
|
+
if (typeof max === "number") {
|
|
3595
|
+
constrainedValue = Math.min(max, constrainedValue);
|
|
3596
|
+
}
|
|
3597
|
+
onChange(constrainedValue);
|
|
3598
|
+
}, [onChange, min, max]);
|
|
3599
|
+
useEffect(() => {
|
|
3600
|
+
// 只有当用户不在编辑状态,且外部值真正变化时才更新
|
|
3601
|
+
if (!isEditing && lastExternalValueRef.current !== value) {
|
|
3602
|
+
const formattedValue = formatValue(value);
|
|
3603
|
+
setLocalValue(formattedValue);
|
|
3604
|
+
lastExternalValueRef.current = value;
|
|
3605
|
+
}
|
|
3606
|
+
}, [value, formatValue, isEditing]);
|
|
3607
|
+
const handleInputChange = e => {
|
|
3608
|
+
const val = e.target.value;
|
|
3609
|
+
|
|
3610
|
+
// 标记为编辑状态
|
|
3611
|
+
setIsEditing(true);
|
|
3612
|
+
setLocalValue(val);
|
|
3613
|
+
|
|
3614
|
+
// 允许输入中间状态,不立即触发onChange
|
|
3615
|
+
if (val === '' || val === '-' || val === '.' || val.endsWith('.')) {
|
|
3616
|
+
return; // 输入中,不触发onChange
|
|
3617
|
+
}
|
|
3618
|
+
const num = parseFloat(val);
|
|
3619
|
+
if (!isNaN(num)) {
|
|
3620
|
+
constrainedOnChange(num);
|
|
3621
|
+
}
|
|
3622
|
+
};
|
|
3623
|
+
const handleBlur = () => {
|
|
3624
|
+
// 退出编辑状态
|
|
3625
|
+
setIsEditing(false);
|
|
3626
|
+
const num = parseFloat(localValue);
|
|
3627
|
+
if (!isNaN(num)) {
|
|
3628
|
+
// 根据 decimalPlaces 进行四舍五入
|
|
3629
|
+
const precision = Math.pow(10, decimalPlaces);
|
|
3630
|
+
const processedValue = Math.round(num * precision) / precision;
|
|
3631
|
+
const formattedValue = formatValue(processedValue);
|
|
3632
|
+
|
|
3633
|
+
// 更新显示值
|
|
3634
|
+
setLocalValue(formattedValue);
|
|
3635
|
+
lastExternalValueRef.current = processedValue;
|
|
3636
|
+
// 触发外部变化
|
|
3637
|
+
constrainedOnChange(processedValue);
|
|
3638
|
+
} else {
|
|
3639
|
+
// 如果输入无效,重置为当前外部值
|
|
3640
|
+
const formattedValue = formatValue(value);
|
|
3641
|
+
setLocalValue(formattedValue);
|
|
3642
|
+
}
|
|
3643
|
+
};
|
|
3644
|
+
const handleMouseDown = useCallback(e => {
|
|
3645
|
+
if (!inputRef.current) return;
|
|
3646
|
+
let x = 0,
|
|
3647
|
+
y = 0;
|
|
3648
|
+
if ("clientX" in e && "clientY" in e) {
|
|
3649
|
+
[x, y] = [e.clientX, e.clientY];
|
|
3650
|
+
}
|
|
3651
|
+
if ("touches" in e) {
|
|
3652
|
+
[x, y] = [e.touches[0].clientX, e.touches[0].clientY];
|
|
3653
|
+
}
|
|
3654
|
+
setIsMouseDown(true);
|
|
3655
|
+
startX.current = x;
|
|
3656
|
+
startValue.current = value;
|
|
3657
|
+
totalMovement.current = 0;
|
|
3658
|
+
setCursorPosition({
|
|
3659
|
+
x,
|
|
3660
|
+
y
|
|
3661
|
+
});
|
|
3662
|
+
}, [value, disablePointerLock]);
|
|
3663
|
+
const updateDelta = useCallback(e => {
|
|
3664
|
+
if (!isMouseDown) return;
|
|
3665
|
+
applyMovement(totalMovement.current, e);
|
|
3666
|
+
}, [isMouseDown]);
|
|
3667
|
+
const getModifiers = useCallback(e => {
|
|
3668
|
+
const mods = _objectSpread2(_objectSpread2({}, defaultModifiers), modifierKeys);
|
|
3669
|
+
for (const key in mods) {
|
|
3670
|
+
if (key !== "default" && e[key]) {
|
|
3671
|
+
currentMultiplier.current = mods[key].multiplier;
|
|
3672
|
+
return mods[key];
|
|
3673
|
+
}
|
|
3674
|
+
}
|
|
3675
|
+
currentMultiplier.current = mods.default.multiplier;
|
|
3676
|
+
return mods.default;
|
|
3677
|
+
}, [modifierKeys]);
|
|
3678
|
+
const applyMovement = useCallback((newMovement, e) => {
|
|
3679
|
+
const {
|
|
3680
|
+
sensitivity,
|
|
3681
|
+
multiplier
|
|
3682
|
+
} = getModifiers(e);
|
|
3683
|
+
const delta = newMovement * sensitivity * multiplier;
|
|
3684
|
+
let newValue = startValue.current + delta;
|
|
3685
|
+
// 根据 decimalPlaces 进行精度控制
|
|
3686
|
+
const precision = Math.pow(10, decimalPlaces);
|
|
3687
|
+
newValue = Math.round(newValue * precision) / precision;
|
|
3688
|
+
newValue = Object.is(newValue, -0) ? 0 : newValue;
|
|
3689
|
+
constrainedOnChange(newValue);
|
|
3690
|
+
}, [constrainedOnChange, getModifiers, decimalPlaces]);
|
|
3691
|
+
const handleArrowKeyDown = e => {
|
|
3692
|
+
if (e.key === "ArrowUp" || e.key === "ArrowDown") {
|
|
3693
|
+
e.preventDefault();
|
|
3694
|
+
const {
|
|
3695
|
+
multiplier
|
|
3696
|
+
} = getModifiers(e);
|
|
3697
|
+
const newValue = handleArrow(e, multiplier, value);
|
|
3698
|
+
constrainedOnChange(newValue);
|
|
3699
|
+
}
|
|
3700
|
+
};
|
|
3701
|
+
const handleModifierKeyDuringDrag = useCallback(e => {
|
|
3702
|
+
if (e.key === "Shift" || e.key === "Control" || e.key === "Meta" || e.key === "Alt") {
|
|
3703
|
+
updateDelta(e);
|
|
3704
|
+
}
|
|
3705
|
+
}, [updateDelta]);
|
|
3706
|
+
const handleMouseMove = useCallback(e => {
|
|
3707
|
+
if (!isMouseDown) return;
|
|
3708
|
+
if ("touches" in e) {
|
|
3709
|
+
e.preventDefault();
|
|
3710
|
+
}
|
|
3711
|
+
if (!disablePointerLock && document.pointerLockElement && !("touches" in e)) {
|
|
3712
|
+
setCursorPosition(prev => {
|
|
3713
|
+
const width = window.innerWidth;
|
|
3714
|
+
const height = window.innerHeight;
|
|
3715
|
+
const x2 = (prev.x + e.movementX + width) % width;
|
|
3716
|
+
const y = (prev.y + e.movementY + height) % height;
|
|
3717
|
+
return {
|
|
3718
|
+
x: x2,
|
|
3719
|
+
y
|
|
3720
|
+
};
|
|
3721
|
+
});
|
|
3722
|
+
}
|
|
3723
|
+
const x = "touches" in e ? e.touches[0].clientX : e.clientX;
|
|
3724
|
+
const newMovement = disablePointerLock || "touches" in e ? x - startX.current : totalMovement.current + e.movementX;
|
|
3725
|
+
if (!isDragging && newMovement !== 0) {
|
|
3726
|
+
if (!disablePointerLock && !("touches" in e)) {
|
|
3727
|
+
var _inputRef$current, _inputRef$current$req;
|
|
3728
|
+
(_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 || (_inputRef$current$req = _inputRef$current.requestPointerLock) === null || _inputRef$current$req === void 0 || _inputRef$current$req.call(_inputRef$current);
|
|
3729
|
+
}
|
|
3730
|
+
setIsDragging(true);
|
|
3731
|
+
document.addEventListener("keydown", handleModifierKeyDuringDrag);
|
|
3732
|
+
document.addEventListener("keyup", handleModifierKeyDuringDrag);
|
|
3733
|
+
onDragStart();
|
|
3734
|
+
}
|
|
3735
|
+
totalMovement.current = newMovement;
|
|
3736
|
+
applyMovement(newMovement, e);
|
|
3737
|
+
}, [isMouseDown, disablePointerLock, startX, isDragging, onDragStart, applyMovement]);
|
|
3738
|
+
const handleMouseUp = useCallback(() => {
|
|
3739
|
+
setIsMouseDown(false);
|
|
3740
|
+
totalMovement.current = 0;
|
|
3741
|
+
if (isDragging) {
|
|
3742
|
+
setIsDragging(false);
|
|
3743
|
+
document.removeEventListener("keydown", handleModifierKeyDuringDrag);
|
|
3744
|
+
document.removeEventListener("keyup", handleModifierKeyDuringDrag);
|
|
3745
|
+
onDragEnd();
|
|
3746
|
+
}
|
|
3747
|
+
if (document.pointerLockElement) {
|
|
3748
|
+
document.exitPointerLock();
|
|
3749
|
+
}
|
|
3750
|
+
}, [isDragging, onDragEnd, disablePointerLock]);
|
|
3751
|
+
useEffect(() => {
|
|
3752
|
+
if (isMouseDown) {
|
|
3753
|
+
document.addEventListener("mousemove", handleMouseMove);
|
|
3754
|
+
document.addEventListener("touchmove", handleMouseMove, {
|
|
3755
|
+
passive: false
|
|
3756
|
+
});
|
|
3757
|
+
document.addEventListener("mouseup", handleMouseUp);
|
|
3758
|
+
document.addEventListener("touchend", handleMouseUp);
|
|
3759
|
+
return () => {
|
|
3760
|
+
document.removeEventListener("mousemove", handleMouseMove);
|
|
3761
|
+
document.removeEventListener("mouseup", handleMouseUp);
|
|
3762
|
+
document.removeEventListener("touchmove", handleMouseMove);
|
|
3763
|
+
document.removeEventListener("touchend", handleMouseUp);
|
|
3764
|
+
};
|
|
3765
|
+
}
|
|
3766
|
+
}, [isMouseDown, handleMouseMove, handleMouseUp]);
|
|
3767
|
+
return /* @__PURE__ */React.createElement(React.Fragment, null, /* @__PURE__ */React.createElement("input", _objectSpread2({
|
|
3768
|
+
ref: inputRef,
|
|
3769
|
+
type: "text",
|
|
3770
|
+
inputMode: "numeric",
|
|
3771
|
+
pattern: "-?[0-9]*\\.?[0-9]*",
|
|
3772
|
+
value: localValue,
|
|
3773
|
+
onChange: handleInputChange,
|
|
3774
|
+
onBlur: handleBlur,
|
|
3775
|
+
onMouseDown: handleMouseDown,
|
|
3776
|
+
onTouchStart: handleMouseDown,
|
|
3777
|
+
onKeyDown: handleArrowKeyDown,
|
|
3778
|
+
className: "draggable-number-input ".concat(className, " ").concat(isDragging ? "dragging" : ""),
|
|
3779
|
+
style: _objectSpread2(_objectSpread2({}, {
|
|
3780
|
+
cursor: "ew-resize",
|
|
3781
|
+
userSelect: "none",
|
|
3782
|
+
caretColor: isDragging ? "transparent" : "initial"
|
|
3783
|
+
}), style)
|
|
3784
|
+
}, restProps)), isDragging && !disablePointerLock && /* @__PURE__ */React.createElement(DragCursor, {
|
|
3785
|
+
cursorPosition
|
|
3786
|
+
}));
|
|
3787
|
+
}
|
|
3788
|
+
|
|
3789
|
+
export { AuthorizationModal$1 as AuthorizationModal, CommonHeader$1 as CommonHeader, DraggableNumberInput, NetworkSettingsModal$1 as NetworkSettingsModal, PresetModal, PtpModal$1 as PtpModal, SystemOperations$1 as SystemOperations, UpgradeManager$1 as UpgradeManager, useAuth, useHardwareUsage$1 as useHardwareUsage, useSystemOperations$1 as useSystemOperations, useUpgrade$1 as useUpgrade };
|
|
3399
3790
|
//# sourceMappingURL=index.esm.js.map
|