@canvas-components/react-components 0.3.18 → 0.3.19
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.cjs +271 -168
- package/dist/index.d.cts +76 -57
- package/dist/index.d.ts +76 -57
- package/dist/index.js +272 -170
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1518,6 +1518,275 @@ function actionStyle(primary) {
|
|
|
1518
1518
|
return { minWidth: 72, height: 32, padding: "0 12px", borderRadius: 6, border: primary ? "1px solid #1677ff" : "1px solid #d9d9d9", background: primary ? "#1677ff" : "#fff", color: primary ? "#fff" : "#374151", cursor: "pointer" };
|
|
1519
1519
|
}
|
|
1520
1520
|
|
|
1521
|
+
// src/components/form/style.css
|
|
1522
|
+
styleInject(".canvas-react-form {\n min-width: 0;\n}\n.canvas-react-form-vertical {\n display: grid;\n gap: 16px;\n}\n.canvas-react-form-horizontal {\n display: grid;\n gap: 12px;\n}\n.canvas-react-form-inline {\n display: flex;\n flex-wrap: wrap;\n align-items: flex-start;\n gap: 12px 16px;\n}\n.canvas-react-form-item {\n box-sizing: border-box;\n min-width: 0;\n}\n.canvas-react-form-item-vertical {\n display: grid;\n gap: 6px;\n}\n.canvas-react-form-item-horizontal {\n display: grid;\n grid-template-columns: auto minmax(0, 1fr);\n align-items: center;\n column-gap: 10px;\n row-gap: 4px;\n}\n.canvas-react-form-item-inline {\n display: inline-grid;\n grid-template-columns: auto minmax(0, 1fr);\n align-items: center;\n column-gap: 8px;\n}\n.canvas-react-form-item-no-wrap {\n flex-wrap: nowrap;\n}\n.canvas-react-form-item-horizontal.canvas-react-form-item-no-wrap {\n display: grid;\n grid-template-columns: max-content minmax(0, 1fr);\n}\n.canvas-react-form-horizontal > .canvas-react-form-item {\n margin-bottom: var(--canvas-react-form-item-spacing, 16px);\n}\n.canvas-react-form-item-inline.canvas-react-form-item-no-wrap {\n display: inline-grid;\n grid-template-columns: max-content minmax(0, 1fr);\n}\n.canvas-react-form-item-no-wrap > .canvas-react-form-label {\n white-space: nowrap;\n}\n.canvas-react-form-label {\n display: inline-flex;\n align-items: center;\n gap: 3px;\n min-width: 0;\n color: #475569;\n font-size: 13px;\n line-height: 1.4;\n}\n.canvas-react-form-horizontal > .canvas-react-form-item > .canvas-react-form-label {\n min-height: 32px;\n}\n.canvas-react-form-required {\n color: #dc2626;\n}\n.canvas-react-form-control {\n display: flex;\n flex-direction: column;\n min-width: 0;\n}\n.canvas-react-form-error {\n color: #dc2626;\n font-size: 12px;\n}\n.canvas-react-form-help,\n.canvas-react-form-extra {\n color: #64748b;\n font-size: 12px;\n}\n.canvas-react-form-item-error .canvas-react-form-control > input,\n.canvas-react-form-item-error .canvas-react-form-control > textarea {\n border-color: #dc2626;\n}\n");
|
|
1523
|
+
function createFormInstance() {
|
|
1524
|
+
const store = {
|
|
1525
|
+
values: {},
|
|
1526
|
+
initialValues: {},
|
|
1527
|
+
errors: {},
|
|
1528
|
+
rules: /* @__PURE__ */ new Map(),
|
|
1529
|
+
listeners: /* @__PURE__ */ new Set(),
|
|
1530
|
+
revision: 0,
|
|
1531
|
+
notify() {
|
|
1532
|
+
store.revision += 1;
|
|
1533
|
+
store.listeners.forEach((listener) => listener());
|
|
1534
|
+
}
|
|
1535
|
+
};
|
|
1536
|
+
return {
|
|
1537
|
+
__store: store,
|
|
1538
|
+
getFieldValue: (name) => store.values[name],
|
|
1539
|
+
setFieldsValue(values) {
|
|
1540
|
+
store.values = { ...store.values, ...values };
|
|
1541
|
+
Object.keys(values).forEach((name) => {
|
|
1542
|
+
delete store.errors[name];
|
|
1543
|
+
});
|
|
1544
|
+
store.notify();
|
|
1545
|
+
},
|
|
1546
|
+
resetFields() {
|
|
1547
|
+
store.values = { ...store.initialValues };
|
|
1548
|
+
store.errors = {};
|
|
1549
|
+
store.notify();
|
|
1550
|
+
},
|
|
1551
|
+
async validateFields() {
|
|
1552
|
+
const errors = {};
|
|
1553
|
+
for (const [name, rules] of store.rules) {
|
|
1554
|
+
const value = store.values[name];
|
|
1555
|
+
for (const rawRule of rules) {
|
|
1556
|
+
const rule = typeof rawRule === "function" ? rawRule({ getFieldValue: (field) => store.values[field] }) : rawRule;
|
|
1557
|
+
if (rule.required && (value === void 0 || value === null || value === "")) {
|
|
1558
|
+
errors[name] = rule.message ?? "\u6B64\u9879\u4E3A\u5FC5\u586B\u9879";
|
|
1559
|
+
break;
|
|
1560
|
+
}
|
|
1561
|
+
if ((rule.type === "number" || rule.type === "integer") && typeof value === "number" && rule.min !== void 0 && value < rule.min) {
|
|
1562
|
+
errors[name] = rule.message ?? `\u4E0D\u80FD\u5C0F\u4E8E ${rule.min}`;
|
|
1563
|
+
break;
|
|
1564
|
+
}
|
|
1565
|
+
if ((rule.type === "number" || rule.type === "integer") && typeof value === "number" && rule.max !== void 0 && value > rule.max) {
|
|
1566
|
+
errors[name] = rule.message ?? `\u4E0D\u80FD\u5927\u4E8E ${rule.max}`;
|
|
1567
|
+
break;
|
|
1568
|
+
}
|
|
1569
|
+
if (rule.type === "integer" && typeof value === "number" && !Number.isInteger(value)) {
|
|
1570
|
+
errors[name] = rule.message ?? "\u8BF7\u8F93\u5165\u6574\u6570";
|
|
1571
|
+
break;
|
|
1572
|
+
}
|
|
1573
|
+
if (rule.validator) {
|
|
1574
|
+
try {
|
|
1575
|
+
await rule.validator(rule, value);
|
|
1576
|
+
} catch (error) {
|
|
1577
|
+
errors[name] = error instanceof Error ? error.message : "\u6821\u9A8C\u5931\u8D25";
|
|
1578
|
+
break;
|
|
1579
|
+
}
|
|
1580
|
+
}
|
|
1581
|
+
}
|
|
1582
|
+
}
|
|
1583
|
+
store.errors = errors;
|
|
1584
|
+
store.notify();
|
|
1585
|
+
if (Object.keys(errors).length > 0) {
|
|
1586
|
+
return Promise.reject({
|
|
1587
|
+
errorFields: errors,
|
|
1588
|
+
values: { ...store.values }
|
|
1589
|
+
});
|
|
1590
|
+
}
|
|
1591
|
+
return { ...store.values };
|
|
1592
|
+
}
|
|
1593
|
+
};
|
|
1594
|
+
}
|
|
1595
|
+
function useReactForm() {
|
|
1596
|
+
const formRef = React.useRef(null);
|
|
1597
|
+
if (!formRef.current) formRef.current = createFormInstance();
|
|
1598
|
+
return [formRef.current];
|
|
1599
|
+
}
|
|
1600
|
+
function useReactFormWatch(name, form) {
|
|
1601
|
+
React.useSyncExternalStore(
|
|
1602
|
+
(listener) => {
|
|
1603
|
+
form.__store.listeners.add(listener);
|
|
1604
|
+
return () => form.__store.listeners.delete(listener);
|
|
1605
|
+
},
|
|
1606
|
+
() => form.__store.revision,
|
|
1607
|
+
() => 0
|
|
1608
|
+
);
|
|
1609
|
+
return form.getFieldValue(name);
|
|
1610
|
+
}
|
|
1611
|
+
var FormContext = React.createContext(null);
|
|
1612
|
+
var emptySubscribe = () => () => {
|
|
1613
|
+
};
|
|
1614
|
+
var emptySnapshot = () => 0;
|
|
1615
|
+
function ReactFormRoot({
|
|
1616
|
+
form: formProp,
|
|
1617
|
+
initialValues,
|
|
1618
|
+
layout = "vertical",
|
|
1619
|
+
noWrap = false,
|
|
1620
|
+
itemSpacing,
|
|
1621
|
+
labelWidth,
|
|
1622
|
+
labelAlign = "right",
|
|
1623
|
+
colon = false,
|
|
1624
|
+
requiredMark = true,
|
|
1625
|
+
className,
|
|
1626
|
+
children,
|
|
1627
|
+
...props
|
|
1628
|
+
}) {
|
|
1629
|
+
const internalForm = React.useRef(null);
|
|
1630
|
+
if (!internalForm.current) internalForm.current = createFormInstance();
|
|
1631
|
+
const form = formProp ?? internalForm.current;
|
|
1632
|
+
const initialKey = React.useMemo(
|
|
1633
|
+
() => JSON.stringify(initialValues ?? {}),
|
|
1634
|
+
[initialValues]
|
|
1635
|
+
);
|
|
1636
|
+
React.useEffect(() => {
|
|
1637
|
+
form.__store.initialValues = { ...initialValues };
|
|
1638
|
+
form.__store.values = { ...initialValues, ...form.__store.values };
|
|
1639
|
+
form.__store.notify();
|
|
1640
|
+
}, [form, initialKey]);
|
|
1641
|
+
const contextValue = React.useMemo(
|
|
1642
|
+
() => ({
|
|
1643
|
+
form,
|
|
1644
|
+
layout,
|
|
1645
|
+
noWrap,
|
|
1646
|
+
labelWidth,
|
|
1647
|
+
labelAlign,
|
|
1648
|
+
colon,
|
|
1649
|
+
requiredMark
|
|
1650
|
+
}),
|
|
1651
|
+
[colon, form, labelAlign, labelWidth, layout, noWrap, requiredMark]
|
|
1652
|
+
);
|
|
1653
|
+
return /* @__PURE__ */ jsxRuntime.jsx(FormContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1654
|
+
"form",
|
|
1655
|
+
{
|
|
1656
|
+
...props,
|
|
1657
|
+
style: itemSpacing === void 0 ? props.style : {
|
|
1658
|
+
...props.style,
|
|
1659
|
+
"--canvas-react-form-item-spacing": itemSpacing
|
|
1660
|
+
},
|
|
1661
|
+
className: joinClassNames(
|
|
1662
|
+
`${REACT_COMPONENT_PREFIX}-form`,
|
|
1663
|
+
`${REACT_COMPONENT_PREFIX}-form-${layout}`,
|
|
1664
|
+
className
|
|
1665
|
+
),
|
|
1666
|
+
onSubmit: (event) => event.preventDefault(),
|
|
1667
|
+
children
|
|
1668
|
+
}
|
|
1669
|
+
) });
|
|
1670
|
+
}
|
|
1671
|
+
function ReactFormItem({
|
|
1672
|
+
label,
|
|
1673
|
+
name,
|
|
1674
|
+
children,
|
|
1675
|
+
rules = [],
|
|
1676
|
+
initialValue,
|
|
1677
|
+
required,
|
|
1678
|
+
colon,
|
|
1679
|
+
labelWidth,
|
|
1680
|
+
labelAlign,
|
|
1681
|
+
labelStyle,
|
|
1682
|
+
controlStyle,
|
|
1683
|
+
help,
|
|
1684
|
+
extra,
|
|
1685
|
+
className,
|
|
1686
|
+
style,
|
|
1687
|
+
noWrap
|
|
1688
|
+
}) {
|
|
1689
|
+
const context = React.useContext(FormContext);
|
|
1690
|
+
const form = context?.form ?? null;
|
|
1691
|
+
if (name && !form) throw new Error("ReactForm.Item \u5FC5\u987B\u5728 ReactForm \u5185\u4F7F\u7528");
|
|
1692
|
+
React.useSyncExternalStore(
|
|
1693
|
+
form ? (listener) => {
|
|
1694
|
+
form.__store.listeners.add(listener);
|
|
1695
|
+
return () => form.__store.listeners.delete(listener);
|
|
1696
|
+
} : emptySubscribe,
|
|
1697
|
+
form ? () => form.__store.revision : emptySnapshot,
|
|
1698
|
+
emptySnapshot
|
|
1699
|
+
);
|
|
1700
|
+
React.useEffect(() => {
|
|
1701
|
+
if (!form || !name) return;
|
|
1702
|
+
form.__store.rules.set(name, rules);
|
|
1703
|
+
if (form.getFieldValue(name) === void 0 && initialValue !== void 0) {
|
|
1704
|
+
form.setFieldsValue({ [name]: initialValue });
|
|
1705
|
+
}
|
|
1706
|
+
return () => {
|
|
1707
|
+
form.__store.rules.delete(name);
|
|
1708
|
+
};
|
|
1709
|
+
}, [form, initialValue, name, rules]);
|
|
1710
|
+
const childProps = React.isValidElement(children) ? children.props : {};
|
|
1711
|
+
const value = form && name ? form.getFieldValue(name) : void 0;
|
|
1712
|
+
const child = form && name && React.isValidElement(children) ? React.cloneElement(children, {
|
|
1713
|
+
value: value ?? "",
|
|
1714
|
+
onChange: (...args) => {
|
|
1715
|
+
const first = args[0];
|
|
1716
|
+
const nextValue = typeof first === "object" && first !== null && "target" in first ? first.target?.value : first;
|
|
1717
|
+
form.setFieldsValue({ [name]: nextValue });
|
|
1718
|
+
const childOnChange = childProps.onChange;
|
|
1719
|
+
if (typeof childOnChange === "function") childOnChange(...args);
|
|
1720
|
+
}
|
|
1721
|
+
}) : children;
|
|
1722
|
+
const error = form && name ? form.__store.errors[name] : void 0;
|
|
1723
|
+
const isRequired = required ?? rules.some((rule) => typeof rule !== "function" && rule.required === true);
|
|
1724
|
+
const resolvedLabelWidth = labelWidth ?? context?.labelWidth;
|
|
1725
|
+
const resolvedLabelAlign = labelAlign ?? context?.labelAlign ?? "right";
|
|
1726
|
+
const showColon = colon ?? context?.colon ?? false;
|
|
1727
|
+
const shouldMarkRequired = context?.requiredMark ?? true;
|
|
1728
|
+
const resolvedLayout = context?.layout ?? "vertical";
|
|
1729
|
+
const resolvedNoWrap = noWrap ?? context?.noWrap ?? false;
|
|
1730
|
+
const labelElementId = typeof childProps.id === "string" ? childProps.id : void 0;
|
|
1731
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1732
|
+
"div",
|
|
1733
|
+
{
|
|
1734
|
+
className: joinClassNames(
|
|
1735
|
+
`${REACT_COMPONENT_PREFIX}-form-item`,
|
|
1736
|
+
`${REACT_COMPONENT_PREFIX}-form-item-${resolvedLayout}`,
|
|
1737
|
+
resolvedNoWrap && `${REACT_COMPONENT_PREFIX}-form-item-no-wrap`,
|
|
1738
|
+
className,
|
|
1739
|
+
error && `${REACT_COMPONENT_PREFIX}-form-item-error`
|
|
1740
|
+
),
|
|
1741
|
+
style,
|
|
1742
|
+
children: [
|
|
1743
|
+
label ? /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1744
|
+
"label",
|
|
1745
|
+
{
|
|
1746
|
+
className: `${REACT_COMPONENT_PREFIX}-form-label`,
|
|
1747
|
+
htmlFor: labelElementId,
|
|
1748
|
+
style: {
|
|
1749
|
+
width: resolvedLabelWidth,
|
|
1750
|
+
flexBasis: resolvedLabelWidth,
|
|
1751
|
+
textAlign: resolvedLabelAlign,
|
|
1752
|
+
...labelStyle
|
|
1753
|
+
},
|
|
1754
|
+
children: [
|
|
1755
|
+
shouldMarkRequired && isRequired ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
1756
|
+
"span",
|
|
1757
|
+
{
|
|
1758
|
+
"aria-hidden": "true",
|
|
1759
|
+
className: `${REACT_COMPONENT_PREFIX}-form-required`,
|
|
1760
|
+
children: "*"
|
|
1761
|
+
}
|
|
1762
|
+
) : null,
|
|
1763
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { children: label }),
|
|
1764
|
+
showColon ? /* @__PURE__ */ jsxRuntime.jsx("span", { "aria-hidden": "true", children: ":" }) : null
|
|
1765
|
+
]
|
|
1766
|
+
}
|
|
1767
|
+
) : null,
|
|
1768
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
1769
|
+
"div",
|
|
1770
|
+
{
|
|
1771
|
+
className: `${REACT_COMPONENT_PREFIX}-form-control`,
|
|
1772
|
+
style: controlStyle,
|
|
1773
|
+
children: [
|
|
1774
|
+
child,
|
|
1775
|
+
error ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: `${REACT_COMPONENT_PREFIX}-form-error`, children: error }) : help ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: `${REACT_COMPONENT_PREFIX}-form-help`, children: help }) : null,
|
|
1776
|
+
extra ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: `${REACT_COMPONENT_PREFIX}-form-extra`, children: extra }) : null
|
|
1777
|
+
]
|
|
1778
|
+
}
|
|
1779
|
+
)
|
|
1780
|
+
]
|
|
1781
|
+
}
|
|
1782
|
+
);
|
|
1783
|
+
}
|
|
1784
|
+
var ReactForm = Object.assign(ReactFormRoot, {
|
|
1785
|
+
Item: ReactFormItem,
|
|
1786
|
+
useForm: useReactForm,
|
|
1787
|
+
useWatch: useReactFormWatch
|
|
1788
|
+
});
|
|
1789
|
+
|
|
1521
1790
|
// src/components/color/style.css
|
|
1522
1791
|
styleInject(".canvas-react-color-wrap {\n display: inline-flex;\n width: 100%;\n height: 100%;\n min-height: 0;\n box-sizing: border-box;\n}\n.canvas-react-color {\n display: flex;\n align-items: center;\n width: 100%;\n min-width: 0;\n height: var(--canvas-react-control-height);\n min-height: 0;\n box-sizing: border-box;\n border: 1px solid var(--canvas-react-color-border);\n border-radius: var(--canvas-react-radius-sm);\n background: var(--canvas-react-color-bg);\n color: var(--canvas-react-color-text);\n font-size: var(--canvas-react-font-size);\n transition: border-color 0.2s ease, box-shadow 0.2s ease;\n cursor: pointer;\n}\n.canvas-react-color:hover {\n border-color: var(--canvas-react-color-primary-hover);\n}\n.canvas-react-color-open,\n.canvas-react-color:focus-within {\n border-color: var(--canvas-react-color-primary);\n box-shadow: var(--canvas-react-shadow-focus);\n}\n.canvas-react-color-disabled {\n color: #9ca3af;\n background: var(--canvas-react-color-bg-soft);\n cursor: not-allowed;\n}\n.canvas-react-color-preview {\n flex: 0 0 auto;\n width: calc(24px * var(--canvas-react-content-zoom, 1));\n height: calc(24px * var(--canvas-react-content-zoom, 1));\n margin-left: 3px;\n box-sizing: border-box;\n border: 1px solid rgba(0, 0, 0, 0.12);\n border-radius: 4px;\n}\n.canvas-react-color-input-wrap {\n flex: 1;\n min-width: 0;\n height: 100%;\n min-height: 0;\n border: 0;\n box-shadow: none;\n}\n.canvas-react-color .canvas-react-input-affix-wrapper {\n height: 100%;\n min-height: 0;\n}\n.canvas-react-color-input-wrap:hover,\n.canvas-react-color-input-wrap:focus-within {\n border-color: transparent;\n box-shadow: none;\n}\n.canvas-react-color-input {\n cursor: pointer;\n text-transform: uppercase;\n}\n.canvas-react-color-arrow {\n flex: 0 0 auto;\n width: 0.5em;\n height: 0.5em;\n min-width: 6px;\n min-height: 6px;\n margin-right: var(--canvas-react-control-padding-inline, 11px);\n border-right: 1.5px solid var(--canvas-react-color-text-muted);\n border-bottom: 1.5px solid var(--canvas-react-color-text-muted);\n transform: rotate(45deg) translateY(-2px);\n transition: transform 0.18s ease;\n}\n.canvas-react-color-arrow-open {\n transform: rotate(225deg) translate(-1px, -1px);\n}\n.canvas-react-color-dropdown {\n overflow: hidden;\n}\n.canvas-react-color-panel {\n padding: 12px;\n box-sizing: border-box;\n}\n.canvas-react-color-saturation {\n position: relative;\n height: 150px;\n overflow: hidden;\n border-radius: 6px;\n cursor: crosshair;\n background-image:\n linear-gradient(\n to top,\n #000,\n transparent),\n linear-gradient(\n to right,\n #fff,\n transparent);\n touch-action: none;\n}\n.canvas-react-color-saturation-thumb {\n position: absolute;\n width: 12px;\n height: 12px;\n border: 2px solid #fff;\n border-radius: 50%;\n box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.28), 0 1px 3px rgba(0, 0, 0, 0.28);\n transform: translate(-50%, -50%);\n pointer-events: none;\n}\n.canvas-react-color-controls {\n display: flex;\n align-items: center;\n gap: 10px;\n margin-top: 12px;\n}\n.canvas-react-color-current {\n flex: 0 0 28px;\n height: 28px;\n box-sizing: border-box;\n border: 1px solid rgba(0, 0, 0, 0.12);\n border-radius: 50%;\n}\n.canvas-react-color-hue {\n width: 100%;\n height: 12px;\n margin: 0;\n appearance: none;\n border-radius: 999px;\n background:\n linear-gradient(\n to right,\n #f00,\n #ff0,\n #0f0,\n #0ff,\n #00f,\n #f0f,\n #f00);\n cursor: pointer;\n}\n.canvas-react-color-hue::-webkit-slider-thumb {\n width: 14px;\n height: 14px;\n appearance: none;\n border: 2px solid #fff;\n border-radius: 50%;\n background: transparent;\n box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.28);\n}\n.canvas-react-color-value-row {\n display: grid;\n grid-template-columns: 36px 1fr;\n align-items: center;\n gap: 8px;\n margin-top: 12px;\n color: var(--canvas-react-color-text-muted);\n font-size: 12px;\n}\n.canvas-react-color-value-row .canvas-react-input-affix-wrapper {\n height: 28px;\n}\n.canvas-react-color-presets {\n display: grid;\n grid-template-columns: repeat(8, 20px);\n gap: 7px;\n margin-top: 12px;\n}\n.canvas-react-color-preset {\n width: 20px;\n height: 20px;\n padding: 0;\n box-sizing: border-box;\n border: 1px solid rgba(0, 0, 0, 0.12);\n border-radius: 4px;\n cursor: pointer;\n transition: transform 0.16s ease, box-shadow 0.16s ease;\n}\n.canvas-react-color-preset:hover {\n transform: scale(1.12);\n}\n.canvas-react-color-preset-selected {\n box-shadow: 0 0 0 2px #fff, 0 0 0 3px var(--canvas-react-color-primary);\n}\n");
|
|
1523
1792
|
var DEFAULT_COLOR = "#1677ff";
|
|
@@ -5914,7 +6183,7 @@ function isPromiseLike(value) {
|
|
|
5914
6183
|
}
|
|
5915
6184
|
|
|
5916
6185
|
// src/components/compat/style.css
|
|
5917
|
-
styleInject(".canvas-react-button {\n display: inline-flex;\n align-items: center;\n justify-content: center;\n gap: 6px;\n min-height: 32px;\n padding: 4px 14px;\n border: 1px solid var(--cc-border-color, #d9d9d9);\n border-radius: 6px;\n color: var(--cc-text-color, #1f2937);\n background: var(--cc-surface-color, #fff);\n cursor: pointer;\n}\n.canvas-react-button:hover:not(:disabled) {\n color: #1677ff;\n border-color: #1677ff;\n}\n.canvas-react-button:disabled {\n cursor: not-allowed;\n opacity: 0.5;\n}\n.canvas-react-button-primary {\n color: #fff;\n border-color: #1677ff;\n background: #1677ff;\n}\n.canvas-react-button-danger {\n color: #dc2626;\n border-color: #fca5a5;\n}\n.canvas-react-button-small {\n min-height: 24px;\n padding: 2px 8px;\n}\n.canvas-react-button-large {\n min-height: 40px;\n padding: 6px 18px;\n}\n.canvas-react-button-icon {\n display: inline-flex;\n}\n.canvas-react-row {\n display: flex;\n flex-flow: row wrap;\n}\n.canvas-react-col {\n min-width: 0;\n padding-inline: 8px;\n}\n.canvas-react-radio-group {\n display: flex;\n gap: 16px;\n}\n.canvas-react-radio {\n display: inline-flex;\n align-items: center;\n gap: 6px;\n cursor: pointer;\n}\n.canvas-react-radio input {\n position: absolute;\n opacity: 0;\n pointer-events: none;\n}\n.canvas-react-radio-mark {\n width: 14px;\n height: 14px;\n border: 1px solid #94a3b8;\n border-radius: 50%;\n box-sizing: border-box;\n}\n.canvas-react-radio input:checked + .canvas-react-radio-mark {\n border: 4px solid #1677ff;\n}\n.canvas-react-form-item {\n display: flex;\n flex-direction: column;\n gap: 6px;\n margin-bottom: 16px;\n}\n.canvas-react-form-label {\n color: #334155;\n font-size: 14px;\n}\n.canvas-react-form-error {\n color: #dc2626;\n font-size: 12px;\n}\n.canvas-react-textarea {\n width: 100%;\n min-height: 72px;\n padding: 8px 10px;\n border: 1px solid #d9d9d9;\n border-radius: 6px;\n box-sizing: border-box;\n font: inherit;\n resize: vertical;\n}\n.canvas-react-message-host {\n position: fixed;\n z-index: 3000;\n top: 24px;\n left: 50%;\n display: flex;\n flex-direction: column;\n gap: 8px;\n transform: translateX(-50%);\n pointer-events: none;\n}\n.canvas-react-message {\n padding: 9px 14px;\n border: 1px solid #e2e8f0;\n border-radius: 8px;\n color: #334155;\n background: #fff;\n box-shadow: 0 8px 24px rgba(15, 23, 42, 0.14);\n}\n.canvas-react-message-error {\n color: #b91c1c;\n border-color: #fecaca;\n}\n");
|
|
6186
|
+
styleInject(".canvas-react-button {\n display: inline-flex;\n align-items: center;\n justify-content: center;\n gap: 6px;\n min-height: 32px;\n padding: 4px 14px;\n border: 1px solid var(--cc-border-color, #d9d9d9);\n border-radius: 6px;\n color: var(--cc-text-color, #1f2937);\n background: var(--cc-surface-color, #fff);\n cursor: pointer;\n}\n.canvas-react-button:hover:not(:disabled) {\n color: #1677ff;\n border-color: #1677ff;\n}\n.canvas-react-button:disabled {\n cursor: not-allowed;\n opacity: 0.5;\n}\n.canvas-react-button-primary {\n color: #fff;\n border-color: #1677ff;\n background: #1677ff;\n}\n.canvas-react-button-primary:hover:not(:disabled) {\n color: #fff;\n border-color: #4096ff;\n background: #4096ff;\n}\n.canvas-react-button-danger {\n color: #dc2626;\n border-color: #fca5a5;\n}\n.canvas-react-button-small {\n min-height: 24px;\n padding: 2px 8px;\n}\n.canvas-react-button-large {\n min-height: 40px;\n padding: 6px 18px;\n}\n.canvas-react-button-icon {\n display: inline-flex;\n}\n.canvas-react-row {\n display: flex;\n flex-flow: row wrap;\n}\n.canvas-react-col {\n min-width: 0;\n padding-inline: 8px;\n}\n.canvas-react-radio-group {\n display: flex;\n gap: 16px;\n}\n.canvas-react-radio {\n display: inline-flex;\n align-items: center;\n gap: 6px;\n cursor: pointer;\n}\n.canvas-react-radio input {\n position: absolute;\n opacity: 0;\n pointer-events: none;\n}\n.canvas-react-radio-mark {\n width: 14px;\n height: 14px;\n border: 1px solid #94a3b8;\n border-radius: 50%;\n box-sizing: border-box;\n}\n.canvas-react-radio input:checked + .canvas-react-radio-mark {\n border: 4px solid #1677ff;\n}\n.canvas-react-form-item {\n display: flex;\n flex-direction: column;\n gap: 6px;\n margin-bottom: 16px;\n}\n.canvas-react-form-label {\n color: #334155;\n font-size: 14px;\n}\n.canvas-react-form-error {\n color: #dc2626;\n font-size: 12px;\n}\n.canvas-react-textarea {\n width: 100%;\n min-height: 72px;\n padding: 8px 10px;\n border: 1px solid #d9d9d9;\n border-radius: 6px;\n box-sizing: border-box;\n font: inherit;\n resize: vertical;\n}\n.canvas-react-message-host {\n position: fixed;\n z-index: 3000;\n top: 24px;\n left: 50%;\n display: flex;\n flex-direction: column;\n gap: 8px;\n transform: translateX(-50%);\n pointer-events: none;\n}\n.canvas-react-message {\n padding: 9px 14px;\n border: 1px solid #e2e8f0;\n border-radius: 8px;\n color: #334155;\n background: #fff;\n box-shadow: 0 8px 24px rgba(15, 23, 42, 0.14);\n}\n.canvas-react-message-error {\n color: #b91c1c;\n border-color: #fecaca;\n}\n");
|
|
5918
6187
|
function ReactButton({
|
|
5919
6188
|
children,
|
|
5920
6189
|
className,
|
|
@@ -6076,173 +6345,6 @@ function ReactTextArea({ className, ...props }) {
|
|
|
6076
6345
|
}
|
|
6077
6346
|
);
|
|
6078
6347
|
}
|
|
6079
|
-
function createFormInstance() {
|
|
6080
|
-
const store = {
|
|
6081
|
-
values: {},
|
|
6082
|
-
initialValues: {},
|
|
6083
|
-
errors: {},
|
|
6084
|
-
rules: /* @__PURE__ */ new Map(),
|
|
6085
|
-
listeners: /* @__PURE__ */ new Set(),
|
|
6086
|
-
revision: 0,
|
|
6087
|
-
notify() {
|
|
6088
|
-
store.revision += 1;
|
|
6089
|
-
store.listeners.forEach((listener) => listener());
|
|
6090
|
-
}
|
|
6091
|
-
};
|
|
6092
|
-
return {
|
|
6093
|
-
__store: store,
|
|
6094
|
-
getFieldValue: (name) => store.values[name],
|
|
6095
|
-
setFieldsValue(values) {
|
|
6096
|
-
store.values = { ...store.values, ...values };
|
|
6097
|
-
Object.keys(values).forEach((name) => {
|
|
6098
|
-
delete store.errors[name];
|
|
6099
|
-
});
|
|
6100
|
-
store.notify();
|
|
6101
|
-
},
|
|
6102
|
-
resetFields() {
|
|
6103
|
-
store.values = { ...store.initialValues };
|
|
6104
|
-
store.errors = {};
|
|
6105
|
-
store.notify();
|
|
6106
|
-
},
|
|
6107
|
-
async validateFields() {
|
|
6108
|
-
const errors = {};
|
|
6109
|
-
for (const [name, rules] of store.rules) {
|
|
6110
|
-
const value = store.values[name];
|
|
6111
|
-
for (const rawRule of rules) {
|
|
6112
|
-
const rule = typeof rawRule === "function" ? rawRule({ getFieldValue: (field) => store.values[field] }) : rawRule;
|
|
6113
|
-
if (rule.required && (value === void 0 || value === null || value === "")) {
|
|
6114
|
-
errors[name] = rule.message ?? "\u6B64\u9879\u4E3A\u5FC5\u586B\u9879";
|
|
6115
|
-
break;
|
|
6116
|
-
}
|
|
6117
|
-
if ((rule.type === "number" || rule.type === "integer") && typeof value === "number" && rule.min !== void 0 && value < rule.min) {
|
|
6118
|
-
errors[name] = rule.message ?? `\u4E0D\u80FD\u5C0F\u4E8E ${rule.min}`;
|
|
6119
|
-
break;
|
|
6120
|
-
}
|
|
6121
|
-
if ((rule.type === "number" || rule.type === "integer") && typeof value === "number" && rule.max !== void 0 && value > rule.max) {
|
|
6122
|
-
errors[name] = rule.message ?? `\u4E0D\u80FD\u5927\u4E8E ${rule.max}`;
|
|
6123
|
-
break;
|
|
6124
|
-
}
|
|
6125
|
-
if (rule.type === "integer" && typeof value === "number" && !Number.isInteger(value)) {
|
|
6126
|
-
errors[name] = rule.message ?? "\u8BF7\u8F93\u5165\u6574\u6570";
|
|
6127
|
-
break;
|
|
6128
|
-
}
|
|
6129
|
-
if (rule.validator) {
|
|
6130
|
-
try {
|
|
6131
|
-
await rule.validator(rule, value);
|
|
6132
|
-
} catch (error) {
|
|
6133
|
-
errors[name] = error instanceof Error ? error.message : "\u6821\u9A8C\u5931\u8D25";
|
|
6134
|
-
break;
|
|
6135
|
-
}
|
|
6136
|
-
}
|
|
6137
|
-
}
|
|
6138
|
-
}
|
|
6139
|
-
store.errors = errors;
|
|
6140
|
-
store.notify();
|
|
6141
|
-
if (Object.keys(errors).length > 0) {
|
|
6142
|
-
return Promise.reject({
|
|
6143
|
-
errorFields: errors,
|
|
6144
|
-
values: { ...store.values }
|
|
6145
|
-
});
|
|
6146
|
-
}
|
|
6147
|
-
return { ...store.values };
|
|
6148
|
-
}
|
|
6149
|
-
};
|
|
6150
|
-
}
|
|
6151
|
-
function useReactForm() {
|
|
6152
|
-
const formRef = React.useRef();
|
|
6153
|
-
if (!formRef.current) formRef.current = createFormInstance();
|
|
6154
|
-
return [formRef.current];
|
|
6155
|
-
}
|
|
6156
|
-
function useReactFormWatch(name, form) {
|
|
6157
|
-
return React.useSyncExternalStore(
|
|
6158
|
-
(listener) => {
|
|
6159
|
-
form.__store.listeners.add(listener);
|
|
6160
|
-
return () => form.__store.listeners.delete(listener);
|
|
6161
|
-
},
|
|
6162
|
-
() => form.__store.revision,
|
|
6163
|
-
() => 0
|
|
6164
|
-
) >= 0 ? form.getFieldValue(name) : void 0;
|
|
6165
|
-
}
|
|
6166
|
-
var FormContext = React.createContext(null);
|
|
6167
|
-
function ReactFormRoot({
|
|
6168
|
-
form,
|
|
6169
|
-
initialValues,
|
|
6170
|
-
layout = "vertical",
|
|
6171
|
-
className,
|
|
6172
|
-
children,
|
|
6173
|
-
...props
|
|
6174
|
-
}) {
|
|
6175
|
-
const initialKey = React.useMemo(
|
|
6176
|
-
() => JSON.stringify(initialValues ?? {}),
|
|
6177
|
-
[initialValues]
|
|
6178
|
-
);
|
|
6179
|
-
React.useEffect(() => {
|
|
6180
|
-
form.__store.initialValues = { ...initialValues };
|
|
6181
|
-
form.__store.values = { ...initialValues, ...form.__store.values };
|
|
6182
|
-
form.__store.notify();
|
|
6183
|
-
}, [form, initialKey]);
|
|
6184
|
-
return /* @__PURE__ */ jsxRuntime.jsx(FormContext.Provider, { value: form, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
6185
|
-
"form",
|
|
6186
|
-
{
|
|
6187
|
-
...props,
|
|
6188
|
-
className: joinClassNames(
|
|
6189
|
-
`${REACT_COMPONENT_PREFIX}-form`,
|
|
6190
|
-
`${REACT_COMPONENT_PREFIX}-form-${layout}`,
|
|
6191
|
-
className
|
|
6192
|
-
),
|
|
6193
|
-
onSubmit: (event) => event.preventDefault(),
|
|
6194
|
-
children
|
|
6195
|
-
}
|
|
6196
|
-
) });
|
|
6197
|
-
}
|
|
6198
|
-
function ReactFormItem({
|
|
6199
|
-
label,
|
|
6200
|
-
name,
|
|
6201
|
-
children,
|
|
6202
|
-
rules = [],
|
|
6203
|
-
initialValue
|
|
6204
|
-
}) {
|
|
6205
|
-
const form = React.useContext(FormContext);
|
|
6206
|
-
if (!form) throw new Error("ReactForm.Item \u5FC5\u987B\u5728 ReactForm \u5185\u4F7F\u7528");
|
|
6207
|
-
React.useSyncExternalStore(
|
|
6208
|
-
(listener) => {
|
|
6209
|
-
form.__store.listeners.add(listener);
|
|
6210
|
-
return () => form.__store.listeners.delete(listener);
|
|
6211
|
-
},
|
|
6212
|
-
() => form.__store.revision,
|
|
6213
|
-
() => 0
|
|
6214
|
-
);
|
|
6215
|
-
React.useEffect(() => {
|
|
6216
|
-
form.__store.rules.set(name, rules);
|
|
6217
|
-
if (form.getFieldValue(name) === void 0 && initialValue !== void 0) {
|
|
6218
|
-
form.setFieldsValue({ [name]: initialValue });
|
|
6219
|
-
}
|
|
6220
|
-
return () => {
|
|
6221
|
-
form.__store.rules.delete(name);
|
|
6222
|
-
};
|
|
6223
|
-
}, [form, initialValue, name, rules]);
|
|
6224
|
-
const childProps = children.props;
|
|
6225
|
-
const value = form.getFieldValue(name);
|
|
6226
|
-
return /* @__PURE__ */ jsxRuntime.jsxs("label", { className: `${REACT_COMPONENT_PREFIX}-form-item`, children: [
|
|
6227
|
-
label ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: `${REACT_COMPONENT_PREFIX}-form-label`, children: label }) : null,
|
|
6228
|
-
React.cloneElement(children, {
|
|
6229
|
-
value: value ?? "",
|
|
6230
|
-
onChange: (...args) => {
|
|
6231
|
-
const first = args[0];
|
|
6232
|
-
const nextValue = typeof first === "object" && first !== null && "target" in first ? first.target?.value : first;
|
|
6233
|
-
form.setFieldsValue({ [name]: nextValue });
|
|
6234
|
-
const childOnChange = childProps.onChange;
|
|
6235
|
-
if (typeof childOnChange === "function") childOnChange(...args);
|
|
6236
|
-
}
|
|
6237
|
-
}),
|
|
6238
|
-
form.__store.errors[name] ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: `${REACT_COMPONENT_PREFIX}-form-error`, children: form.__store.errors[name] }) : null
|
|
6239
|
-
] });
|
|
6240
|
-
}
|
|
6241
|
-
var ReactForm = Object.assign(ReactFormRoot, {
|
|
6242
|
-
Item: ReactFormItem,
|
|
6243
|
-
useForm: useReactForm,
|
|
6244
|
-
useWatch: useReactFormWatch
|
|
6245
|
-
});
|
|
6246
6348
|
function showMessage(type, content) {
|
|
6247
6349
|
if (typeof document === "undefined") return;
|
|
6248
6350
|
const hostId = `${REACT_COMPONENT_PREFIX}-message-host`;
|
|
@@ -9841,6 +9943,7 @@ exports.ReactDateTimeRangePicker = ReactDateTimeRangePicker;
|
|
|
9841
9943
|
exports.ReactFilterPanel = ReactFilterPanel;
|
|
9842
9944
|
exports.ReactFlex = ReactFlex;
|
|
9843
9945
|
exports.ReactForm = ReactForm;
|
|
9946
|
+
exports.ReactFormItem = ReactFormItem;
|
|
9844
9947
|
exports.ReactImagePreview = ReactImagePreview;
|
|
9845
9948
|
exports.ReactInput = ReactInput;
|
|
9846
9949
|
exports.ReactInputNumber = ReactInputNumber;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
|
-
import { InputHTMLAttributes, ReactNode, KeyboardEvent as KeyboardEvent$1,
|
|
2
|
+
import { InputHTMLAttributes, ReactNode, HTMLAttributes, CSSProperties, KeyboardEvent as KeyboardEvent$1, ButtonHTMLAttributes, MouseEvent, RefObject, TextareaHTMLAttributes, ReactElement } from 'react';
|
|
3
3
|
|
|
4
4
|
interface ReactCheckboxRef {
|
|
5
5
|
focus: () => void;
|
|
@@ -102,6 +102,80 @@ declare function ReactFilterPanel(props: {
|
|
|
102
102
|
request: ReactFilterPanelRequest | null;
|
|
103
103
|
}): react.JSX.Element | null;
|
|
104
104
|
|
|
105
|
+
type ReactFormValues = Record<string, unknown>;
|
|
106
|
+
interface ReactFormRuleContext {
|
|
107
|
+
getFieldValue: (name: string) => unknown;
|
|
108
|
+
}
|
|
109
|
+
interface ReactFormRuleConfig {
|
|
110
|
+
required?: boolean;
|
|
111
|
+
message?: string;
|
|
112
|
+
type?: "number" | "integer" | "string";
|
|
113
|
+
min?: number;
|
|
114
|
+
max?: number;
|
|
115
|
+
validator?: (rule: ReactFormRuleConfig, value: unknown) => void | Promise<void>;
|
|
116
|
+
}
|
|
117
|
+
type ReactFormRule = ReactFormRuleConfig | ((context: ReactFormRuleContext) => ReactFormRuleConfig);
|
|
118
|
+
interface ReactFormInstance<T extends object = Record<string, unknown>> {
|
|
119
|
+
getFieldValue: (name: string) => unknown;
|
|
120
|
+
setFieldsValue: (values: Partial<T>) => void;
|
|
121
|
+
resetFields: () => void;
|
|
122
|
+
validateFields: () => Promise<T>;
|
|
123
|
+
/** @internal */
|
|
124
|
+
__store: FormStore;
|
|
125
|
+
}
|
|
126
|
+
interface FormStore {
|
|
127
|
+
values: ReactFormValues;
|
|
128
|
+
initialValues: ReactFormValues;
|
|
129
|
+
errors: Record<string, string>;
|
|
130
|
+
rules: Map<string, ReactFormRule[]>;
|
|
131
|
+
listeners: Set<() => void>;
|
|
132
|
+
revision: number;
|
|
133
|
+
notify: () => void;
|
|
134
|
+
}
|
|
135
|
+
type ReactFormLayout = "vertical" | "horizontal" | "inline";
|
|
136
|
+
/** 创建表单实例。 */
|
|
137
|
+
declare function useReactForm<T extends object = Record<string, unknown>>(): readonly [ReactFormInstance<T>];
|
|
138
|
+
/** 订阅表单字段值。 */
|
|
139
|
+
declare function useReactFormWatch(name: string, form: ReactFormInstance): unknown;
|
|
140
|
+
interface ReactFormProps extends Omit<HTMLAttributes<HTMLFormElement>, "onSubmit"> {
|
|
141
|
+
form?: ReactFormInstance;
|
|
142
|
+
initialValues?: ReactFormValues;
|
|
143
|
+
layout?: ReactFormLayout;
|
|
144
|
+
noWrap?: boolean;
|
|
145
|
+
itemSpacing?: CSSProperties["marginBlockEnd"];
|
|
146
|
+
labelWidth?: CSSProperties["width"];
|
|
147
|
+
labelAlign?: "left" | "right";
|
|
148
|
+
colon?: boolean;
|
|
149
|
+
requiredMark?: boolean;
|
|
150
|
+
}
|
|
151
|
+
declare function ReactFormRoot({ form: formProp, initialValues, layout, noWrap, itemSpacing, labelWidth, labelAlign, colon, requiredMark, className, children, ...props }: ReactFormProps): react.JSX.Element;
|
|
152
|
+
interface ReactFormItemProps {
|
|
153
|
+
label?: ReactNode;
|
|
154
|
+
name?: string;
|
|
155
|
+
children: ReactNode;
|
|
156
|
+
rules?: ReactFormRule[];
|
|
157
|
+
dependencies?: string[];
|
|
158
|
+
initialValue?: unknown;
|
|
159
|
+
required?: boolean;
|
|
160
|
+
colon?: boolean;
|
|
161
|
+
labelWidth?: CSSProperties["width"];
|
|
162
|
+
labelAlign?: "left" | "right";
|
|
163
|
+
labelStyle?: CSSProperties;
|
|
164
|
+
controlStyle?: CSSProperties;
|
|
165
|
+
help?: ReactNode;
|
|
166
|
+
extra?: ReactNode;
|
|
167
|
+
className?: string;
|
|
168
|
+
style?: CSSProperties;
|
|
169
|
+
noWrap?: boolean;
|
|
170
|
+
}
|
|
171
|
+
declare function ReactFormItem({ label, name, children, rules, initialValue, required, colon, labelWidth, labelAlign, labelStyle, controlStyle, help, extra, className, style, noWrap, }: ReactFormItemProps): react.JSX.Element;
|
|
172
|
+
/** Ant Design 风格表单,支持横向、纵向与行内布局。 */
|
|
173
|
+
declare const ReactForm: typeof ReactFormRoot & {
|
|
174
|
+
Item: typeof ReactFormItem;
|
|
175
|
+
useForm: typeof useReactForm;
|
|
176
|
+
useWatch: typeof useReactFormWatch;
|
|
177
|
+
};
|
|
178
|
+
|
|
105
179
|
interface ReactInputProps extends Omit<InputHTMLAttributes<HTMLInputElement>, "size"> {
|
|
106
180
|
/**
|
|
107
181
|
* 回车确认回调。
|
|
@@ -1323,61 +1397,6 @@ interface ReactTextAreaProps extends TextareaHTMLAttributes<HTMLTextAreaElement>
|
|
|
1323
1397
|
}
|
|
1324
1398
|
/** 多行文本输入框。 */
|
|
1325
1399
|
declare function ReactTextArea({ className, ...props }: ReactTextAreaProps): react.JSX.Element;
|
|
1326
|
-
type ReactFormValues = Record<string, unknown>;
|
|
1327
|
-
interface ReactFormRuleContext {
|
|
1328
|
-
getFieldValue: (name: string) => any;
|
|
1329
|
-
}
|
|
1330
|
-
interface ReactFormRuleConfig {
|
|
1331
|
-
required?: boolean;
|
|
1332
|
-
message?: string;
|
|
1333
|
-
type?: "number" | "integer" | "string";
|
|
1334
|
-
min?: number;
|
|
1335
|
-
max?: number;
|
|
1336
|
-
validator?: (rule: ReactFormRuleConfig, value: any) => void | Promise<void>;
|
|
1337
|
-
}
|
|
1338
|
-
type ReactFormRule = ReactFormRuleConfig | ((context: ReactFormRuleContext) => ReactFormRuleConfig);
|
|
1339
|
-
interface ReactFormInstance<T extends object = any> {
|
|
1340
|
-
getFieldValue: (name: string) => any;
|
|
1341
|
-
setFieldsValue: (values: Partial<T>) => void;
|
|
1342
|
-
resetFields: () => void;
|
|
1343
|
-
validateFields: () => Promise<T>;
|
|
1344
|
-
/** @internal */
|
|
1345
|
-
__store: FormStore;
|
|
1346
|
-
}
|
|
1347
|
-
interface FormStore {
|
|
1348
|
-
values: ReactFormValues;
|
|
1349
|
-
initialValues: ReactFormValues;
|
|
1350
|
-
errors: Record<string, string>;
|
|
1351
|
-
rules: Map<string, ReactFormRule[]>;
|
|
1352
|
-
listeners: Set<() => void>;
|
|
1353
|
-
revision: number;
|
|
1354
|
-
notify: () => void;
|
|
1355
|
-
}
|
|
1356
|
-
/** 创建表单实例。 */
|
|
1357
|
-
declare function useReactForm<T extends object = any>(): readonly [ReactFormInstance<T>];
|
|
1358
|
-
/** 订阅表单字段值。 */
|
|
1359
|
-
declare function useReactFormWatch(name: string, form: ReactFormInstance): any;
|
|
1360
|
-
interface ReactFormProps extends Omit<HTMLAttributes<HTMLFormElement>, "onSubmit"> {
|
|
1361
|
-
form: ReactFormInstance;
|
|
1362
|
-
initialValues?: ReactFormValues;
|
|
1363
|
-
layout?: "vertical" | "horizontal";
|
|
1364
|
-
}
|
|
1365
|
-
declare function ReactFormRoot({ form, initialValues, layout, className, children, ...props }: ReactFormProps): react.JSX.Element;
|
|
1366
|
-
interface ReactFormItemProps {
|
|
1367
|
-
label?: ReactNode;
|
|
1368
|
-
name: string;
|
|
1369
|
-
children: ReactElement;
|
|
1370
|
-
rules?: ReactFormRule[];
|
|
1371
|
-
dependencies?: string[];
|
|
1372
|
-
initialValue?: unknown;
|
|
1373
|
-
}
|
|
1374
|
-
declare function ReactFormItem({ label, name, children, rules, initialValue, }: ReactFormItemProps): react.JSX.Element;
|
|
1375
|
-
/** 带字段绑定和异步校验的轻量表单。 */
|
|
1376
|
-
declare const ReactForm: typeof ReactFormRoot & {
|
|
1377
|
-
Item: typeof ReactFormItem;
|
|
1378
|
-
useForm: typeof useReactForm;
|
|
1379
|
-
useWatch: typeof useReactFormWatch;
|
|
1380
|
-
};
|
|
1381
1400
|
type ReactMessageType = "info" | "success" | "warning" | "error";
|
|
1382
1401
|
/** 全局消息提示服务。 */
|
|
1383
1402
|
declare const reactMessage: {
|
|
@@ -1410,4 +1429,4 @@ declare function useReactContentScale(): ReactContentScaleValue;
|
|
|
1410
1429
|
*/
|
|
1411
1430
|
declare const REACT_COMPONENT_PREFIX = "canvas-react";
|
|
1412
1431
|
|
|
1413
|
-
export { type CascaderCheckedStrategy, type CascaderPath, REACT_COMPONENT_PREFIX, ReactAutoComplete, type ReactAutoCompleteProps, ReactButton, type ReactButtonProps, ReactCascader, type ReactCascaderChangeInfo, type ReactCascaderOption, type ReactCascaderProps, ReactCheckbox, type ReactCheckboxProps, type ReactCheckboxRef, ReactCol, type ReactColProps, ReactColorPicker, type ReactColorPickerProps, ReactContentScaleProvider, type ReactContentScaleValue, ReactDatePicker, type ReactDatePickerProps, ReactDateRangePicker, type ReactDateRangePickerProps, ReactDateTimePicker, type ReactDateTimePickerProps, ReactDateTimeRangePicker, type ReactDateTimeRangePickerProps, type ReactFilterConditionOperator, ReactFilterPanel, type ReactFilterPanelCondition, type ReactFilterPanelOption, type ReactFilterPanelRequest, type ReactFilterPanelTexts, type ReactFilterPanelValue, ReactFlex, type ReactFlexProps, ReactForm, type ReactFormInstance, type ReactFormItemProps, type ReactFormProps, type ReactFormRule, type ReactFormRuleConfig, type ReactFormValues, ReactImagePreview, type ReactImagePreviewProps, ReactInput, ReactInputNumber, type ReactInputNumberProps, type ReactInputProps, ReactInputRange, type ReactInputRangeProps, type ReactInputRangeValue, type ReactMessageType, ReactModal, type ReactModalButtonProps, type ReactModalCancelEvent, type ReactModalProps, ReactMonthPicker, type ReactMonthPickerProps, ReactNumberInput, type ReactNumberInputProps, ReactPagination, type ReactPaginationProps, type ReactPaginationStyles, ReactPopconfirm, type ReactPopconfirmButtonProps, type ReactPopconfirmPlacement, type ReactPopconfirmProps, ReactPopup, type ReactPopupProps, ReactQuarterPicker, type ReactQuarterPickerProps, ReactRadio, type ReactRadioGroupProps, type ReactRadioProps, type ReactResizablePanel, type ReactResizablePanelSizes, ReactResizablePanels, type ReactResizablePanelsDirection, type ReactResizablePanelsProps, type ReactResizablePanelsResizeInfo, ReactRow, type ReactRowProps, ReactScrollbarPositionDialog, type ReactScrollbarSettings, ReactScrollbarSettingsDialog, ReactSelect, type ReactSelectChangeInfo, type ReactSelectFilterOption, type ReactSelectOption, type ReactSelectProps, ReactTextArea, type ReactTextAreaProps, ReactTimePicker, type ReactTimePickerProps, ReactTimeRangePicker, type ReactTimeRangePickerProps, ReactTooltip, type ReactTooltipProps, ReactTransition, type ReactTransitionDuration, type ReactTransitionOptions, type ReactTransitionPhase, type ReactTransitionProps, type ReactTransitionState, ReactTreeSelect, type ReactTreeSelectChangeInfo, type TreeSelectNode as ReactTreeSelectNode, type ReactTreeSelectProps, type ReactTreeSelectValue, ReactVirtualList, type ReactVirtualListProps, type ReactVirtualListRef, ReactYearPicker, type ReactYearPickerProps, type SharedScrollbarSettings, getSharedScrollbarSettings, reactMessage, resolveReactScrollbarMode, resolveResizablePanelSizes, setSharedScrollbarSettings, subscribeSharedScrollbarSettings, useReactContentScale, useReactForm, useReactFormWatch, useReactTransition };
|
|
1432
|
+
export { type CascaderCheckedStrategy, type CascaderPath, REACT_COMPONENT_PREFIX, ReactAutoComplete, type ReactAutoCompleteProps, ReactButton, type ReactButtonProps, ReactCascader, type ReactCascaderChangeInfo, type ReactCascaderOption, type ReactCascaderProps, ReactCheckbox, type ReactCheckboxProps, type ReactCheckboxRef, ReactCol, type ReactColProps, ReactColorPicker, type ReactColorPickerProps, ReactContentScaleProvider, type ReactContentScaleValue, ReactDatePicker, type ReactDatePickerProps, ReactDateRangePicker, type ReactDateRangePickerProps, ReactDateTimePicker, type ReactDateTimePickerProps, ReactDateTimeRangePicker, type ReactDateTimeRangePickerProps, type ReactFilterConditionOperator, ReactFilterPanel, type ReactFilterPanelCondition, type ReactFilterPanelOption, type ReactFilterPanelRequest, type ReactFilterPanelTexts, type ReactFilterPanelValue, ReactFlex, type ReactFlexProps, ReactForm, type ReactFormInstance, ReactFormItem, type ReactFormItemProps, type ReactFormLayout, type ReactFormProps, type ReactFormRule, type ReactFormRuleConfig, type ReactFormRuleContext, type ReactFormValues, ReactImagePreview, type ReactImagePreviewProps, ReactInput, ReactInputNumber, type ReactInputNumberProps, type ReactInputProps, ReactInputRange, type ReactInputRangeProps, type ReactInputRangeValue, type ReactMessageType, ReactModal, type ReactModalButtonProps, type ReactModalCancelEvent, type ReactModalProps, ReactMonthPicker, type ReactMonthPickerProps, ReactNumberInput, type ReactNumberInputProps, ReactPagination, type ReactPaginationProps, type ReactPaginationStyles, ReactPopconfirm, type ReactPopconfirmButtonProps, type ReactPopconfirmPlacement, type ReactPopconfirmProps, ReactPopup, type ReactPopupProps, ReactQuarterPicker, type ReactQuarterPickerProps, ReactRadio, type ReactRadioGroupProps, type ReactRadioProps, type ReactResizablePanel, type ReactResizablePanelSizes, ReactResizablePanels, type ReactResizablePanelsDirection, type ReactResizablePanelsProps, type ReactResizablePanelsResizeInfo, ReactRow, type ReactRowProps, ReactScrollbarPositionDialog, type ReactScrollbarSettings, ReactScrollbarSettingsDialog, ReactSelect, type ReactSelectChangeInfo, type ReactSelectFilterOption, type ReactSelectOption, type ReactSelectProps, ReactTextArea, type ReactTextAreaProps, ReactTimePicker, type ReactTimePickerProps, ReactTimeRangePicker, type ReactTimeRangePickerProps, ReactTooltip, type ReactTooltipProps, ReactTransition, type ReactTransitionDuration, type ReactTransitionOptions, type ReactTransitionPhase, type ReactTransitionProps, type ReactTransitionState, ReactTreeSelect, type ReactTreeSelectChangeInfo, type TreeSelectNode as ReactTreeSelectNode, type ReactTreeSelectProps, type ReactTreeSelectValue, ReactVirtualList, type ReactVirtualListProps, type ReactVirtualListRef, ReactYearPicker, type ReactYearPickerProps, type SharedScrollbarSettings, getSharedScrollbarSettings, reactMessage, resolveReactScrollbarMode, resolveResizablePanelSizes, setSharedScrollbarSettings, subscribeSharedScrollbarSettings, useReactContentScale, useReactForm, useReactFormWatch, useReactTransition };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
|
-
import { InputHTMLAttributes, ReactNode, KeyboardEvent as KeyboardEvent$1,
|
|
2
|
+
import { InputHTMLAttributes, ReactNode, HTMLAttributes, CSSProperties, KeyboardEvent as KeyboardEvent$1, ButtonHTMLAttributes, MouseEvent, RefObject, TextareaHTMLAttributes, ReactElement } from 'react';
|
|
3
3
|
|
|
4
4
|
interface ReactCheckboxRef {
|
|
5
5
|
focus: () => void;
|
|
@@ -102,6 +102,80 @@ declare function ReactFilterPanel(props: {
|
|
|
102
102
|
request: ReactFilterPanelRequest | null;
|
|
103
103
|
}): react.JSX.Element | null;
|
|
104
104
|
|
|
105
|
+
type ReactFormValues = Record<string, unknown>;
|
|
106
|
+
interface ReactFormRuleContext {
|
|
107
|
+
getFieldValue: (name: string) => unknown;
|
|
108
|
+
}
|
|
109
|
+
interface ReactFormRuleConfig {
|
|
110
|
+
required?: boolean;
|
|
111
|
+
message?: string;
|
|
112
|
+
type?: "number" | "integer" | "string";
|
|
113
|
+
min?: number;
|
|
114
|
+
max?: number;
|
|
115
|
+
validator?: (rule: ReactFormRuleConfig, value: unknown) => void | Promise<void>;
|
|
116
|
+
}
|
|
117
|
+
type ReactFormRule = ReactFormRuleConfig | ((context: ReactFormRuleContext) => ReactFormRuleConfig);
|
|
118
|
+
interface ReactFormInstance<T extends object = Record<string, unknown>> {
|
|
119
|
+
getFieldValue: (name: string) => unknown;
|
|
120
|
+
setFieldsValue: (values: Partial<T>) => void;
|
|
121
|
+
resetFields: () => void;
|
|
122
|
+
validateFields: () => Promise<T>;
|
|
123
|
+
/** @internal */
|
|
124
|
+
__store: FormStore;
|
|
125
|
+
}
|
|
126
|
+
interface FormStore {
|
|
127
|
+
values: ReactFormValues;
|
|
128
|
+
initialValues: ReactFormValues;
|
|
129
|
+
errors: Record<string, string>;
|
|
130
|
+
rules: Map<string, ReactFormRule[]>;
|
|
131
|
+
listeners: Set<() => void>;
|
|
132
|
+
revision: number;
|
|
133
|
+
notify: () => void;
|
|
134
|
+
}
|
|
135
|
+
type ReactFormLayout = "vertical" | "horizontal" | "inline";
|
|
136
|
+
/** 创建表单实例。 */
|
|
137
|
+
declare function useReactForm<T extends object = Record<string, unknown>>(): readonly [ReactFormInstance<T>];
|
|
138
|
+
/** 订阅表单字段值。 */
|
|
139
|
+
declare function useReactFormWatch(name: string, form: ReactFormInstance): unknown;
|
|
140
|
+
interface ReactFormProps extends Omit<HTMLAttributes<HTMLFormElement>, "onSubmit"> {
|
|
141
|
+
form?: ReactFormInstance;
|
|
142
|
+
initialValues?: ReactFormValues;
|
|
143
|
+
layout?: ReactFormLayout;
|
|
144
|
+
noWrap?: boolean;
|
|
145
|
+
itemSpacing?: CSSProperties["marginBlockEnd"];
|
|
146
|
+
labelWidth?: CSSProperties["width"];
|
|
147
|
+
labelAlign?: "left" | "right";
|
|
148
|
+
colon?: boolean;
|
|
149
|
+
requiredMark?: boolean;
|
|
150
|
+
}
|
|
151
|
+
declare function ReactFormRoot({ form: formProp, initialValues, layout, noWrap, itemSpacing, labelWidth, labelAlign, colon, requiredMark, className, children, ...props }: ReactFormProps): react.JSX.Element;
|
|
152
|
+
interface ReactFormItemProps {
|
|
153
|
+
label?: ReactNode;
|
|
154
|
+
name?: string;
|
|
155
|
+
children: ReactNode;
|
|
156
|
+
rules?: ReactFormRule[];
|
|
157
|
+
dependencies?: string[];
|
|
158
|
+
initialValue?: unknown;
|
|
159
|
+
required?: boolean;
|
|
160
|
+
colon?: boolean;
|
|
161
|
+
labelWidth?: CSSProperties["width"];
|
|
162
|
+
labelAlign?: "left" | "right";
|
|
163
|
+
labelStyle?: CSSProperties;
|
|
164
|
+
controlStyle?: CSSProperties;
|
|
165
|
+
help?: ReactNode;
|
|
166
|
+
extra?: ReactNode;
|
|
167
|
+
className?: string;
|
|
168
|
+
style?: CSSProperties;
|
|
169
|
+
noWrap?: boolean;
|
|
170
|
+
}
|
|
171
|
+
declare function ReactFormItem({ label, name, children, rules, initialValue, required, colon, labelWidth, labelAlign, labelStyle, controlStyle, help, extra, className, style, noWrap, }: ReactFormItemProps): react.JSX.Element;
|
|
172
|
+
/** Ant Design 风格表单,支持横向、纵向与行内布局。 */
|
|
173
|
+
declare const ReactForm: typeof ReactFormRoot & {
|
|
174
|
+
Item: typeof ReactFormItem;
|
|
175
|
+
useForm: typeof useReactForm;
|
|
176
|
+
useWatch: typeof useReactFormWatch;
|
|
177
|
+
};
|
|
178
|
+
|
|
105
179
|
interface ReactInputProps extends Omit<InputHTMLAttributes<HTMLInputElement>, "size"> {
|
|
106
180
|
/**
|
|
107
181
|
* 回车确认回调。
|
|
@@ -1323,61 +1397,6 @@ interface ReactTextAreaProps extends TextareaHTMLAttributes<HTMLTextAreaElement>
|
|
|
1323
1397
|
}
|
|
1324
1398
|
/** 多行文本输入框。 */
|
|
1325
1399
|
declare function ReactTextArea({ className, ...props }: ReactTextAreaProps): react.JSX.Element;
|
|
1326
|
-
type ReactFormValues = Record<string, unknown>;
|
|
1327
|
-
interface ReactFormRuleContext {
|
|
1328
|
-
getFieldValue: (name: string) => any;
|
|
1329
|
-
}
|
|
1330
|
-
interface ReactFormRuleConfig {
|
|
1331
|
-
required?: boolean;
|
|
1332
|
-
message?: string;
|
|
1333
|
-
type?: "number" | "integer" | "string";
|
|
1334
|
-
min?: number;
|
|
1335
|
-
max?: number;
|
|
1336
|
-
validator?: (rule: ReactFormRuleConfig, value: any) => void | Promise<void>;
|
|
1337
|
-
}
|
|
1338
|
-
type ReactFormRule = ReactFormRuleConfig | ((context: ReactFormRuleContext) => ReactFormRuleConfig);
|
|
1339
|
-
interface ReactFormInstance<T extends object = any> {
|
|
1340
|
-
getFieldValue: (name: string) => any;
|
|
1341
|
-
setFieldsValue: (values: Partial<T>) => void;
|
|
1342
|
-
resetFields: () => void;
|
|
1343
|
-
validateFields: () => Promise<T>;
|
|
1344
|
-
/** @internal */
|
|
1345
|
-
__store: FormStore;
|
|
1346
|
-
}
|
|
1347
|
-
interface FormStore {
|
|
1348
|
-
values: ReactFormValues;
|
|
1349
|
-
initialValues: ReactFormValues;
|
|
1350
|
-
errors: Record<string, string>;
|
|
1351
|
-
rules: Map<string, ReactFormRule[]>;
|
|
1352
|
-
listeners: Set<() => void>;
|
|
1353
|
-
revision: number;
|
|
1354
|
-
notify: () => void;
|
|
1355
|
-
}
|
|
1356
|
-
/** 创建表单实例。 */
|
|
1357
|
-
declare function useReactForm<T extends object = any>(): readonly [ReactFormInstance<T>];
|
|
1358
|
-
/** 订阅表单字段值。 */
|
|
1359
|
-
declare function useReactFormWatch(name: string, form: ReactFormInstance): any;
|
|
1360
|
-
interface ReactFormProps extends Omit<HTMLAttributes<HTMLFormElement>, "onSubmit"> {
|
|
1361
|
-
form: ReactFormInstance;
|
|
1362
|
-
initialValues?: ReactFormValues;
|
|
1363
|
-
layout?: "vertical" | "horizontal";
|
|
1364
|
-
}
|
|
1365
|
-
declare function ReactFormRoot({ form, initialValues, layout, className, children, ...props }: ReactFormProps): react.JSX.Element;
|
|
1366
|
-
interface ReactFormItemProps {
|
|
1367
|
-
label?: ReactNode;
|
|
1368
|
-
name: string;
|
|
1369
|
-
children: ReactElement;
|
|
1370
|
-
rules?: ReactFormRule[];
|
|
1371
|
-
dependencies?: string[];
|
|
1372
|
-
initialValue?: unknown;
|
|
1373
|
-
}
|
|
1374
|
-
declare function ReactFormItem({ label, name, children, rules, initialValue, }: ReactFormItemProps): react.JSX.Element;
|
|
1375
|
-
/** 带字段绑定和异步校验的轻量表单。 */
|
|
1376
|
-
declare const ReactForm: typeof ReactFormRoot & {
|
|
1377
|
-
Item: typeof ReactFormItem;
|
|
1378
|
-
useForm: typeof useReactForm;
|
|
1379
|
-
useWatch: typeof useReactFormWatch;
|
|
1380
|
-
};
|
|
1381
1400
|
type ReactMessageType = "info" | "success" | "warning" | "error";
|
|
1382
1401
|
/** 全局消息提示服务。 */
|
|
1383
1402
|
declare const reactMessage: {
|
|
@@ -1410,4 +1429,4 @@ declare function useReactContentScale(): ReactContentScaleValue;
|
|
|
1410
1429
|
*/
|
|
1411
1430
|
declare const REACT_COMPONENT_PREFIX = "canvas-react";
|
|
1412
1431
|
|
|
1413
|
-
export { type CascaderCheckedStrategy, type CascaderPath, REACT_COMPONENT_PREFIX, ReactAutoComplete, type ReactAutoCompleteProps, ReactButton, type ReactButtonProps, ReactCascader, type ReactCascaderChangeInfo, type ReactCascaderOption, type ReactCascaderProps, ReactCheckbox, type ReactCheckboxProps, type ReactCheckboxRef, ReactCol, type ReactColProps, ReactColorPicker, type ReactColorPickerProps, ReactContentScaleProvider, type ReactContentScaleValue, ReactDatePicker, type ReactDatePickerProps, ReactDateRangePicker, type ReactDateRangePickerProps, ReactDateTimePicker, type ReactDateTimePickerProps, ReactDateTimeRangePicker, type ReactDateTimeRangePickerProps, type ReactFilterConditionOperator, ReactFilterPanel, type ReactFilterPanelCondition, type ReactFilterPanelOption, type ReactFilterPanelRequest, type ReactFilterPanelTexts, type ReactFilterPanelValue, ReactFlex, type ReactFlexProps, ReactForm, type ReactFormInstance, type ReactFormItemProps, type ReactFormProps, type ReactFormRule, type ReactFormRuleConfig, type ReactFormValues, ReactImagePreview, type ReactImagePreviewProps, ReactInput, ReactInputNumber, type ReactInputNumberProps, type ReactInputProps, ReactInputRange, type ReactInputRangeProps, type ReactInputRangeValue, type ReactMessageType, ReactModal, type ReactModalButtonProps, type ReactModalCancelEvent, type ReactModalProps, ReactMonthPicker, type ReactMonthPickerProps, ReactNumberInput, type ReactNumberInputProps, ReactPagination, type ReactPaginationProps, type ReactPaginationStyles, ReactPopconfirm, type ReactPopconfirmButtonProps, type ReactPopconfirmPlacement, type ReactPopconfirmProps, ReactPopup, type ReactPopupProps, ReactQuarterPicker, type ReactQuarterPickerProps, ReactRadio, type ReactRadioGroupProps, type ReactRadioProps, type ReactResizablePanel, type ReactResizablePanelSizes, ReactResizablePanels, type ReactResizablePanelsDirection, type ReactResizablePanelsProps, type ReactResizablePanelsResizeInfo, ReactRow, type ReactRowProps, ReactScrollbarPositionDialog, type ReactScrollbarSettings, ReactScrollbarSettingsDialog, ReactSelect, type ReactSelectChangeInfo, type ReactSelectFilterOption, type ReactSelectOption, type ReactSelectProps, ReactTextArea, type ReactTextAreaProps, ReactTimePicker, type ReactTimePickerProps, ReactTimeRangePicker, type ReactTimeRangePickerProps, ReactTooltip, type ReactTooltipProps, ReactTransition, type ReactTransitionDuration, type ReactTransitionOptions, type ReactTransitionPhase, type ReactTransitionProps, type ReactTransitionState, ReactTreeSelect, type ReactTreeSelectChangeInfo, type TreeSelectNode as ReactTreeSelectNode, type ReactTreeSelectProps, type ReactTreeSelectValue, ReactVirtualList, type ReactVirtualListProps, type ReactVirtualListRef, ReactYearPicker, type ReactYearPickerProps, type SharedScrollbarSettings, getSharedScrollbarSettings, reactMessage, resolveReactScrollbarMode, resolveResizablePanelSizes, setSharedScrollbarSettings, subscribeSharedScrollbarSettings, useReactContentScale, useReactForm, useReactFormWatch, useReactTransition };
|
|
1432
|
+
export { type CascaderCheckedStrategy, type CascaderPath, REACT_COMPONENT_PREFIX, ReactAutoComplete, type ReactAutoCompleteProps, ReactButton, type ReactButtonProps, ReactCascader, type ReactCascaderChangeInfo, type ReactCascaderOption, type ReactCascaderProps, ReactCheckbox, type ReactCheckboxProps, type ReactCheckboxRef, ReactCol, type ReactColProps, ReactColorPicker, type ReactColorPickerProps, ReactContentScaleProvider, type ReactContentScaleValue, ReactDatePicker, type ReactDatePickerProps, ReactDateRangePicker, type ReactDateRangePickerProps, ReactDateTimePicker, type ReactDateTimePickerProps, ReactDateTimeRangePicker, type ReactDateTimeRangePickerProps, type ReactFilterConditionOperator, ReactFilterPanel, type ReactFilterPanelCondition, type ReactFilterPanelOption, type ReactFilterPanelRequest, type ReactFilterPanelTexts, type ReactFilterPanelValue, ReactFlex, type ReactFlexProps, ReactForm, type ReactFormInstance, ReactFormItem, type ReactFormItemProps, type ReactFormLayout, type ReactFormProps, type ReactFormRule, type ReactFormRuleConfig, type ReactFormRuleContext, type ReactFormValues, ReactImagePreview, type ReactImagePreviewProps, ReactInput, ReactInputNumber, type ReactInputNumberProps, type ReactInputProps, ReactInputRange, type ReactInputRangeProps, type ReactInputRangeValue, type ReactMessageType, ReactModal, type ReactModalButtonProps, type ReactModalCancelEvent, type ReactModalProps, ReactMonthPicker, type ReactMonthPickerProps, ReactNumberInput, type ReactNumberInputProps, ReactPagination, type ReactPaginationProps, type ReactPaginationStyles, ReactPopconfirm, type ReactPopconfirmButtonProps, type ReactPopconfirmPlacement, type ReactPopconfirmProps, ReactPopup, type ReactPopupProps, ReactQuarterPicker, type ReactQuarterPickerProps, ReactRadio, type ReactRadioGroupProps, type ReactRadioProps, type ReactResizablePanel, type ReactResizablePanelSizes, ReactResizablePanels, type ReactResizablePanelsDirection, type ReactResizablePanelsProps, type ReactResizablePanelsResizeInfo, ReactRow, type ReactRowProps, ReactScrollbarPositionDialog, type ReactScrollbarSettings, ReactScrollbarSettingsDialog, ReactSelect, type ReactSelectChangeInfo, type ReactSelectFilterOption, type ReactSelectOption, type ReactSelectProps, ReactTextArea, type ReactTextAreaProps, ReactTimePicker, type ReactTimePickerProps, ReactTimeRangePicker, type ReactTimeRangePickerProps, ReactTooltip, type ReactTooltipProps, ReactTransition, type ReactTransitionDuration, type ReactTransitionOptions, type ReactTransitionPhase, type ReactTransitionProps, type ReactTransitionState, ReactTreeSelect, type ReactTreeSelectChangeInfo, type TreeSelectNode as ReactTreeSelectNode, type ReactTreeSelectProps, type ReactTreeSelectValue, ReactVirtualList, type ReactVirtualListProps, type ReactVirtualListRef, ReactYearPicker, type ReactYearPickerProps, type SharedScrollbarSettings, getSharedScrollbarSettings, reactMessage, resolveReactScrollbarMode, resolveResizablePanelSizes, setSharedScrollbarSettings, subscribeSharedScrollbarSettings, useReactContentScale, useReactForm, useReactFormWatch, useReactTransition };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { forwardRef, useRef, useEffect, useImperativeHandle, createContext, useState, useMemo, useLayoutEffect, useContext,
|
|
2
|
+
import { forwardRef, useRef, useEffect, useImperativeHandle, createContext, useState, useMemo, useLayoutEffect, useSyncExternalStore, useContext, isValidElement, cloneElement, Fragment as Fragment$1, useId } from 'react';
|
|
3
3
|
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
4
4
|
import { createPortal } from 'react-dom';
|
|
5
5
|
|
|
@@ -1497,6 +1497,275 @@ function actionStyle(primary) {
|
|
|
1497
1497
|
return { minWidth: 72, height: 32, padding: "0 12px", borderRadius: 6, border: primary ? "1px solid #1677ff" : "1px solid #d9d9d9", background: primary ? "#1677ff" : "#fff", color: primary ? "#fff" : "#374151", cursor: "pointer" };
|
|
1498
1498
|
}
|
|
1499
1499
|
|
|
1500
|
+
// src/components/form/style.css
|
|
1501
|
+
styleInject(".canvas-react-form {\n min-width: 0;\n}\n.canvas-react-form-vertical {\n display: grid;\n gap: 16px;\n}\n.canvas-react-form-horizontal {\n display: grid;\n gap: 12px;\n}\n.canvas-react-form-inline {\n display: flex;\n flex-wrap: wrap;\n align-items: flex-start;\n gap: 12px 16px;\n}\n.canvas-react-form-item {\n box-sizing: border-box;\n min-width: 0;\n}\n.canvas-react-form-item-vertical {\n display: grid;\n gap: 6px;\n}\n.canvas-react-form-item-horizontal {\n display: grid;\n grid-template-columns: auto minmax(0, 1fr);\n align-items: center;\n column-gap: 10px;\n row-gap: 4px;\n}\n.canvas-react-form-item-inline {\n display: inline-grid;\n grid-template-columns: auto minmax(0, 1fr);\n align-items: center;\n column-gap: 8px;\n}\n.canvas-react-form-item-no-wrap {\n flex-wrap: nowrap;\n}\n.canvas-react-form-item-horizontal.canvas-react-form-item-no-wrap {\n display: grid;\n grid-template-columns: max-content minmax(0, 1fr);\n}\n.canvas-react-form-horizontal > .canvas-react-form-item {\n margin-bottom: var(--canvas-react-form-item-spacing, 16px);\n}\n.canvas-react-form-item-inline.canvas-react-form-item-no-wrap {\n display: inline-grid;\n grid-template-columns: max-content minmax(0, 1fr);\n}\n.canvas-react-form-item-no-wrap > .canvas-react-form-label {\n white-space: nowrap;\n}\n.canvas-react-form-label {\n display: inline-flex;\n align-items: center;\n gap: 3px;\n min-width: 0;\n color: #475569;\n font-size: 13px;\n line-height: 1.4;\n}\n.canvas-react-form-horizontal > .canvas-react-form-item > .canvas-react-form-label {\n min-height: 32px;\n}\n.canvas-react-form-required {\n color: #dc2626;\n}\n.canvas-react-form-control {\n display: flex;\n flex-direction: column;\n min-width: 0;\n}\n.canvas-react-form-error {\n color: #dc2626;\n font-size: 12px;\n}\n.canvas-react-form-help,\n.canvas-react-form-extra {\n color: #64748b;\n font-size: 12px;\n}\n.canvas-react-form-item-error .canvas-react-form-control > input,\n.canvas-react-form-item-error .canvas-react-form-control > textarea {\n border-color: #dc2626;\n}\n");
|
|
1502
|
+
function createFormInstance() {
|
|
1503
|
+
const store = {
|
|
1504
|
+
values: {},
|
|
1505
|
+
initialValues: {},
|
|
1506
|
+
errors: {},
|
|
1507
|
+
rules: /* @__PURE__ */ new Map(),
|
|
1508
|
+
listeners: /* @__PURE__ */ new Set(),
|
|
1509
|
+
revision: 0,
|
|
1510
|
+
notify() {
|
|
1511
|
+
store.revision += 1;
|
|
1512
|
+
store.listeners.forEach((listener) => listener());
|
|
1513
|
+
}
|
|
1514
|
+
};
|
|
1515
|
+
return {
|
|
1516
|
+
__store: store,
|
|
1517
|
+
getFieldValue: (name) => store.values[name],
|
|
1518
|
+
setFieldsValue(values) {
|
|
1519
|
+
store.values = { ...store.values, ...values };
|
|
1520
|
+
Object.keys(values).forEach((name) => {
|
|
1521
|
+
delete store.errors[name];
|
|
1522
|
+
});
|
|
1523
|
+
store.notify();
|
|
1524
|
+
},
|
|
1525
|
+
resetFields() {
|
|
1526
|
+
store.values = { ...store.initialValues };
|
|
1527
|
+
store.errors = {};
|
|
1528
|
+
store.notify();
|
|
1529
|
+
},
|
|
1530
|
+
async validateFields() {
|
|
1531
|
+
const errors = {};
|
|
1532
|
+
for (const [name, rules] of store.rules) {
|
|
1533
|
+
const value = store.values[name];
|
|
1534
|
+
for (const rawRule of rules) {
|
|
1535
|
+
const rule = typeof rawRule === "function" ? rawRule({ getFieldValue: (field) => store.values[field] }) : rawRule;
|
|
1536
|
+
if (rule.required && (value === void 0 || value === null || value === "")) {
|
|
1537
|
+
errors[name] = rule.message ?? "\u6B64\u9879\u4E3A\u5FC5\u586B\u9879";
|
|
1538
|
+
break;
|
|
1539
|
+
}
|
|
1540
|
+
if ((rule.type === "number" || rule.type === "integer") && typeof value === "number" && rule.min !== void 0 && value < rule.min) {
|
|
1541
|
+
errors[name] = rule.message ?? `\u4E0D\u80FD\u5C0F\u4E8E ${rule.min}`;
|
|
1542
|
+
break;
|
|
1543
|
+
}
|
|
1544
|
+
if ((rule.type === "number" || rule.type === "integer") && typeof value === "number" && rule.max !== void 0 && value > rule.max) {
|
|
1545
|
+
errors[name] = rule.message ?? `\u4E0D\u80FD\u5927\u4E8E ${rule.max}`;
|
|
1546
|
+
break;
|
|
1547
|
+
}
|
|
1548
|
+
if (rule.type === "integer" && typeof value === "number" && !Number.isInteger(value)) {
|
|
1549
|
+
errors[name] = rule.message ?? "\u8BF7\u8F93\u5165\u6574\u6570";
|
|
1550
|
+
break;
|
|
1551
|
+
}
|
|
1552
|
+
if (rule.validator) {
|
|
1553
|
+
try {
|
|
1554
|
+
await rule.validator(rule, value);
|
|
1555
|
+
} catch (error) {
|
|
1556
|
+
errors[name] = error instanceof Error ? error.message : "\u6821\u9A8C\u5931\u8D25";
|
|
1557
|
+
break;
|
|
1558
|
+
}
|
|
1559
|
+
}
|
|
1560
|
+
}
|
|
1561
|
+
}
|
|
1562
|
+
store.errors = errors;
|
|
1563
|
+
store.notify();
|
|
1564
|
+
if (Object.keys(errors).length > 0) {
|
|
1565
|
+
return Promise.reject({
|
|
1566
|
+
errorFields: errors,
|
|
1567
|
+
values: { ...store.values }
|
|
1568
|
+
});
|
|
1569
|
+
}
|
|
1570
|
+
return { ...store.values };
|
|
1571
|
+
}
|
|
1572
|
+
};
|
|
1573
|
+
}
|
|
1574
|
+
function useReactForm() {
|
|
1575
|
+
const formRef = useRef(null);
|
|
1576
|
+
if (!formRef.current) formRef.current = createFormInstance();
|
|
1577
|
+
return [formRef.current];
|
|
1578
|
+
}
|
|
1579
|
+
function useReactFormWatch(name, form) {
|
|
1580
|
+
useSyncExternalStore(
|
|
1581
|
+
(listener) => {
|
|
1582
|
+
form.__store.listeners.add(listener);
|
|
1583
|
+
return () => form.__store.listeners.delete(listener);
|
|
1584
|
+
},
|
|
1585
|
+
() => form.__store.revision,
|
|
1586
|
+
() => 0
|
|
1587
|
+
);
|
|
1588
|
+
return form.getFieldValue(name);
|
|
1589
|
+
}
|
|
1590
|
+
var FormContext = createContext(null);
|
|
1591
|
+
var emptySubscribe = () => () => {
|
|
1592
|
+
};
|
|
1593
|
+
var emptySnapshot = () => 0;
|
|
1594
|
+
function ReactFormRoot({
|
|
1595
|
+
form: formProp,
|
|
1596
|
+
initialValues,
|
|
1597
|
+
layout = "vertical",
|
|
1598
|
+
noWrap = false,
|
|
1599
|
+
itemSpacing,
|
|
1600
|
+
labelWidth,
|
|
1601
|
+
labelAlign = "right",
|
|
1602
|
+
colon = false,
|
|
1603
|
+
requiredMark = true,
|
|
1604
|
+
className,
|
|
1605
|
+
children,
|
|
1606
|
+
...props
|
|
1607
|
+
}) {
|
|
1608
|
+
const internalForm = useRef(null);
|
|
1609
|
+
if (!internalForm.current) internalForm.current = createFormInstance();
|
|
1610
|
+
const form = formProp ?? internalForm.current;
|
|
1611
|
+
const initialKey = useMemo(
|
|
1612
|
+
() => JSON.stringify(initialValues ?? {}),
|
|
1613
|
+
[initialValues]
|
|
1614
|
+
);
|
|
1615
|
+
useEffect(() => {
|
|
1616
|
+
form.__store.initialValues = { ...initialValues };
|
|
1617
|
+
form.__store.values = { ...initialValues, ...form.__store.values };
|
|
1618
|
+
form.__store.notify();
|
|
1619
|
+
}, [form, initialKey]);
|
|
1620
|
+
const contextValue = useMemo(
|
|
1621
|
+
() => ({
|
|
1622
|
+
form,
|
|
1623
|
+
layout,
|
|
1624
|
+
noWrap,
|
|
1625
|
+
labelWidth,
|
|
1626
|
+
labelAlign,
|
|
1627
|
+
colon,
|
|
1628
|
+
requiredMark
|
|
1629
|
+
}),
|
|
1630
|
+
[colon, form, labelAlign, labelWidth, layout, noWrap, requiredMark]
|
|
1631
|
+
);
|
|
1632
|
+
return /* @__PURE__ */ jsx(FormContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsx(
|
|
1633
|
+
"form",
|
|
1634
|
+
{
|
|
1635
|
+
...props,
|
|
1636
|
+
style: itemSpacing === void 0 ? props.style : {
|
|
1637
|
+
...props.style,
|
|
1638
|
+
"--canvas-react-form-item-spacing": itemSpacing
|
|
1639
|
+
},
|
|
1640
|
+
className: joinClassNames(
|
|
1641
|
+
`${REACT_COMPONENT_PREFIX}-form`,
|
|
1642
|
+
`${REACT_COMPONENT_PREFIX}-form-${layout}`,
|
|
1643
|
+
className
|
|
1644
|
+
),
|
|
1645
|
+
onSubmit: (event) => event.preventDefault(),
|
|
1646
|
+
children
|
|
1647
|
+
}
|
|
1648
|
+
) });
|
|
1649
|
+
}
|
|
1650
|
+
function ReactFormItem({
|
|
1651
|
+
label,
|
|
1652
|
+
name,
|
|
1653
|
+
children,
|
|
1654
|
+
rules = [],
|
|
1655
|
+
initialValue,
|
|
1656
|
+
required,
|
|
1657
|
+
colon,
|
|
1658
|
+
labelWidth,
|
|
1659
|
+
labelAlign,
|
|
1660
|
+
labelStyle,
|
|
1661
|
+
controlStyle,
|
|
1662
|
+
help,
|
|
1663
|
+
extra,
|
|
1664
|
+
className,
|
|
1665
|
+
style,
|
|
1666
|
+
noWrap
|
|
1667
|
+
}) {
|
|
1668
|
+
const context = useContext(FormContext);
|
|
1669
|
+
const form = context?.form ?? null;
|
|
1670
|
+
if (name && !form) throw new Error("ReactForm.Item \u5FC5\u987B\u5728 ReactForm \u5185\u4F7F\u7528");
|
|
1671
|
+
useSyncExternalStore(
|
|
1672
|
+
form ? (listener) => {
|
|
1673
|
+
form.__store.listeners.add(listener);
|
|
1674
|
+
return () => form.__store.listeners.delete(listener);
|
|
1675
|
+
} : emptySubscribe,
|
|
1676
|
+
form ? () => form.__store.revision : emptySnapshot,
|
|
1677
|
+
emptySnapshot
|
|
1678
|
+
);
|
|
1679
|
+
useEffect(() => {
|
|
1680
|
+
if (!form || !name) return;
|
|
1681
|
+
form.__store.rules.set(name, rules);
|
|
1682
|
+
if (form.getFieldValue(name) === void 0 && initialValue !== void 0) {
|
|
1683
|
+
form.setFieldsValue({ [name]: initialValue });
|
|
1684
|
+
}
|
|
1685
|
+
return () => {
|
|
1686
|
+
form.__store.rules.delete(name);
|
|
1687
|
+
};
|
|
1688
|
+
}, [form, initialValue, name, rules]);
|
|
1689
|
+
const childProps = isValidElement(children) ? children.props : {};
|
|
1690
|
+
const value = form && name ? form.getFieldValue(name) : void 0;
|
|
1691
|
+
const child = form && name && isValidElement(children) ? cloneElement(children, {
|
|
1692
|
+
value: value ?? "",
|
|
1693
|
+
onChange: (...args) => {
|
|
1694
|
+
const first = args[0];
|
|
1695
|
+
const nextValue = typeof first === "object" && first !== null && "target" in first ? first.target?.value : first;
|
|
1696
|
+
form.setFieldsValue({ [name]: nextValue });
|
|
1697
|
+
const childOnChange = childProps.onChange;
|
|
1698
|
+
if (typeof childOnChange === "function") childOnChange(...args);
|
|
1699
|
+
}
|
|
1700
|
+
}) : children;
|
|
1701
|
+
const error = form && name ? form.__store.errors[name] : void 0;
|
|
1702
|
+
const isRequired = required ?? rules.some((rule) => typeof rule !== "function" && rule.required === true);
|
|
1703
|
+
const resolvedLabelWidth = labelWidth ?? context?.labelWidth;
|
|
1704
|
+
const resolvedLabelAlign = labelAlign ?? context?.labelAlign ?? "right";
|
|
1705
|
+
const showColon = colon ?? context?.colon ?? false;
|
|
1706
|
+
const shouldMarkRequired = context?.requiredMark ?? true;
|
|
1707
|
+
const resolvedLayout = context?.layout ?? "vertical";
|
|
1708
|
+
const resolvedNoWrap = noWrap ?? context?.noWrap ?? false;
|
|
1709
|
+
const labelElementId = typeof childProps.id === "string" ? childProps.id : void 0;
|
|
1710
|
+
return /* @__PURE__ */ jsxs(
|
|
1711
|
+
"div",
|
|
1712
|
+
{
|
|
1713
|
+
className: joinClassNames(
|
|
1714
|
+
`${REACT_COMPONENT_PREFIX}-form-item`,
|
|
1715
|
+
`${REACT_COMPONENT_PREFIX}-form-item-${resolvedLayout}`,
|
|
1716
|
+
resolvedNoWrap && `${REACT_COMPONENT_PREFIX}-form-item-no-wrap`,
|
|
1717
|
+
className,
|
|
1718
|
+
error && `${REACT_COMPONENT_PREFIX}-form-item-error`
|
|
1719
|
+
),
|
|
1720
|
+
style,
|
|
1721
|
+
children: [
|
|
1722
|
+
label ? /* @__PURE__ */ jsxs(
|
|
1723
|
+
"label",
|
|
1724
|
+
{
|
|
1725
|
+
className: `${REACT_COMPONENT_PREFIX}-form-label`,
|
|
1726
|
+
htmlFor: labelElementId,
|
|
1727
|
+
style: {
|
|
1728
|
+
width: resolvedLabelWidth,
|
|
1729
|
+
flexBasis: resolvedLabelWidth,
|
|
1730
|
+
textAlign: resolvedLabelAlign,
|
|
1731
|
+
...labelStyle
|
|
1732
|
+
},
|
|
1733
|
+
children: [
|
|
1734
|
+
shouldMarkRequired && isRequired ? /* @__PURE__ */ jsx(
|
|
1735
|
+
"span",
|
|
1736
|
+
{
|
|
1737
|
+
"aria-hidden": "true",
|
|
1738
|
+
className: `${REACT_COMPONENT_PREFIX}-form-required`,
|
|
1739
|
+
children: "*"
|
|
1740
|
+
}
|
|
1741
|
+
) : null,
|
|
1742
|
+
/* @__PURE__ */ jsx("span", { children: label }),
|
|
1743
|
+
showColon ? /* @__PURE__ */ jsx("span", { "aria-hidden": "true", children: ":" }) : null
|
|
1744
|
+
]
|
|
1745
|
+
}
|
|
1746
|
+
) : null,
|
|
1747
|
+
/* @__PURE__ */ jsxs(
|
|
1748
|
+
"div",
|
|
1749
|
+
{
|
|
1750
|
+
className: `${REACT_COMPONENT_PREFIX}-form-control`,
|
|
1751
|
+
style: controlStyle,
|
|
1752
|
+
children: [
|
|
1753
|
+
child,
|
|
1754
|
+
error ? /* @__PURE__ */ jsx("span", { className: `${REACT_COMPONENT_PREFIX}-form-error`, children: error }) : help ? /* @__PURE__ */ jsx("span", { className: `${REACT_COMPONENT_PREFIX}-form-help`, children: help }) : null,
|
|
1755
|
+
extra ? /* @__PURE__ */ jsx("span", { className: `${REACT_COMPONENT_PREFIX}-form-extra`, children: extra }) : null
|
|
1756
|
+
]
|
|
1757
|
+
}
|
|
1758
|
+
)
|
|
1759
|
+
]
|
|
1760
|
+
}
|
|
1761
|
+
);
|
|
1762
|
+
}
|
|
1763
|
+
var ReactForm = Object.assign(ReactFormRoot, {
|
|
1764
|
+
Item: ReactFormItem,
|
|
1765
|
+
useForm: useReactForm,
|
|
1766
|
+
useWatch: useReactFormWatch
|
|
1767
|
+
});
|
|
1768
|
+
|
|
1500
1769
|
// src/components/color/style.css
|
|
1501
1770
|
styleInject(".canvas-react-color-wrap {\n display: inline-flex;\n width: 100%;\n height: 100%;\n min-height: 0;\n box-sizing: border-box;\n}\n.canvas-react-color {\n display: flex;\n align-items: center;\n width: 100%;\n min-width: 0;\n height: var(--canvas-react-control-height);\n min-height: 0;\n box-sizing: border-box;\n border: 1px solid var(--canvas-react-color-border);\n border-radius: var(--canvas-react-radius-sm);\n background: var(--canvas-react-color-bg);\n color: var(--canvas-react-color-text);\n font-size: var(--canvas-react-font-size);\n transition: border-color 0.2s ease, box-shadow 0.2s ease;\n cursor: pointer;\n}\n.canvas-react-color:hover {\n border-color: var(--canvas-react-color-primary-hover);\n}\n.canvas-react-color-open,\n.canvas-react-color:focus-within {\n border-color: var(--canvas-react-color-primary);\n box-shadow: var(--canvas-react-shadow-focus);\n}\n.canvas-react-color-disabled {\n color: #9ca3af;\n background: var(--canvas-react-color-bg-soft);\n cursor: not-allowed;\n}\n.canvas-react-color-preview {\n flex: 0 0 auto;\n width: calc(24px * var(--canvas-react-content-zoom, 1));\n height: calc(24px * var(--canvas-react-content-zoom, 1));\n margin-left: 3px;\n box-sizing: border-box;\n border: 1px solid rgba(0, 0, 0, 0.12);\n border-radius: 4px;\n}\n.canvas-react-color-input-wrap {\n flex: 1;\n min-width: 0;\n height: 100%;\n min-height: 0;\n border: 0;\n box-shadow: none;\n}\n.canvas-react-color .canvas-react-input-affix-wrapper {\n height: 100%;\n min-height: 0;\n}\n.canvas-react-color-input-wrap:hover,\n.canvas-react-color-input-wrap:focus-within {\n border-color: transparent;\n box-shadow: none;\n}\n.canvas-react-color-input {\n cursor: pointer;\n text-transform: uppercase;\n}\n.canvas-react-color-arrow {\n flex: 0 0 auto;\n width: 0.5em;\n height: 0.5em;\n min-width: 6px;\n min-height: 6px;\n margin-right: var(--canvas-react-control-padding-inline, 11px);\n border-right: 1.5px solid var(--canvas-react-color-text-muted);\n border-bottom: 1.5px solid var(--canvas-react-color-text-muted);\n transform: rotate(45deg) translateY(-2px);\n transition: transform 0.18s ease;\n}\n.canvas-react-color-arrow-open {\n transform: rotate(225deg) translate(-1px, -1px);\n}\n.canvas-react-color-dropdown {\n overflow: hidden;\n}\n.canvas-react-color-panel {\n padding: 12px;\n box-sizing: border-box;\n}\n.canvas-react-color-saturation {\n position: relative;\n height: 150px;\n overflow: hidden;\n border-radius: 6px;\n cursor: crosshair;\n background-image:\n linear-gradient(\n to top,\n #000,\n transparent),\n linear-gradient(\n to right,\n #fff,\n transparent);\n touch-action: none;\n}\n.canvas-react-color-saturation-thumb {\n position: absolute;\n width: 12px;\n height: 12px;\n border: 2px solid #fff;\n border-radius: 50%;\n box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.28), 0 1px 3px rgba(0, 0, 0, 0.28);\n transform: translate(-50%, -50%);\n pointer-events: none;\n}\n.canvas-react-color-controls {\n display: flex;\n align-items: center;\n gap: 10px;\n margin-top: 12px;\n}\n.canvas-react-color-current {\n flex: 0 0 28px;\n height: 28px;\n box-sizing: border-box;\n border: 1px solid rgba(0, 0, 0, 0.12);\n border-radius: 50%;\n}\n.canvas-react-color-hue {\n width: 100%;\n height: 12px;\n margin: 0;\n appearance: none;\n border-radius: 999px;\n background:\n linear-gradient(\n to right,\n #f00,\n #ff0,\n #0f0,\n #0ff,\n #00f,\n #f0f,\n #f00);\n cursor: pointer;\n}\n.canvas-react-color-hue::-webkit-slider-thumb {\n width: 14px;\n height: 14px;\n appearance: none;\n border: 2px solid #fff;\n border-radius: 50%;\n background: transparent;\n box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.28);\n}\n.canvas-react-color-value-row {\n display: grid;\n grid-template-columns: 36px 1fr;\n align-items: center;\n gap: 8px;\n margin-top: 12px;\n color: var(--canvas-react-color-text-muted);\n font-size: 12px;\n}\n.canvas-react-color-value-row .canvas-react-input-affix-wrapper {\n height: 28px;\n}\n.canvas-react-color-presets {\n display: grid;\n grid-template-columns: repeat(8, 20px);\n gap: 7px;\n margin-top: 12px;\n}\n.canvas-react-color-preset {\n width: 20px;\n height: 20px;\n padding: 0;\n box-sizing: border-box;\n border: 1px solid rgba(0, 0, 0, 0.12);\n border-radius: 4px;\n cursor: pointer;\n transition: transform 0.16s ease, box-shadow 0.16s ease;\n}\n.canvas-react-color-preset:hover {\n transform: scale(1.12);\n}\n.canvas-react-color-preset-selected {\n box-shadow: 0 0 0 2px #fff, 0 0 0 3px var(--canvas-react-color-primary);\n}\n");
|
|
1502
1771
|
var DEFAULT_COLOR = "#1677ff";
|
|
@@ -5893,7 +6162,7 @@ function isPromiseLike(value) {
|
|
|
5893
6162
|
}
|
|
5894
6163
|
|
|
5895
6164
|
// src/components/compat/style.css
|
|
5896
|
-
styleInject(".canvas-react-button {\n display: inline-flex;\n align-items: center;\n justify-content: center;\n gap: 6px;\n min-height: 32px;\n padding: 4px 14px;\n border: 1px solid var(--cc-border-color, #d9d9d9);\n border-radius: 6px;\n color: var(--cc-text-color, #1f2937);\n background: var(--cc-surface-color, #fff);\n cursor: pointer;\n}\n.canvas-react-button:hover:not(:disabled) {\n color: #1677ff;\n border-color: #1677ff;\n}\n.canvas-react-button:disabled {\n cursor: not-allowed;\n opacity: 0.5;\n}\n.canvas-react-button-primary {\n color: #fff;\n border-color: #1677ff;\n background: #1677ff;\n}\n.canvas-react-button-danger {\n color: #dc2626;\n border-color: #fca5a5;\n}\n.canvas-react-button-small {\n min-height: 24px;\n padding: 2px 8px;\n}\n.canvas-react-button-large {\n min-height: 40px;\n padding: 6px 18px;\n}\n.canvas-react-button-icon {\n display: inline-flex;\n}\n.canvas-react-row {\n display: flex;\n flex-flow: row wrap;\n}\n.canvas-react-col {\n min-width: 0;\n padding-inline: 8px;\n}\n.canvas-react-radio-group {\n display: flex;\n gap: 16px;\n}\n.canvas-react-radio {\n display: inline-flex;\n align-items: center;\n gap: 6px;\n cursor: pointer;\n}\n.canvas-react-radio input {\n position: absolute;\n opacity: 0;\n pointer-events: none;\n}\n.canvas-react-radio-mark {\n width: 14px;\n height: 14px;\n border: 1px solid #94a3b8;\n border-radius: 50%;\n box-sizing: border-box;\n}\n.canvas-react-radio input:checked + .canvas-react-radio-mark {\n border: 4px solid #1677ff;\n}\n.canvas-react-form-item {\n display: flex;\n flex-direction: column;\n gap: 6px;\n margin-bottom: 16px;\n}\n.canvas-react-form-label {\n color: #334155;\n font-size: 14px;\n}\n.canvas-react-form-error {\n color: #dc2626;\n font-size: 12px;\n}\n.canvas-react-textarea {\n width: 100%;\n min-height: 72px;\n padding: 8px 10px;\n border: 1px solid #d9d9d9;\n border-radius: 6px;\n box-sizing: border-box;\n font: inherit;\n resize: vertical;\n}\n.canvas-react-message-host {\n position: fixed;\n z-index: 3000;\n top: 24px;\n left: 50%;\n display: flex;\n flex-direction: column;\n gap: 8px;\n transform: translateX(-50%);\n pointer-events: none;\n}\n.canvas-react-message {\n padding: 9px 14px;\n border: 1px solid #e2e8f0;\n border-radius: 8px;\n color: #334155;\n background: #fff;\n box-shadow: 0 8px 24px rgba(15, 23, 42, 0.14);\n}\n.canvas-react-message-error {\n color: #b91c1c;\n border-color: #fecaca;\n}\n");
|
|
6165
|
+
styleInject(".canvas-react-button {\n display: inline-flex;\n align-items: center;\n justify-content: center;\n gap: 6px;\n min-height: 32px;\n padding: 4px 14px;\n border: 1px solid var(--cc-border-color, #d9d9d9);\n border-radius: 6px;\n color: var(--cc-text-color, #1f2937);\n background: var(--cc-surface-color, #fff);\n cursor: pointer;\n}\n.canvas-react-button:hover:not(:disabled) {\n color: #1677ff;\n border-color: #1677ff;\n}\n.canvas-react-button:disabled {\n cursor: not-allowed;\n opacity: 0.5;\n}\n.canvas-react-button-primary {\n color: #fff;\n border-color: #1677ff;\n background: #1677ff;\n}\n.canvas-react-button-primary:hover:not(:disabled) {\n color: #fff;\n border-color: #4096ff;\n background: #4096ff;\n}\n.canvas-react-button-danger {\n color: #dc2626;\n border-color: #fca5a5;\n}\n.canvas-react-button-small {\n min-height: 24px;\n padding: 2px 8px;\n}\n.canvas-react-button-large {\n min-height: 40px;\n padding: 6px 18px;\n}\n.canvas-react-button-icon {\n display: inline-flex;\n}\n.canvas-react-row {\n display: flex;\n flex-flow: row wrap;\n}\n.canvas-react-col {\n min-width: 0;\n padding-inline: 8px;\n}\n.canvas-react-radio-group {\n display: flex;\n gap: 16px;\n}\n.canvas-react-radio {\n display: inline-flex;\n align-items: center;\n gap: 6px;\n cursor: pointer;\n}\n.canvas-react-radio input {\n position: absolute;\n opacity: 0;\n pointer-events: none;\n}\n.canvas-react-radio-mark {\n width: 14px;\n height: 14px;\n border: 1px solid #94a3b8;\n border-radius: 50%;\n box-sizing: border-box;\n}\n.canvas-react-radio input:checked + .canvas-react-radio-mark {\n border: 4px solid #1677ff;\n}\n.canvas-react-form-item {\n display: flex;\n flex-direction: column;\n gap: 6px;\n margin-bottom: 16px;\n}\n.canvas-react-form-label {\n color: #334155;\n font-size: 14px;\n}\n.canvas-react-form-error {\n color: #dc2626;\n font-size: 12px;\n}\n.canvas-react-textarea {\n width: 100%;\n min-height: 72px;\n padding: 8px 10px;\n border: 1px solid #d9d9d9;\n border-radius: 6px;\n box-sizing: border-box;\n font: inherit;\n resize: vertical;\n}\n.canvas-react-message-host {\n position: fixed;\n z-index: 3000;\n top: 24px;\n left: 50%;\n display: flex;\n flex-direction: column;\n gap: 8px;\n transform: translateX(-50%);\n pointer-events: none;\n}\n.canvas-react-message {\n padding: 9px 14px;\n border: 1px solid #e2e8f0;\n border-radius: 8px;\n color: #334155;\n background: #fff;\n box-shadow: 0 8px 24px rgba(15, 23, 42, 0.14);\n}\n.canvas-react-message-error {\n color: #b91c1c;\n border-color: #fecaca;\n}\n");
|
|
5897
6166
|
function ReactButton({
|
|
5898
6167
|
children,
|
|
5899
6168
|
className,
|
|
@@ -6055,173 +6324,6 @@ function ReactTextArea({ className, ...props }) {
|
|
|
6055
6324
|
}
|
|
6056
6325
|
);
|
|
6057
6326
|
}
|
|
6058
|
-
function createFormInstance() {
|
|
6059
|
-
const store = {
|
|
6060
|
-
values: {},
|
|
6061
|
-
initialValues: {},
|
|
6062
|
-
errors: {},
|
|
6063
|
-
rules: /* @__PURE__ */ new Map(),
|
|
6064
|
-
listeners: /* @__PURE__ */ new Set(),
|
|
6065
|
-
revision: 0,
|
|
6066
|
-
notify() {
|
|
6067
|
-
store.revision += 1;
|
|
6068
|
-
store.listeners.forEach((listener) => listener());
|
|
6069
|
-
}
|
|
6070
|
-
};
|
|
6071
|
-
return {
|
|
6072
|
-
__store: store,
|
|
6073
|
-
getFieldValue: (name) => store.values[name],
|
|
6074
|
-
setFieldsValue(values) {
|
|
6075
|
-
store.values = { ...store.values, ...values };
|
|
6076
|
-
Object.keys(values).forEach((name) => {
|
|
6077
|
-
delete store.errors[name];
|
|
6078
|
-
});
|
|
6079
|
-
store.notify();
|
|
6080
|
-
},
|
|
6081
|
-
resetFields() {
|
|
6082
|
-
store.values = { ...store.initialValues };
|
|
6083
|
-
store.errors = {};
|
|
6084
|
-
store.notify();
|
|
6085
|
-
},
|
|
6086
|
-
async validateFields() {
|
|
6087
|
-
const errors = {};
|
|
6088
|
-
for (const [name, rules] of store.rules) {
|
|
6089
|
-
const value = store.values[name];
|
|
6090
|
-
for (const rawRule of rules) {
|
|
6091
|
-
const rule = typeof rawRule === "function" ? rawRule({ getFieldValue: (field) => store.values[field] }) : rawRule;
|
|
6092
|
-
if (rule.required && (value === void 0 || value === null || value === "")) {
|
|
6093
|
-
errors[name] = rule.message ?? "\u6B64\u9879\u4E3A\u5FC5\u586B\u9879";
|
|
6094
|
-
break;
|
|
6095
|
-
}
|
|
6096
|
-
if ((rule.type === "number" || rule.type === "integer") && typeof value === "number" && rule.min !== void 0 && value < rule.min) {
|
|
6097
|
-
errors[name] = rule.message ?? `\u4E0D\u80FD\u5C0F\u4E8E ${rule.min}`;
|
|
6098
|
-
break;
|
|
6099
|
-
}
|
|
6100
|
-
if ((rule.type === "number" || rule.type === "integer") && typeof value === "number" && rule.max !== void 0 && value > rule.max) {
|
|
6101
|
-
errors[name] = rule.message ?? `\u4E0D\u80FD\u5927\u4E8E ${rule.max}`;
|
|
6102
|
-
break;
|
|
6103
|
-
}
|
|
6104
|
-
if (rule.type === "integer" && typeof value === "number" && !Number.isInteger(value)) {
|
|
6105
|
-
errors[name] = rule.message ?? "\u8BF7\u8F93\u5165\u6574\u6570";
|
|
6106
|
-
break;
|
|
6107
|
-
}
|
|
6108
|
-
if (rule.validator) {
|
|
6109
|
-
try {
|
|
6110
|
-
await rule.validator(rule, value);
|
|
6111
|
-
} catch (error) {
|
|
6112
|
-
errors[name] = error instanceof Error ? error.message : "\u6821\u9A8C\u5931\u8D25";
|
|
6113
|
-
break;
|
|
6114
|
-
}
|
|
6115
|
-
}
|
|
6116
|
-
}
|
|
6117
|
-
}
|
|
6118
|
-
store.errors = errors;
|
|
6119
|
-
store.notify();
|
|
6120
|
-
if (Object.keys(errors).length > 0) {
|
|
6121
|
-
return Promise.reject({
|
|
6122
|
-
errorFields: errors,
|
|
6123
|
-
values: { ...store.values }
|
|
6124
|
-
});
|
|
6125
|
-
}
|
|
6126
|
-
return { ...store.values };
|
|
6127
|
-
}
|
|
6128
|
-
};
|
|
6129
|
-
}
|
|
6130
|
-
function useReactForm() {
|
|
6131
|
-
const formRef = useRef();
|
|
6132
|
-
if (!formRef.current) formRef.current = createFormInstance();
|
|
6133
|
-
return [formRef.current];
|
|
6134
|
-
}
|
|
6135
|
-
function useReactFormWatch(name, form) {
|
|
6136
|
-
return useSyncExternalStore(
|
|
6137
|
-
(listener) => {
|
|
6138
|
-
form.__store.listeners.add(listener);
|
|
6139
|
-
return () => form.__store.listeners.delete(listener);
|
|
6140
|
-
},
|
|
6141
|
-
() => form.__store.revision,
|
|
6142
|
-
() => 0
|
|
6143
|
-
) >= 0 ? form.getFieldValue(name) : void 0;
|
|
6144
|
-
}
|
|
6145
|
-
var FormContext = createContext(null);
|
|
6146
|
-
function ReactFormRoot({
|
|
6147
|
-
form,
|
|
6148
|
-
initialValues,
|
|
6149
|
-
layout = "vertical",
|
|
6150
|
-
className,
|
|
6151
|
-
children,
|
|
6152
|
-
...props
|
|
6153
|
-
}) {
|
|
6154
|
-
const initialKey = useMemo(
|
|
6155
|
-
() => JSON.stringify(initialValues ?? {}),
|
|
6156
|
-
[initialValues]
|
|
6157
|
-
);
|
|
6158
|
-
useEffect(() => {
|
|
6159
|
-
form.__store.initialValues = { ...initialValues };
|
|
6160
|
-
form.__store.values = { ...initialValues, ...form.__store.values };
|
|
6161
|
-
form.__store.notify();
|
|
6162
|
-
}, [form, initialKey]);
|
|
6163
|
-
return /* @__PURE__ */ jsx(FormContext.Provider, { value: form, children: /* @__PURE__ */ jsx(
|
|
6164
|
-
"form",
|
|
6165
|
-
{
|
|
6166
|
-
...props,
|
|
6167
|
-
className: joinClassNames(
|
|
6168
|
-
`${REACT_COMPONENT_PREFIX}-form`,
|
|
6169
|
-
`${REACT_COMPONENT_PREFIX}-form-${layout}`,
|
|
6170
|
-
className
|
|
6171
|
-
),
|
|
6172
|
-
onSubmit: (event) => event.preventDefault(),
|
|
6173
|
-
children
|
|
6174
|
-
}
|
|
6175
|
-
) });
|
|
6176
|
-
}
|
|
6177
|
-
function ReactFormItem({
|
|
6178
|
-
label,
|
|
6179
|
-
name,
|
|
6180
|
-
children,
|
|
6181
|
-
rules = [],
|
|
6182
|
-
initialValue
|
|
6183
|
-
}) {
|
|
6184
|
-
const form = useContext(FormContext);
|
|
6185
|
-
if (!form) throw new Error("ReactForm.Item \u5FC5\u987B\u5728 ReactForm \u5185\u4F7F\u7528");
|
|
6186
|
-
useSyncExternalStore(
|
|
6187
|
-
(listener) => {
|
|
6188
|
-
form.__store.listeners.add(listener);
|
|
6189
|
-
return () => form.__store.listeners.delete(listener);
|
|
6190
|
-
},
|
|
6191
|
-
() => form.__store.revision,
|
|
6192
|
-
() => 0
|
|
6193
|
-
);
|
|
6194
|
-
useEffect(() => {
|
|
6195
|
-
form.__store.rules.set(name, rules);
|
|
6196
|
-
if (form.getFieldValue(name) === void 0 && initialValue !== void 0) {
|
|
6197
|
-
form.setFieldsValue({ [name]: initialValue });
|
|
6198
|
-
}
|
|
6199
|
-
return () => {
|
|
6200
|
-
form.__store.rules.delete(name);
|
|
6201
|
-
};
|
|
6202
|
-
}, [form, initialValue, name, rules]);
|
|
6203
|
-
const childProps = children.props;
|
|
6204
|
-
const value = form.getFieldValue(name);
|
|
6205
|
-
return /* @__PURE__ */ jsxs("label", { className: `${REACT_COMPONENT_PREFIX}-form-item`, children: [
|
|
6206
|
-
label ? /* @__PURE__ */ jsx("span", { className: `${REACT_COMPONENT_PREFIX}-form-label`, children: label }) : null,
|
|
6207
|
-
cloneElement(children, {
|
|
6208
|
-
value: value ?? "",
|
|
6209
|
-
onChange: (...args) => {
|
|
6210
|
-
const first = args[0];
|
|
6211
|
-
const nextValue = typeof first === "object" && first !== null && "target" in first ? first.target?.value : first;
|
|
6212
|
-
form.setFieldsValue({ [name]: nextValue });
|
|
6213
|
-
const childOnChange = childProps.onChange;
|
|
6214
|
-
if (typeof childOnChange === "function") childOnChange(...args);
|
|
6215
|
-
}
|
|
6216
|
-
}),
|
|
6217
|
-
form.__store.errors[name] ? /* @__PURE__ */ jsx("span", { className: `${REACT_COMPONENT_PREFIX}-form-error`, children: form.__store.errors[name] }) : null
|
|
6218
|
-
] });
|
|
6219
|
-
}
|
|
6220
|
-
var ReactForm = Object.assign(ReactFormRoot, {
|
|
6221
|
-
Item: ReactFormItem,
|
|
6222
|
-
useForm: useReactForm,
|
|
6223
|
-
useWatch: useReactFormWatch
|
|
6224
|
-
});
|
|
6225
6327
|
function showMessage(type, content) {
|
|
6226
6328
|
if (typeof document === "undefined") return;
|
|
6227
6329
|
const hostId = `${REACT_COMPONENT_PREFIX}-message-host`;
|
|
@@ -9805,4 +9907,4 @@ function resolveDecadeStart6(year) {
|
|
|
9805
9907
|
return Math.floor(year / 10) * 10;
|
|
9806
9908
|
}
|
|
9807
9909
|
|
|
9808
|
-
export { REACT_COMPONENT_PREFIX, ReactAutoComplete, ReactButton, ReactCascader, ReactCheckbox, ReactCol, ReactColorPicker, ReactContentScaleProvider, ReactDatePicker, ReactDateRangePicker, ReactDateTimePicker, ReactDateTimeRangePicker, ReactFilterPanel, ReactFlex, ReactForm, ReactImagePreview, ReactInput, ReactInputNumber, ReactInputRange, ReactModal, ReactMonthPicker, ReactNumberInput, ReactPagination, ReactPopconfirm, ReactPopup, ReactQuarterPicker, ReactRadio, ReactResizablePanels, ReactRow, ReactScrollbarPositionDialog, ReactScrollbarSettingsDialog, ReactSelect, ReactTextArea, ReactTimePicker, ReactTimeRangePicker, ReactTooltip, ReactTransition, ReactTreeSelect, ReactVirtualList, ReactYearPicker, getSharedScrollbarSettings, reactMessage, resolveReactScrollbarMode, resolveResizablePanelSizes, setSharedScrollbarSettings, subscribeSharedScrollbarSettings, useReactContentScale, useReactForm, useReactFormWatch, useReactTransition };
|
|
9910
|
+
export { REACT_COMPONENT_PREFIX, ReactAutoComplete, ReactButton, ReactCascader, ReactCheckbox, ReactCol, ReactColorPicker, ReactContentScaleProvider, ReactDatePicker, ReactDateRangePicker, ReactDateTimePicker, ReactDateTimeRangePicker, ReactFilterPanel, ReactFlex, ReactForm, ReactFormItem, ReactImagePreview, ReactInput, ReactInputNumber, ReactInputRange, ReactModal, ReactMonthPicker, ReactNumberInput, ReactPagination, ReactPopconfirm, ReactPopup, ReactQuarterPicker, ReactRadio, ReactResizablePanels, ReactRow, ReactScrollbarPositionDialog, ReactScrollbarSettingsDialog, ReactSelect, ReactTextArea, ReactTimePicker, ReactTimeRangePicker, ReactTooltip, ReactTransition, ReactTreeSelect, ReactVirtualList, ReactYearPicker, getSharedScrollbarSettings, reactMessage, resolveReactScrollbarMode, resolveResizablePanelSizes, setSharedScrollbarSettings, subscribeSharedScrollbarSettings, useReactContentScale, useReactForm, useReactFormWatch, useReactTransition };
|