@tiny-codes/react-easy 1.1.3 → 1.2.1

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.
Files changed (68) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/es/components/ConfirmAction/index.d.ts +97 -28
  3. package/es/components/ConfirmAction/index.js +47 -28
  4. package/es/components/ConfirmAction/index.js.map +1 -1
  5. package/es/components/ConfirmAction/withConfirmAction.d.ts +48 -0
  6. package/es/components/ConfirmAction/withConfirmAction.js +131 -0
  7. package/es/components/ConfirmAction/withConfirmAction.js.map +1 -0
  8. package/es/components/ContextMenu/index.d.ts +42 -0
  9. package/es/components/ContextMenu/index.js +188 -0
  10. package/es/components/ContextMenu/index.js.map +1 -0
  11. package/es/components/ContextMenu/style/index.d.ts +3 -0
  12. package/es/components/ContextMenu/style/index.js +25 -0
  13. package/es/components/ContextMenu/style/index.js.map +1 -0
  14. package/es/components/DeleteConfirmAction/index.d.ts +1 -1
  15. package/es/components/DeleteConfirmAction/index.js +9 -3
  16. package/es/components/DeleteConfirmAction/index.js.map +1 -1
  17. package/es/components/DeleteConfirmAction/withDeleteConfirmAction.d.ts +19 -0
  18. package/es/components/DeleteConfirmAction/withDeleteConfirmAction.js +20 -0
  19. package/es/components/DeleteConfirmAction/withDeleteConfirmAction.js.map +1 -0
  20. package/es/components/EditableText/form.d.ts +12 -6
  21. package/es/components/EditableText/form.js +106 -56
  22. package/es/components/EditableText/form.js.map +1 -1
  23. package/es/components/EditableText/index.d.ts +31 -9
  24. package/es/components/EditableText/index.js +13 -7
  25. package/es/components/EditableText/index.js.map +1 -1
  26. package/es/components/Loading/index.d.ts +2 -2
  27. package/es/components/Loading/index.js +5 -5
  28. package/es/components/Loading/index.js.map +1 -1
  29. package/es/components/ModalAction/index.d.ts +35 -29
  30. package/es/components/ModalAction/index.js +16 -9
  31. package/es/components/ModalAction/index.js.map +1 -1
  32. package/es/components/index.d.ts +5 -1
  33. package/es/components/index.js +3 -0
  34. package/es/components/index.js.map +1 -1
  35. package/lib/components/ConfirmAction/index.d.ts +97 -28
  36. package/lib/components/ConfirmAction/index.js +57 -32
  37. package/lib/components/ConfirmAction/index.js.map +2 -2
  38. package/lib/components/ConfirmAction/withConfirmAction.d.ts +48 -0
  39. package/lib/components/ConfirmAction/withConfirmAction.js +123 -0
  40. package/lib/components/ConfirmAction/withConfirmAction.js.map +7 -0
  41. package/lib/components/ContextMenu/index.d.ts +42 -0
  42. package/lib/components/ContextMenu/index.js +190 -0
  43. package/lib/components/ContextMenu/index.js.map +7 -0
  44. package/lib/components/ContextMenu/style/index.d.ts +3 -0
  45. package/lib/components/ContextMenu/style/index.js +48 -0
  46. package/lib/components/ContextMenu/style/index.js.map +7 -0
  47. package/lib/components/DeleteConfirmAction/index.d.ts +1 -1
  48. package/lib/components/DeleteConfirmAction/index.js +28 -16
  49. package/lib/components/DeleteConfirmAction/index.js.map +2 -2
  50. package/lib/components/DeleteConfirmAction/withDeleteConfirmAction.d.ts +19 -0
  51. package/lib/components/DeleteConfirmAction/withDeleteConfirmAction.js +38 -0
  52. package/lib/components/DeleteConfirmAction/withDeleteConfirmAction.js.map +7 -0
  53. package/lib/components/EditableText/form.d.ts +12 -6
  54. package/lib/components/EditableText/form.js +69 -39
  55. package/lib/components/EditableText/form.js.map +2 -2
  56. package/lib/components/EditableText/index.d.ts +31 -9
  57. package/lib/components/EditableText/index.js +12 -5
  58. package/lib/components/EditableText/index.js.map +2 -2
  59. package/lib/components/Loading/index.d.ts +2 -2
  60. package/lib/components/Loading/index.js +4 -4
  61. package/lib/components/Loading/index.js.map +2 -2
  62. package/lib/components/ModalAction/index.d.ts +35 -29
  63. package/lib/components/ModalAction/index.js +22 -17
  64. package/lib/components/ModalAction/index.js.map +2 -2
  65. package/lib/components/index.d.ts +5 -1
  66. package/lib/components/index.js +9 -0
  67. package/lib/components/index.js.map +2 -2
  68. package/package.json +3 -2
@@ -0,0 +1,48 @@
1
+ import type { ComponentType, PropsWithoutRef, ReactNode, RefAttributes } from 'react';
2
+ import type { ActionCompConstraint, ConfirmActionProps, ConfirmActionRef } from '.';
3
+ import { type ButtonProps, type SwitchProps } from 'antd';
4
+ import type { LinkProps } from 'antd/es/typography/Link';
5
+ /**
6
+ * - **EN:** Generate a confirm box component with custom trigger and default props
7
+ * - **CN:** 将一个组件包装成一个确认弹框组件,支持自定义触发器和默认属性
8
+ *
9
+ * @param actionComponent Custom trigger component | 自定义触发器组件
10
+ * @param defaultProps Default properties of the confirm box | 确认弹框的默认属性
11
+ */
12
+ export default function withConfirmAction<P extends ActionCompConstraint, OuterTriggerProp extends object, OuterEvent extends keyof OuterTriggerProp, Ref extends object>(ActionComponent: ActionComponentInterface<P, Ref>, defaultProps?: Partial<Omit<P, keyof ActionCompConstraint> & ConfirmActionProps<OuterTriggerProp, OuterEvent>> | ((actualProps: Omit<P, keyof ActionCompConstraint> & ConfirmActionProps<OuterTriggerProp, OuterEvent>) => Partial<Omit<P, keyof ActionCompConstraint> & ConfirmActionProps<OuterTriggerProp, OuterEvent>>)): WithGenericTriggers<P, Ref>;
13
+ export declare function withConfirmActionInternal<P extends ActionCompConstraint, OuterTriggerProp extends object, OuterEvent extends keyof OuterTriggerProp, Ref extends object>(ActionComponent: ActionComponentInterface<P, Ref>, renderDefaultProps: Partial<ConfirmActionProps<any, never>> & {
14
+ confirmType: 'normal' | 'delete';
15
+ }, defaultProps?: Partial<Omit<P, keyof ActionCompConstraint> & ConfirmActionProps<OuterTriggerProp, OuterEvent>> | ((actualProps: Omit<P, keyof ActionCompConstraint> & ConfirmActionProps<OuterTriggerProp, OuterEvent>) => Partial<Omit<P, keyof ActionCompConstraint> & ConfirmActionProps<OuterTriggerProp, OuterEvent>>)): WithGenericTriggers<P, Ref>;
16
+ /**
17
+ * - **EN:** ModalAction component type
18
+ * - **CN:** ModalAction组件的类型
19
+ */
20
+ export type ActionComponentInterface<P extends ActionCompConstraint, Ref extends object> = ComponentType<P & RefAttributes<ConfirmActionRef<Ref>>>;
21
+ type WithGenericTriggers<P extends ActionCompConstraint, Ref extends object> = (<TriggerProp extends object, Event extends keyof TriggerProp>(props: PropsWithoutRef<Omit<P, keyof ActionCompConstraint>> & ConfirmActionProps<TriggerProp, Event> & RefAttributes<ConfirmActionRef<Ref>>) => ReactNode) & TypedTriggers<P, Ref>;
22
+ /**
23
+ * - **EN:** Built-in trigger types (specified form components)
24
+ * - **CN:** 内置的几种触发器类型(已指定表单组件)
25
+ */
26
+ export interface TypedTriggers<P extends ActionCompConstraint, Ref extends object> {
27
+ /**
28
+ * - **EN:** Dialog with button type trigger
29
+ * - **CN:** 按钮类型的弹窗
30
+ */
31
+ Button: ConfirmActionWithTrigger<P, ButtonProps, 'onClick', Ref>;
32
+ /**
33
+ * - **EN:** Dialog with switch type trigger
34
+ * - **CN:** 开关类型的弹窗
35
+ */
36
+ Switch: ConfirmActionWithTrigger<P, SwitchProps, 'onChange', Ref>;
37
+ /**
38
+ * - **EN:** Dialog with link type trigger
39
+ * - **CN:** 链接类型的弹窗
40
+ */
41
+ Link: ConfirmActionWithTrigger<P, LinkProps, 'onClick', Ref>;
42
+ }
43
+ /**
44
+ * - **EN:** ModalAction with specified trigger type (specified form component)
45
+ * - **CN:** 已指定Trigger类型的ModalAction(并且已指定表单组件)
46
+ */
47
+ type ConfirmActionWithTrigger<P extends ActionCompConstraint, TriggerProp extends object, Event extends keyof TriggerProp, Ref extends object, OMIT extends string = never> = ComponentType<Omit<PropsWithoutRef<Omit<P, keyof ActionCompConstraint>> & ConfirmActionProps<TriggerProp, Event>, 'triggerComponent' | 'triggerEvent' | OMIT> & RefAttributes<ConfirmActionRef<Ref>>>;
48
+ export {};
@@ -0,0 +1,131 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
5
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
6
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
7
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
8
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
9
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
10
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
11
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
12
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
13
+ import { forwardRef, useCallback, useImperativeHandle, useRef, useState } from 'react';
14
+ import { genRenderer, withDefaultConfirmActionProps } from '.';
15
+ import { Button, Switch, Typography } from 'antd';
16
+ import { isForwardRef } from 'react-is';
17
+
18
+ /**
19
+ * - **EN:** Generate a confirm box component with custom trigger and default props
20
+ * - **CN:** 将一个组件包装成一个确认弹框组件,支持自定义触发器和默认属性
21
+ *
22
+ * @param actionComponent Custom trigger component | 自定义触发器组件
23
+ * @param defaultProps Default properties of the confirm box | 确认弹框的默认属性
24
+ */
25
+ import { jsx as _jsx } from "react/jsx-runtime";
26
+ export default function withConfirmAction(ActionComponent, defaultProps) {
27
+ return withConfirmActionInternal(ActionComponent, {
28
+ confirmType: 'normal'
29
+ }, defaultProps);
30
+ }
31
+ export function withConfirmActionInternal(ActionComponent,
32
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
33
+ renderDefaultProps, defaultProps) {
34
+ var ConfirmActionWithRef = /*#__PURE__*/forwardRef(genRenderer(renderDefaultProps));
35
+ ConfirmActionWithRef.displayName = 'ForwardRef(ConfirmAction)';
36
+ var WrappedActionComponent = /*#__PURE__*/forwardRef(function (propsWithDefaults, ref) {
37
+ var actionRef = useRef(null);
38
+ var _useState = useState(null),
39
+ _useState2 = _slicedToArray(_useState, 2),
40
+ customRef = _useState2[0],
41
+ setCustomRef = _useState2[1];
42
+ var saveFuncRef = useRef(undefined);
43
+
44
+ // Receive the onSave callback method passed by the form component
45
+ var setOnOk = useCallback(function (handler) {
46
+ saveFuncRef.current = handler;
47
+ }, []);
48
+
49
+ // Merge the default ref and custom ref and output to the parent component
50
+ useImperativeHandle(ref, function () {
51
+ return _objectSpread(_objectSpread({}, actionRef.current), customRef);
52
+ }, [customRef]);
53
+
54
+ // Render the default trigger DOM element, and pass it to the custom ActionComponent
55
+ var triggerDom = /*#__PURE__*/_jsx(ConfirmActionWithRef, _objectSpread(_objectSpread({}, propsWithDefaults), {}, {
56
+ onOk: saveFuncRef.current,
57
+ ref: actionRef
58
+ }));
59
+ return /*#__PURE__*/_jsx(ActionComponent, _objectSpread(_objectSpread({}, propsWithDefaults), {}, {
60
+ ref: isForwardRef(ActionComponent) ? setCustomRef : undefined,
61
+ setOK: setOnOk,
62
+ triggerDom: triggerDom
63
+ }));
64
+ });
65
+ WrappedActionComponent.displayName = 'ConfirmAction(ActionComponent)';
66
+ var withDefaults = withDefaultConfirmActionProps(WrappedActionComponent,
67
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
68
+ defaultProps);
69
+ // return withDefaults;
70
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
71
+ return addTriggers(withDefaults);
72
+ }
73
+
74
+ /**
75
+ * - **EN:** Add trigger types to the ModalAction component
76
+ * - **CN:** 给ModalAction组件添加子触发器类型
77
+ */
78
+ function addTriggers(comp) {
79
+ var patchedComp = comp;
80
+ // Type of button trigger
81
+ patchedComp.Button = withDefaultConfirmActionProps(
82
+ // @ts-expect-error: because the type is a little bit complex, so we ignore the type error here
83
+ comp, {
84
+ triggerComponent: Button,
85
+ triggerEvent: 'onClick',
86
+ triggerProps: {}
87
+ }
88
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
89
+ );
90
+ // Type of switch trigger
91
+ patchedComp.Switch = withDefaultConfirmActionProps(
92
+ // @ts-expect-error: because the type is a little bit complex, so we ignore the type error here
93
+ comp, {
94
+ triggerComponent: Switch,
95
+ triggerEvent: 'onChange',
96
+ triggerProps: {}
97
+ }
98
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
99
+ );
100
+ // Type of link trigger
101
+ patchedComp.Link = withDefaultConfirmActionProps(
102
+ // @ts-expect-error: because the type is a little bit complex, so we ignore the type error here
103
+ comp, {
104
+ triggerComponent: Typography.Link,
105
+ triggerEvent: 'onClick',
106
+ triggerProps: {
107
+ style: {
108
+ whiteSpace: 'nowrap'
109
+ }
110
+ }
111
+ }
112
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
113
+ );
114
+ return patchedComp;
115
+ }
116
+
117
+ /**
118
+ * - **EN:** ModalAction component type
119
+ * - **CN:** ModalAction组件的类型
120
+ */
121
+
122
+ /**
123
+ * - **EN:** Built-in trigger types (specified form components)
124
+ * - **CN:** 内置的几种触发器类型(已指定表单组件)
125
+ */
126
+
127
+ /**
128
+ * - **EN:** ModalAction with specified trigger type (specified form component)
129
+ * - **CN:** 已指定Trigger类型的ModalAction(并且已指定表单组件)
130
+ */
131
+ //# sourceMappingURL=withConfirmAction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["forwardRef","useCallback","useImperativeHandle","useRef","useState","genRenderer","withDefaultConfirmActionProps","Button","Switch","Typography","isForwardRef","jsx","_jsx","withConfirmAction","ActionComponent","defaultProps","withConfirmActionInternal","confirmType","renderDefaultProps","ConfirmActionWithRef","displayName","WrappedActionComponent","propsWithDefaults","ref","actionRef","_useState","_useState2","_slicedToArray","customRef","setCustomRef","saveFuncRef","undefined","setOnOk","handler","current","_objectSpread","triggerDom","onOk","setOK","withDefaults","addTriggers","comp","patchedComp","triggerComponent","triggerEvent","triggerProps","Link","style","whiteSpace"],"sources":["../../../src/components/ConfirmAction/withConfirmAction.tsx"],"sourcesContent":["import type { ComponentType, PropsWithoutRef, ReactNode, RefAttributes } from 'react';\nimport { forwardRef, useCallback, useImperativeHandle, useRef, useState } from 'react';\nimport type { ActionCompConstraint, ConfirmActionProps, ConfirmActionRef } from '.';\nimport { genRenderer, withDefaultConfirmActionProps } from '.';\nimport { Button, type ButtonProps, Switch, type SwitchProps, Typography } from 'antd';\nimport type { LinkProps } from 'antd/es/typography/Link';\nimport { isForwardRef } from 'react-is';\n\n/**\n * - **EN:** Generate a confirm box component with custom trigger and default props\n * - **CN:** 将一个组件包装成一个确认弹框组件,支持自定义触发器和默认属性\n *\n * @param actionComponent Custom trigger component | 自定义触发器组件\n * @param defaultProps Default properties of the confirm box | 确认弹框的默认属性\n */\nexport default function withConfirmAction<\n P extends ActionCompConstraint,\n OuterTriggerProp extends object,\n OuterEvent extends keyof OuterTriggerProp,\n Ref extends object,\n>(\n ActionComponent: ActionComponentInterface<P, Ref>,\n defaultProps?:\n | Partial<Omit<P, keyof ActionCompConstraint> & ConfirmActionProps<OuterTriggerProp, OuterEvent>>\n | ((\n actualProps: Omit<P, keyof ActionCompConstraint> & ConfirmActionProps<OuterTriggerProp, OuterEvent>\n ) => Partial<Omit<P, keyof ActionCompConstraint> & ConfirmActionProps<OuterTriggerProp, OuterEvent>>)\n) {\n return withConfirmActionInternal(\n ActionComponent,\n {\n confirmType: 'normal',\n },\n defaultProps\n );\n}\n\nexport function withConfirmActionInternal<\n P extends ActionCompConstraint,\n OuterTriggerProp extends object,\n OuterEvent extends keyof OuterTriggerProp,\n Ref extends object,\n>(\n ActionComponent: ActionComponentInterface<P, Ref>,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n renderDefaultProps: Partial<ConfirmActionProps<any, never>> & { confirmType: 'normal' | 'delete' },\n defaultProps?:\n | Partial<Omit<P, keyof ActionCompConstraint> & ConfirmActionProps<OuterTriggerProp, OuterEvent>>\n | ((\n actualProps: Omit<P, keyof ActionCompConstraint> & ConfirmActionProps<OuterTriggerProp, OuterEvent>\n ) => Partial<Omit<P, keyof ActionCompConstraint> & ConfirmActionProps<OuterTriggerProp, OuterEvent>>)\n) {\n const ConfirmActionWithRef = forwardRef(genRenderer(renderDefaultProps));\n ConfirmActionWithRef.displayName = 'ForwardRef(ConfirmAction)';\n\n const WrappedActionComponent = forwardRef<Ref, ConfirmActionProps<OuterTriggerProp, OuterEvent>>(\n (propsWithDefaults, ref) => {\n const actionRef = useRef<ConfirmActionRef>(null);\n const [customRef, setCustomRef] = useState<Ref | null>(null);\n const saveFuncRef = useRef<(...triggerEventArgs: any[]) => unknown | Promise<unknown>>(undefined);\n\n // Receive the onSave callback method passed by the form component\n const setOnOk: ActionCompConstraint['setOK'] = useCallback((handler) => {\n saveFuncRef.current = handler;\n }, []);\n\n // Merge the default ref and custom ref and output to the parent component\n useImperativeHandle(ref, () => {\n return {\n ...actionRef.current,\n ...customRef,\n } as ConfirmActionRef<Ref>;\n }, [customRef]);\n\n // Render the default trigger DOM element, and pass it to the custom ActionComponent\n const triggerDom = (\n <ConfirmActionWithRef\n {...(propsWithDefaults as ConfirmActionProps<object, never>)}\n onOk={saveFuncRef.current}\n ref={actionRef}\n />\n );\n\n return (\n <ActionComponent\n {...(propsWithDefaults as P)}\n ref={isForwardRef(ActionComponent) ? setCustomRef : undefined}\n setOK={setOnOk}\n triggerDom={triggerDom}\n />\n );\n }\n );\n WrappedActionComponent.displayName = 'ConfirmAction(ActionComponent)';\n\n const withDefaults = withDefaultConfirmActionProps(\n WrappedActionComponent,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n defaultProps as any\n ) as unknown as ComponentType<\n Omit<ConfirmActionProps<OuterTriggerProp, OuterEvent>, 'triggerComponent'> & RefAttributes<ConfirmActionRef>\n >;\n // return withDefaults;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return addTriggers<P, OuterTriggerProp, OuterEvent, Ref>(withDefaults as any);\n}\n\n/**\n * - **EN:** Add trigger types to the ModalAction component\n * - **CN:** 给ModalAction组件添加子触发器类型\n */\nfunction addTriggers<\n P extends ActionCompConstraint,\n OuterTriggerProp extends object,\n OuterEvent extends keyof OuterTriggerProp,\n Ref extends object,\n>(comp: ComponentType<ConfirmActionProps<OuterTriggerProp, OuterEvent> & RefAttributes<ConfirmActionRef<Ref>>>) {\n const patchedComp = comp as unknown as WithGenericTriggers<P, Ref>;\n // Type of button trigger\n patchedComp.Button = withDefaultConfirmActionProps<P, ButtonProps, 'onClick', Ref>(\n // @ts-expect-error: because the type is a little bit complex, so we ignore the type error here\n comp,\n {\n triggerComponent: Button,\n triggerEvent: 'onClick',\n triggerProps: {},\n }\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ) as any;\n // Type of switch trigger\n patchedComp.Switch = withDefaultConfirmActionProps<P, SwitchProps, 'onChange', Ref>(\n // @ts-expect-error: because the type is a little bit complex, so we ignore the type error here\n comp,\n {\n triggerComponent: Switch,\n triggerEvent: 'onChange',\n triggerProps: {},\n }\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ) as any;\n // Type of link trigger\n patchedComp.Link = withDefaultConfirmActionProps<P, LinkProps, 'onClick', Ref>(\n // @ts-expect-error: because the type is a little bit complex, so we ignore the type error here\n comp,\n {\n triggerComponent: Typography.Link,\n triggerEvent: 'onClick',\n triggerProps: {\n style: { whiteSpace: 'nowrap' },\n },\n }\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ) as any;\n return patchedComp;\n}\n\n/**\n * - **EN:** ModalAction component type\n * - **CN:** ModalAction组件的类型\n */\nexport type ActionComponentInterface<P extends ActionCompConstraint, Ref extends object> = ComponentType<\n P & RefAttributes<ConfirmActionRef<Ref>>\n>;\n\ntype WithGenericTriggers<P extends ActionCompConstraint, Ref extends object> = (<\n TriggerProp extends object,\n Event extends keyof TriggerProp,\n>(\n props: PropsWithoutRef<Omit<P, keyof ActionCompConstraint>> &\n ConfirmActionProps<TriggerProp, Event> &\n RefAttributes<ConfirmActionRef<Ref>>\n) => ReactNode) &\n TypedTriggers<P, Ref>;\n\n/**\n * - **EN:** Built-in trigger types (specified form components)\n * - **CN:** 内置的几种触发器类型(已指定表单组件)\n */\nexport interface TypedTriggers<P extends ActionCompConstraint, Ref extends object> {\n /**\n * - **EN:** Dialog with button type trigger\n * - **CN:** 按钮类型的弹窗\n */\n Button: ConfirmActionWithTrigger<P, ButtonProps, 'onClick', Ref>;\n /**\n * - **EN:** Dialog with switch type trigger\n * - **CN:** 开关类型的弹窗\n */\n Switch: ConfirmActionWithTrigger<P, SwitchProps, 'onChange', Ref>;\n /**\n * - **EN:** Dialog with link type trigger\n * - **CN:** 链接类型的弹窗\n */\n Link: ConfirmActionWithTrigger<P, LinkProps, 'onClick', Ref>;\n}\n\n/**\n * - **EN:** ModalAction with specified trigger type (specified form component)\n * - **CN:** 已指定Trigger类型的ModalAction(并且已指定表单组件)\n */\ntype ConfirmActionWithTrigger<\n P extends ActionCompConstraint,\n TriggerProp extends object,\n Event extends keyof TriggerProp,\n Ref extends object,\n OMIT extends string = never,\n> = ComponentType<\n Omit<\n PropsWithoutRef<Omit<P, keyof ActionCompConstraint>> & ConfirmActionProps<TriggerProp, Event>,\n 'triggerComponent' | 'triggerEvent' | OMIT\n > &\n RefAttributes<ConfirmActionRef<Ref>>\n>;\n"],"mappings":";;;;;;;;;;;;AACA,SAASA,UAAU,EAAEC,WAAW,EAAEC,mBAAmB,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO;AAEtF,SAASC,WAAW,EAAEC,6BAA6B,QAAQ,GAAG;AAC9D,SAASC,MAAM,EAAoBC,MAAM,EAAoBC,UAAU,QAAQ,MAAM;AAErF,SAASC,YAAY,QAAQ,UAAU;;AAEvC;AACA;AACA;AACA;AACA;AACA;AACA;AANA,SAAAC,GAAA,IAAAC,IAAA;AAOA,eAAe,SAASC,iBAAiBA,CAMvCC,eAAiD,EACjDC,YAIyG,EACzG;EACA,OAAOC,yBAAyB,CAC9BF,eAAe,EACf;IACEG,WAAW,EAAE;EACf,CAAC,EACDF,YACF,CAAC;AACH;AAEA,OAAO,SAASC,yBAAyBA,CAMvCF,eAAiD;AACjD;AACAI,kBAAkG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mB,YAAY,GAAGjC,6BAA6B,CAChDe,sBAAsB;EACtB;EACAN,YACF,CAEC;EACD;EACA;EACA,OAAOyB,WAAW,CAAuCD,YAAmB,CAAC;AAC/E;;AAEA;AACA;AACA;AACA;AACA,SAASC,WAAWA,CAKlBC,IAA4G,EAAE;EAC9G,IAAMC,WAAW,GAAGD,IAA8C;EAClE;EACAC,WAAW,CAACnC,MAAM,GAAGD,6BAA6B;EAChD;EACAmC,IAAI,EACJ;IACEE,gBAAgB,EAAEpC,MAAM;IACxBqC,YAAY,EAAE,SAAS;IACvBC,YAAY,EAAE,CAAC;EACjB;EACA;EACF,CAAQ;EACR;EACAH,WAAW,CAAClC,MAAM,GAAGF,6BAA6B;EAChD;EACAmC,IAAI,EACJ;IACEE,gBAAgB,EAAEnC,MAAM;IACxBoC,YAAY,EAAE,UAAU;IACxBC,YAAY,EAAE,CAAC;EACjB;EACA;EACF,CAAQ;EACR;EACAH,WAAW,CAACI,IAAI,GAAGxC,6BAA6B;EAC9C;EACAmC,IAAI,EACJ;IACEE,gBAAgB,EAAElC,UAAU,CAACqC,IAAI;IACjCF,YAAY,EAAE,SAAS;IACvBC,YAAY,EAAE;MACZE,KAAK,EAAE;QAAEC,UAAU,EAAE;MAAS;IAChC;EACF;EACA;EACF,CAAQ;EACR,OAAON,WAAW;AACpB;;AAEA;AACA;AACA;AACA;;AAeA;AACA;AACA;AACA;;AAmBA;AACA;AACA;AACA"}
@@ -0,0 +1,42 @@
1
+ import type { CSSProperties, ReactNode } from 'react';
2
+ import type { ItemProps, MenuProps, SeparatorProps, SubMenuProps } from 'react-contexify';
3
+ import 'react-contexify/dist/ReactContexify.css';
4
+ export interface ContextMenuProps extends MenuProps {
5
+ /**
6
+ * - **EN:** Menu items to be displayed
7
+ * - **CN:** 要显示的菜单项
8
+ */
9
+ items: (ContextMenuItem | ContextMenuSeparator | ContextMenuSubmenu)[] | undefined;
10
+ /**
11
+ * - **EN:** Trigger methods to show the menu, default is `['contextMenu']`
12
+ * - **CN:** 触发显示菜单的方式,默认是 `['contextMenu']`
13
+ */
14
+ trigger?: ('click' | 'doubleClick' | 'hover' | 'contextMenu')[];
15
+ triggerProps?: {
16
+ className?: string;
17
+ style?: CSSProperties;
18
+ };
19
+ prefixCls?: string;
20
+ }
21
+ declare const ContextMenu: import("react").ForwardRefExoticComponent<ContextMenuProps & import("react").RefAttributes<ContextMenuRef>>;
22
+ export interface ContextMenuRef {
23
+ show: (event: React.MouseEvent<HTMLElement>) => void;
24
+ hideAll: () => void;
25
+ }
26
+ export interface ContextMenuItem extends Omit<ItemProps, 'children' | 'keyMatcher'> {
27
+ key: string;
28
+ className?: string;
29
+ icon?: ReactNode;
30
+ label?: ReactNode;
31
+ shortcutKey?: Partial<Pick<KeyboardEvent, 'ctrlKey' | 'altKey' | 'shiftKey' | 'metaKey' | 'key'>> | ItemProps['keyMatcher'];
32
+ children?: ReactNode;
33
+ }
34
+ export interface ContextMenuSeparator extends SeparatorProps {
35
+ type: 'separator';
36
+ }
37
+ export interface ContextMenuSubmenu extends SubMenuProps {
38
+ key: string;
39
+ type: 'submenu';
40
+ items: (ContextMenuItem | ContextMenuSeparator | ContextMenuSubmenu)[];
41
+ }
42
+ export default ContextMenu;
@@ -0,0 +1,188 @@
1
+ var _excluded = ["id", "items", "trigger", "triggerProps", "prefixCls", "className", "children"];
2
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
3
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
4
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
5
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
7
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
8
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
9
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
10
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
11
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
12
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
13
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
14
+ function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
15
+ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
16
+ import { forwardRef, useContext, useImperativeHandle, useMemo } from 'react';
17
+ import { theme as AntdTheme, ConfigProvider, Typography } from 'antd';
18
+ import classNames from 'classnames';
19
+ import { Item, Menu, RightSlot, Separator, Submenu, useContextMenu } from 'react-contexify';
20
+ import { useRefFunction } from "../../hooks";
21
+ import useStyle from "./style";
22
+ import 'react-contexify/dist/ReactContexify.css';
23
+ import { jsx as _jsx } from "react/jsx-runtime";
24
+ import { Fragment as _Fragment } from "react/jsx-runtime";
25
+ import { jsxs as _jsxs } from "react/jsx-runtime";
26
+ import { createElement as _createElement } from "react";
27
+ // 上下文菜单组件
28
+ var ContextMenu = /*#__PURE__*/forwardRef(function (props, ref) {
29
+ var id = props.id,
30
+ items = props.items,
31
+ _props$trigger = props.trigger,
32
+ trigger = _props$trigger === void 0 ? ['contextMenu'] : _props$trigger,
33
+ triggerProps = props.triggerProps,
34
+ prefixClsInProps = props.prefixCls,
35
+ className = props.className,
36
+ children = props.children,
37
+ rest = _objectWithoutProperties(props, _excluded);
38
+ var _useContext = useContext(ConfigProvider.ConfigContext),
39
+ getPrefixCls = _useContext.getPrefixCls;
40
+ var prefixCls = getPrefixCls('context-menu', prefixClsInProps);
41
+ var _useStyle = useStyle(prefixCls),
42
+ _useStyle2 = _slicedToArray(_useStyle, 3),
43
+ wrapCSSVar = _useStyle2[0],
44
+ hashId = _useStyle2[1],
45
+ cssVarCls = _useStyle2[2];
46
+ var _useContextMenu = useContextMenu({
47
+ id: id
48
+ }),
49
+ show = _useContextMenu.show,
50
+ hideAll = _useContextMenu.hideAll;
51
+ var eventNames = useMemo(function () {
52
+ return {
53
+ click: ['onClick', undefined],
54
+ doubleClick: ['onDoubleClick', undefined],
55
+ hover: ['onPointerEnter', 'onPointerLeave'],
56
+ contextMenu: ['onContextMenu', undefined]
57
+ };
58
+ }, []);
59
+
60
+ // Show context menu handler
61
+ var handleShow = useRefFunction(function (event, options) {
62
+ show({
63
+ id: id,
64
+ event: event,
65
+ props: props,
66
+ position: options === null || options === void 0 ? void 0 : options.position
67
+ });
68
+ });
69
+ // Hide all context menus handler
70
+ var handleHideAll = useRefFunction(function () {
71
+ hideAll();
72
+ });
73
+ var eventHandlers = useMemo(function () {
74
+ var handlers = {};
75
+ if (trigger) {
76
+ trigger.forEach(function (eventType) {
77
+ var _eventNames$eventType = _slicedToArray(eventNames[eventType], 2),
78
+ handlerName = _eventNames$eventType[0],
79
+ leaveHandlerName = _eventNames$eventType[1];
80
+ handlers[handlerName] = function (event) {
81
+ handleShow(event);
82
+ };
83
+ if (leaveHandlerName) {
84
+ handlers[leaveHandlerName] = handleHideAll;
85
+ }
86
+ });
87
+ }
88
+ return handlers;
89
+ }, [eventNames, trigger]);
90
+
91
+ // Expose show and hideAll methods to the ref
92
+ useImperativeHandle(ref, function () {
93
+ return {
94
+ show: handleShow,
95
+ hideAll: handleHideAll
96
+ };
97
+ }, []);
98
+ return /*#__PURE__*/_jsxs(_Fragment, {
99
+ children: [children && wrapCSSVar( /*#__PURE__*/_jsx("div", _objectSpread(_objectSpread({}, eventHandlers), {}, {
100
+ className: classNames(hashId, cssVarCls, prefixCls, "".concat(prefixCls, "-trigger"), triggerProps === null || triggerProps === void 0 ? void 0 : triggerProps.className),
101
+ style: triggerProps === null || triggerProps === void 0 ? void 0 : triggerProps.style,
102
+ children: children
103
+ }))), wrapCSSVar( /*#__PURE__*/_jsx(Menu, _objectSpread(_objectSpread({
104
+ id: id,
105
+ className: classNames(hashId, cssVarCls, prefixCls, "".concat(prefixCls, "-menu"), _defineProperty({}, "".concat(prefixCls, "-menu-has-items"), !!(items !== null && items !== void 0 && items.length)), className)
106
+ }, rest), {}, {
107
+ children: renderItems(items, {
108
+ theme: props.theme,
109
+ cmpPrefixCls: prefixCls
110
+ })
111
+ })))]
112
+ });
113
+ });
114
+ ContextMenu.displayName = 'ContextMenu';
115
+
116
+ // Render menu items
117
+ function renderItems(items, options) {
118
+ return items === null || items === void 0 ? void 0 : items.map(function (item, index) {
119
+ var isSeparator = 'type' in item && item.type === 'separator';
120
+ var isSubmenu = 'type' in item && item.type === 'submenu';
121
+ var menuItem = item;
122
+ if (isSeparator) {
123
+ // eslint-disable-next-line react/no-array-index-key
124
+ return /*#__PURE__*/_jsx(Separator, {}, "[separator]:".concat(index));
125
+ }
126
+ if (isSubmenu) {
127
+ var subMenu = item;
128
+ return /*#__PURE__*/_createElement(Submenu, _objectSpread(_objectSpread({}, subMenu), {}, {
129
+ key: subMenu.key
130
+ }), renderItems(item.items, options));
131
+ }
132
+ return /*#__PURE__*/_createElement(Item, _objectSpread(_objectSpread({}, menuItem), {}, {
133
+ keyMatcher: _typeof(menuItem.shortcutKey) === 'object' ? function (e) {
134
+ var shortcutKey = menuItem.shortcutKey;
135
+ if (shortcutKey.ctrlKey && !e.ctrlKey) return false;
136
+ if (shortcutKey.altKey && !e.altKey) return false;
137
+ if (shortcutKey.shiftKey && !e.shiftKey) return false;
138
+ if (shortcutKey.metaKey && !e.metaKey) return false;
139
+ if (!shortcutKey.key || shortcutKey.key !== e.key) return false;
140
+ return true;
141
+ } : menuItem.shortcutKey,
142
+ key: menuItem.key
143
+ }), menuItem.children ? menuItem.children : /*#__PURE__*/_jsxs(_Fragment, {
144
+ children: [menuItem.icon, /*#__PURE__*/_jsx("span", {
145
+ children: menuItem.label
146
+ }), _typeof(menuItem.shortcutKey) === 'object' && /*#__PURE__*/_jsx(RightSlot, {
147
+ children: getShortcutText(menuItem.shortcutKey, options)
148
+ })]
149
+ }));
150
+ });
151
+ }
152
+ function getShortcutText(event, options) {
153
+ var theme = options.theme,
154
+ cmpPrefixCls = options.cmpPrefixCls;
155
+ var keys = [];
156
+ var Keyboard = function Keyboard(props) {
157
+ return /*#__PURE__*/_jsx(ConfigProvider, {
158
+ theme: {
159
+ algorithm: theme === 'dark' ? AntdTheme.darkAlgorithm : undefined
160
+ },
161
+ children: /*#__PURE__*/_jsx(Typography.Text, {
162
+ keyboard: true,
163
+ className: "".concat(cmpPrefixCls, "-shortcut-key"),
164
+ children: props.children
165
+ })
166
+ });
167
+ };
168
+ if (event.ctrlKey) keys.push( /*#__PURE__*/_jsx(Keyboard, {
169
+ children: "^"
170
+ }));
171
+ if (event.altKey) keys.push( /*#__PURE__*/_jsx(Keyboard, {
172
+ children: "\u2325"
173
+ }));
174
+ if (event.shiftKey) keys.push( /*#__PURE__*/_jsx(Keyboard, {
175
+ children: "\u21E7"
176
+ }));
177
+ if (event.metaKey) keys.push( /*#__PURE__*/_jsx(Keyboard, {
178
+ children: "\u2318"
179
+ }));
180
+ if (event.key) {
181
+ keys.push( /*#__PURE__*/_jsx(Keyboard, {
182
+ children: event.key
183
+ }));
184
+ }
185
+ return keys;
186
+ }
187
+ export default ContextMenu;
188
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["forwardRef","useContext","useImperativeHandle","useMemo","theme","AntdTheme","ConfigProvider","Typography","classNames","Item","Menu","RightSlot","Separator","Submenu","useContextMenu","useRefFunction","useStyle","jsx","_jsx","Fragment","_Fragment","jsxs","_jsxs","createElement","_createElement","ContextMenu","props","ref","id","items","_props$trigger","trigger","triggerProps","prefixClsInProps","prefixCls","className","children","rest","_objectWithoutProperties","_excluded","_useContext","ConfigContext","getPrefixCls","_useStyle","_useStyle2","_slicedToArray","wrapCSSVar","hashId","cssVarCls","_useContextMenu","show","hideAll","eventNames","click","undefined","doubleClick","hover","contextMenu","handleShow","event","options","position","handleHideAll","eventHandlers","handlers","forEach","eventType","_eventNames$eventType","handlerName","leaveHandlerName","_objectSpread","concat","style","_defineProperty","length","renderItems","cmpPrefixCls","displayName","map","item","index","isSeparator","type","isSubmenu","menuItem","subMenu","key","keyMatcher","_typeof","shortcutKey","e","ctrlKey","altKey","shiftKey","metaKey","icon","label","getShortcutText","keys","Keyboard","algorithm","darkAlgorithm","Text","keyboard","push"],"sources":["../../../src/components/ContextMenu/index.tsx"],"sourcesContent":["import type { CSSProperties, ReactNode } from 'react';\nimport { forwardRef, useContext, useImperativeHandle, useMemo } from 'react';\nimport { theme as AntdTheme, ConfigProvider, Typography } from 'antd';\nimport classNames from 'classnames';\nimport type { ItemProps, MenuProps, SeparatorProps, ShowContextMenuParams, SubMenuProps } from 'react-contexify';\nimport { Item, Menu, RightSlot, Separator, Submenu, useContextMenu } from 'react-contexify';\nimport { useRefFunction } from '../../hooks';\nimport useStyle from './style';\nimport 'react-contexify/dist/ReactContexify.css';\n\nexport interface ContextMenuProps extends MenuProps {\n /**\n * - **EN:** Menu items to be displayed\n * - **CN:** 要显示的菜单项\n */\n items: (ContextMenuItem | ContextMenuSeparator | ContextMenuSubmenu)[] | undefined;\n /**\n * - **EN:** Trigger methods to show the menu, default is `['contextMenu']`\n * - **CN:** 触发显示菜单的方式,默认是 `['contextMenu']`\n */\n trigger?: ('click' | 'doubleClick' | 'hover' | 'contextMenu')[];\n triggerProps?: {\n className?: string;\n style?: CSSProperties;\n };\n prefixCls?: string;\n}\n// 上下文菜单组件\nconst ContextMenu = forwardRef<ContextMenuRef, ContextMenuProps>((props, ref) => {\n const {\n id,\n items,\n trigger = ['contextMenu'],\n triggerProps,\n prefixCls: prefixClsInProps,\n className,\n children,\n ...rest\n } = props;\n const { getPrefixCls } = useContext(ConfigProvider.ConfigContext);\n const prefixCls = getPrefixCls('context-menu', prefixClsInProps);\n const [wrapCSSVar, hashId, cssVarCls] = useStyle(prefixCls);\n const { show, hideAll } = useContextMenu({ id });\n const eventNames = useMemo<Record<NonNullable<ContextMenuProps['trigger']>[number], [string, string | undefined]>>(\n () => ({\n click: ['onClick', undefined],\n doubleClick: ['onDoubleClick', undefined],\n hover: ['onPointerEnter', 'onPointerLeave'],\n contextMenu: ['onContextMenu', undefined],\n }),\n []\n );\n\n // Show context menu handler\n const handleShow = useRefFunction(\n (event: React.MouseEvent<HTMLElement>, options?: Pick<ShowContextMenuParams, 'position'>) => {\n show({\n id,\n event,\n props,\n position: options?.position,\n });\n }\n );\n // Hide all context menus handler\n const handleHideAll = useRefFunction(() => {\n hideAll();\n });\n const eventHandlers = useMemo(() => {\n const handlers: Record<string, (event: React.MouseEvent<HTMLElement>) => void> = {};\n if (trigger) {\n trigger.forEach((eventType) => {\n const [handlerName, leaveHandlerName] = eventNames[eventType];\n handlers[handlerName] = (event: React.MouseEvent<HTMLElement>) => {\n handleShow(event);\n };\n if (leaveHandlerName) {\n handlers[leaveHandlerName] = handleHideAll;\n }\n });\n }\n return handlers;\n }, [eventNames, trigger]);\n\n // Expose show and hideAll methods to the ref\n useImperativeHandle(\n ref,\n () => ({\n show: handleShow,\n hideAll: handleHideAll,\n }),\n []\n );\n\n return (\n <>\n {children &&\n wrapCSSVar(\n <div\n {...eventHandlers}\n className={classNames(hashId, cssVarCls, prefixCls, `${prefixCls}-trigger`, triggerProps?.className)}\n style={triggerProps?.style}\n >\n {children}\n </div>\n )}\n {wrapCSSVar(\n <Menu\n id={id}\n className={classNames(\n hashId,\n cssVarCls,\n prefixCls,\n `${prefixCls}-menu`,\n {\n [`${prefixCls}-menu-has-items`]: !!items?.length,\n },\n className\n )}\n {...rest}\n >\n {renderItems(items, { theme: props.theme, cmpPrefixCls: prefixCls })}\n </Menu>\n )}\n </>\n );\n});\nContextMenu.displayName = 'ContextMenu';\n\n// Render menu items\nfunction renderItems(\n items: (ContextMenuItem | ContextMenuSeparator | ContextMenuSubmenu)[] | undefined,\n options: Pick<ContextMenuProps, 'theme'> & { cmpPrefixCls: string }\n): ReactNode[] | undefined {\n return items?.map((item, index) => {\n const isSeparator = 'type' in item && item.type === 'separator';\n const isSubmenu = 'type' in item && item.type === 'submenu';\n const menuItem = item as ContextMenuItem;\n\n if (isSeparator) {\n // eslint-disable-next-line react/no-array-index-key\n return <Separator key={`[separator]:${index}`} />;\n }\n\n if (isSubmenu) {\n const subMenu = item as ContextMenuSubmenu;\n return (\n <Submenu {...subMenu} key={subMenu.key}>\n {renderItems(item.items, options)}\n </Submenu>\n );\n }\n\n return (\n <Item\n {...menuItem}\n keyMatcher={\n typeof menuItem.shortcutKey === 'object'\n ? (e) => {\n const shortcutKey = menuItem.shortcutKey as Partial<KeyboardEvent>;\n if (shortcutKey.ctrlKey && !e.ctrlKey) return false;\n if (shortcutKey.altKey && !e.altKey) return false;\n if (shortcutKey.shiftKey && !e.shiftKey) return false;\n if (shortcutKey.metaKey && !e.metaKey) return false;\n if (!shortcutKey.key || shortcutKey.key !== e.key) return false;\n return true;\n }\n : menuItem.shortcutKey\n }\n key={menuItem.key}\n >\n {menuItem.children ? (\n menuItem.children\n ) : (\n <>\n {menuItem.icon}\n <span>{menuItem.label}</span>\n {typeof menuItem.shortcutKey === 'object' && (\n <RightSlot>{getShortcutText(menuItem.shortcutKey, options)}</RightSlot>\n )}\n </>\n )}\n </Item>\n );\n });\n}\n\nfunction getShortcutText(\n event: Partial<Pick<KeyboardEvent, 'ctrlKey' | 'altKey' | 'shiftKey' | 'metaKey' | 'key'>>,\n options: Pick<ContextMenuProps, 'theme'> & { cmpPrefixCls: string }\n): ReactNode[] {\n const { theme, cmpPrefixCls } = options;\n const keys: ReactNode[] = [];\n const Keyboard = (props: { children: ReactNode }) => {\n return (\n <ConfigProvider theme={{ algorithm: theme === 'dark' ? AntdTheme.darkAlgorithm : undefined }}>\n <Typography.Text keyboard className={`${cmpPrefixCls}-shortcut-key`}>\n {props.children}\n </Typography.Text>\n </ConfigProvider>\n );\n };\n if (event.ctrlKey) keys.push(<Keyboard>^</Keyboard>);\n if (event.altKey) keys.push(<Keyboard>⌥</Keyboard>);\n if (event.shiftKey) keys.push(<Keyboard>⇧</Keyboard>);\n if (event.metaKey) keys.push(<Keyboard>⌘</Keyboard>);\n if (event.key) {\n keys.push(<Keyboard>{event.key}</Keyboard>);\n }\n return keys;\n}\n\nexport interface ContextMenuRef {\n show: (event: React.MouseEvent<HTMLElement>) => void;\n hideAll: () => void;\n}\n\nexport interface ContextMenuItem extends Omit<ItemProps, 'children' | 'keyMatcher'> {\n key: string;\n className?: string;\n icon?: ReactNode;\n label?: ReactNode;\n shortcutKey?:\n | Partial<Pick<KeyboardEvent, 'ctrlKey' | 'altKey' | 'shiftKey' | 'metaKey' | 'key'>>\n | ItemProps['keyMatcher'];\n children?: ReactNode;\n}\n\nexport interface ContextMenuSeparator extends SeparatorProps {\n type: 'separator';\n}\n\nexport interface ContextMenuSubmenu extends SubMenuProps {\n key: string;\n type: 'submenu';\n items: (ContextMenuItem | ContextMenuSeparator | ContextMenuSubmenu)[];\n}\n\nexport default ContextMenu;\n"],"mappings":";;;;;;;;;;;;;;;AACA,SAASA,UAAU,EAAEC,UAAU,EAAEC,mBAAmB,EAAEC,OAAO,QAAQ,OAAO;AAC5E,SAASC,KAAK,IAAIC,SAAS,EAAEC,cAAc,EAAEC,UAAU,QAAQ,MAAM;AACrE,OAAOC,UAAU,MAAM,YAAY;AAEnC,SAASC,IAAI,EAAEC,IAAI,EAAEC,SAAS,EAAEC,SAAS,EAAEC,OAAO,EAAEC,cAAc,QAAQ,iBAAiB;AAC3F,SAASC,cAA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CAAC,CAAC;EACnD,IAAIuB,KAAK,CAACkC,QAAQ,EAAEK,IAAI,CAACM,IAAI,eAACtF,IAAA,CAACiF,QAAQ;IAAA/D,QAAA,EAAC;EAAC,CAAU,CAAC,CAAC;EACrD,IAAIuB,KAAK,CAACmC,OAAO,EAAEI,IAAI,CAACM,IAAI,eAACtF,IAAA,CAACiF,QAAQ;IAAA/D,QAAA,EAAC;EAAC,CAAU,CAAC,CAAC;EACpD,IAAIuB,KAAK,CAAC2B,GAAG,EAAE;IACbY,IAAI,CAACM,IAAI,eAACtF,IAAA,CAACiF,QAAQ;MAAA/D,QAAA,EAAEuB,KAAK,CAAC2B;IAAG,CAAW,CAAC,CAAC;EAC7C;EACA,OAAOY,IAAI;AACb;AA4BA,eAAezE,WAAW"}
@@ -0,0 +1,3 @@
1
+ /// <reference types="react" />
2
+ declare const _default: (prefixCls: string, rootCls?: string | undefined) => readonly [(node: import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>>) => import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>>, string, string];
3
+ export default _default;
@@ -0,0 +1,25 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
3
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
4
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
5
+ import { genStyleHooks } from 'antd/es/theme/internal';
6
+ var genStyle = function genStyle(token) {
7
+ var componentCls = token.componentCls;
8
+ return _defineProperty({}, componentCls, {
9
+ '&-trigger': {
10
+ width: 'fit-content'
11
+ },
12
+ '&-menu': _defineProperty({
13
+ padding: 0,
14
+ '&-has-items': {
15
+ padding: 'var(--contexify-menu-padding)'
16
+ }
17
+ }, "".concat(componentCls, "-shortcut-key"), {
18
+ kbd: {
19
+ fontFamily: '-apple-system,BlinkMacSystemFont,PingFang SC,Hiragino Sans GB,sans-serif'
20
+ }
21
+ })
22
+ });
23
+ };
24
+ export default genStyleHooks('ContextMenu', genStyle);
25
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["genStyleHooks","genStyle","token","componentCls","_defineProperty","width","padding","concat","kbd","fontFamily"],"sources":["../../../../src/components/ContextMenu/style/index.ts"],"sourcesContent":["import { genStyleHooks } from 'antd/es/theme/internal';\nimport type { AliasToken, GenerateStyle } from 'antd/es/theme/internal';\nimport type { CSSObject } from '@ant-design/cssinjs';\nimport type { FullToken } from '@ant-design/cssinjs-utils';\n\ntype OverflowTagsToken = FullToken<{ ''?: object }, AliasToken, ''>;\n\nconst genStyle: GenerateStyle<OverflowTagsToken> = (token): CSSObject => {\n const { componentCls } = token;\n return {\n [componentCls]: {\n '&-trigger': {\n width: 'fit-content',\n },\n '&-menu': {\n padding: 0,\n '&-has-items': {\n padding: 'var(--contexify-menu-padding)',\n },\n [`${componentCls}-shortcut-key`]: {\n kbd: {\n fontFamily: '-apple-system,BlinkMacSystemFont,PingFang SC,Hiragino Sans GB,sans-serif',\n },\n },\n },\n },\n };\n};\n\nexport default genStyleHooks('ContextMenu' as never, genStyle);\n"],"mappings":";;;;AAAA,SAASA,aAAa,QAAQ,wBAAwB;AAOtD,IAAMC,QAA0C,GAAG,SAA7CA,QAA0CA,CAAIC,KAAK,EAAgB;EACvE,IAAQC,YAAY,GAAKD,KAAK,CAAtBC,YAAY;EACpB,OAAAC,eAAA,KACGD,YAAY,EAAG;IACd,WAAW,EAAE;MACXE,KAAK,EAAE;IACT,CAAC;IACD,QAAQ,EAAAD,eAAA;MACNE,OAAO,EAAE,CAAC;MACV,aAAa,EAAE;QACbA,OAAO,EAAE;MACX;IAAC,MAAAC,MAAA,CACGJ,YAAY,oBAAkB;MAChCK,GAAG,EAAE;QACHC,UAAU,EAAE;MACd;IACF,CAAC;EAEL,CAAC;AAEL,CAAC;AAED,eAAeT,aAAa,CAAC,aAAa,EAAWC,QAAQ,CAAC"}
@@ -1,4 +1,4 @@
1
- import { type ConfirmActionWithStatic } from '../ConfirmAction';
1
+ import type { ConfirmActionWithStatic } from '../ConfirmAction';
2
2
  /**
3
3
  * - **EN:** Delete operation confirmation box
4
4
  * - **CN:** 删除操作确认框
@@ -19,8 +19,10 @@ var DeleteConfirmAction = forwarded;
19
19
  * - **EN:** Deletion confirmation box with button type
20
20
  * - **CN:** 按钮类型的删除确认框
21
21
  */
22
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types
23
+ DeleteConfirmAction.Button = withDefaultConfirmActionProps(
22
24
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
23
- DeleteConfirmAction.Button = withDefaultConfirmActionProps(forwarded, {
25
+ forwarded, {
24
26
  triggerComponent: Button,
25
27
  triggerEvent: 'onClick',
26
28
  triggerProps: {}
@@ -29,8 +31,10 @@ DeleteConfirmAction.Button = withDefaultConfirmActionProps(forwarded, {
29
31
  * - **EN:** Deletion confirmation box with switch type
30
32
  * - **CN:** 开关类型的删除确认框
31
33
  */
34
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types
35
+ DeleteConfirmAction.Switch = withDefaultConfirmActionProps(
32
36
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
33
- DeleteConfirmAction.Switch = withDefaultConfirmActionProps(forwarded, {
37
+ forwarded, {
34
38
  triggerComponent: Switch,
35
39
  triggerEvent: 'onChange',
36
40
  triggerProps: {}
@@ -39,8 +43,10 @@ DeleteConfirmAction.Switch = withDefaultConfirmActionProps(forwarded, {
39
43
  * - **EN:** Deletion confirmation box with link type
40
44
  * - **CN:** 链接类型的删除确认框
41
45
  */
46
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types
47
+ DeleteConfirmAction.Link = withDefaultConfirmActionProps(
42
48
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
43
- DeleteConfirmAction.Link = withDefaultConfirmActionProps(forwarded, {
49
+ forwarded, {
44
50
  triggerComponent: Typography.Link,
45
51
  triggerEvent: 'onClick',
46
52
  triggerProps: {
@@ -1 +1 @@
1
- {"version":3,"names":["forwardRef","Button","Switch","Typography","CloseCircleFilled","genRenderer","withDefaultConfirmActionProps","jsx","_jsx","renderDeleteConfirmAction","confirmType","danger","icon","forwarded","DeleteConfirmAction","triggerComponent","triggerEvent","triggerProps","Link","style","whiteSpace"],"sources":["../../../src/components/DeleteConfirmAction/index.tsx"],"sourcesContent":["import { forwardRef } from 'react';\nimport type { ButtonProps, SwitchProps } from 'antd';\nimport { Button, Switch, Typography } from 'antd';\nimport type { LinkProps } from 'antd/es/typography/Link';\nimport { CloseCircleFilled } from '@ant-design/icons';\nimport { type ConfirmActionWithStatic, genRenderer, withDefaultConfirmActionProps } from '../ConfirmAction';\n\nconst renderDeleteConfirmAction = genRenderer({\n confirmType: 'delete',\n danger: true,\n icon: <CloseCircleFilled />,\n});\nconst forwarded = forwardRef(renderDeleteConfirmAction);\n\n/**\n * - **EN:** Delete operation confirmation box\n * - **CN:** 删除操作确认框\n */\nconst DeleteConfirmAction = forwarded as unknown as ConfirmActionWithStatic;\n/**\n * - **EN:** Deletion confirmation box with button type\n * - **CN:** 按钮类型的删除确认框\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nDeleteConfirmAction.Button = withDefaultConfirmActionProps<ButtonProps, 'onClick'>(forwarded as any, {\n triggerComponent: Button,\n triggerEvent: 'onClick',\n triggerProps: {},\n});\n/**\n * - **EN:** Deletion confirmation box with switch type\n * - **CN:** 开关类型的删除确认框\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nDeleteConfirmAction.Switch = withDefaultConfirmActionProps<SwitchProps, 'onChange'>(forwarded as any, {\n triggerComponent: Switch,\n triggerEvent: 'onChange',\n triggerProps: {},\n});\n/**\n * - **EN:** Deletion confirmation box with link type\n * - **CN:** 链接类型的删除确认框\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nDeleteConfirmAction.Link = withDefaultConfirmActionProps<LinkProps, 'onClick'>(forwarded as any, {\n triggerComponent: Typography.Link,\n triggerEvent: 'onClick',\n triggerProps: {\n style: { whiteSpace: 'nowrap' },\n },\n});\n\nexport default DeleteConfirmAction;\n"],"mappings":"AAAA,SAASA,UAAU,QAAQ,OAAO;AAElC,SAASC,MAAM,EAAEC,MAAM,EAAEC,UAAU,QAAQ,MAAM;AAEjD,SAASC,iBAAiB,QAAQ,mBAAmB;AACrD,SAAuCC,WAAW,EAAEC,6BAA6B;AAA2B,SAAAC,GAAA,IAAAC,IAAA;AAE5G,IAAMC,yBAAyB,GAAGJ,WAAW,CAAC;EAC5CK,WAAW,EAAE,QAAQ;EACrBC,MAAM,EAAE,IAAI;EACZC,IAAI,eAAEJ,IAAA,CAACJ,iBAAiB,IAAE;AAC5B,CAAC,CAAC;AACF,IAAMS,SAAS,gBAAGb,UAAU,CAACS,yBAAyB,CAAC;;AAEvD;AACA;AACA;AACA;AACA,IAAMK,mBAAmB,GAAGD,SAA+C;AAC3E;AACA;AACA;AACA;AACA;AACAC,mBAAmB,CAACb,MAAM,GAAGK,6BAA6B,CAAyBO,SAAS,EAAS;EACnGE,gBAAgB,EAAEd,MAAM;EACxBe,YAAY,EAAE,SAAS;EACvBC,YAAY,EAAE,CAAC;AACjB,CAAC,CAAC;AACF;AACA;AACA;AACA;AACA;AACAH,mBAAmB,CAACZ,MAAM,GAAGI,6BAA6B,CAA0BO,SAAS,EAAS;EACpGE,gBAAgB,EAAEb,MAAM;EACxBc,YAAY,EAAE,UAAU;EACxBC,YAAY,EAAE,CAAC;AACjB,CAAC,CAAC;AACF;AACA;AACA;AACA;AACA;AACAH,mBAAmB,CAACI,IAAI,GAAGZ,6BAA6B,CAAuBO,SAAS,EAAS;EAC/FE,gBAAgB,EAAEZ,UAAU,CAACe,IAAI;EACjCF,YAAY,EAAE,SAAS;EACvBC,YAAY,EAAE;IACZE,KAAK,EAAE;MAAEC,UAAU,EAAE;IAAS;EAChC;AACF,CAAC,CAAC;AAEF,eAAeN,mBAAmB"}
1
+ {"version":3,"names":["forwardRef","Button","Switch","Typography","CloseCircleFilled","genRenderer","withDefaultConfirmActionProps","jsx","_jsx","renderDeleteConfirmAction","confirmType","danger","icon","forwarded","DeleteConfirmAction","triggerComponent","triggerEvent","triggerProps","Link","style","whiteSpace"],"sources":["../../../src/components/DeleteConfirmAction/index.tsx"],"sourcesContent":["import { forwardRef } from 'react';\nimport type { ButtonProps, SwitchProps } from 'antd';\nimport { Button, Switch, Typography } from 'antd';\nimport type { LinkProps } from 'antd/es/typography/Link';\nimport { CloseCircleFilled } from '@ant-design/icons';\nimport type { ActionCompConstraint, ConfirmActionWithStatic } from '../ConfirmAction';\nimport { genRenderer, withDefaultConfirmActionProps } from '../ConfirmAction';\n\nconst renderDeleteConfirmAction = genRenderer({\n confirmType: 'delete',\n danger: true,\n icon: <CloseCircleFilled />,\n});\nconst forwarded = forwardRef(renderDeleteConfirmAction);\n\n/**\n * - **EN:** Delete operation confirmation box\n * - **CN:** 删除操作确认框\n */\nconst DeleteConfirmAction = forwarded as unknown as ConfirmActionWithStatic;\n/**\n * - **EN:** Deletion confirmation box with button type\n * - **CN:** 按钮类型的删除确认框\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types\nDeleteConfirmAction.Button = withDefaultConfirmActionProps<ActionCompConstraint, ButtonProps, 'onClick', {}>(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n forwarded as any,\n {\n triggerComponent: Button,\n triggerEvent: 'onClick',\n triggerProps: {},\n }\n);\n/**\n * - **EN:** Deletion confirmation box with switch type\n * - **CN:** 开关类型的删除确认框\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types\nDeleteConfirmAction.Switch = withDefaultConfirmActionProps<ActionCompConstraint, SwitchProps, 'onChange', {}>(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n forwarded as any,\n {\n triggerComponent: Switch,\n triggerEvent: 'onChange',\n triggerProps: {},\n }\n);\n/**\n * - **EN:** Deletion confirmation box with link type\n * - **CN:** 链接类型的删除确认框\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types\nDeleteConfirmAction.Link = withDefaultConfirmActionProps<ActionCompConstraint, LinkProps, 'onClick', {}>(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n forwarded as any,\n {\n triggerComponent: Typography.Link,\n triggerEvent: 'onClick',\n triggerProps: {\n style: { whiteSpace: 'nowrap' },\n },\n }\n);\n\nexport default DeleteConfirmAction;\n"],"mappings":"AAAA,SAASA,UAAU,QAAQ,OAAO;AAElC,SAASC,MAAM,EAAEC,MAAM,EAAEC,UAAU,QAAQ,MAAM;AAEjD,SAASC,iBAAiB,QAAQ,mBAAmB;AAErD,SAASC,WAAW,EAAEC,6BAA6B;AAA2B,SAAAC,GAAA,IAAAC,IAAA;AAE9E,IAAMC,yBAAyB,GAAGJ,WAAW,CAAC;EAC5CK,WAAW,EAAE,QAAQ;EACrBC,MAAM,EAAE,IAAI;EACZC,IAAI,eAAEJ,IAAA,CAACJ,iBAAiB,IAAE;AAC5B,CAAC,CAAC;AACF,IAAMS,SAAS,gBAAGb,UAAU,CAACS,yBAAyB,CAAC;;AAEvD;AACA;AACA;AACA;AACA,IAAMK,mBAAmB,GAAGD,SAA+C;AAC3E;AACA;AACA;AACA;AACA;AACAC,mBAAmB,CAACb,MAAM,GAAGK,6BAA6B;AACxD;AACAO,SAAS,EACT;EACEE,gBAAgB,EAAEd,MAAM;EACxBe,YAAY,EAAE,SAAS;EACvBC,YAAY,EAAE,CAAC;AACjB,CACF,CAAC;AACD;AACA;AACA;AACA;AACA;AACAH,mBAAmB,CAACZ,MAAM,GAAGI,6BAA6B;AACxD;AACAO,SAAS,EACT;EACEE,gBAAgB,EAAEb,MAAM;EACxBc,YAAY,EAAE,UAAU;EACxBC,YAAY,EAAE,CAAC;AACjB,CACF,CAAC;AACD;AACA;AACA;AACA;AACA;AACAH,mBAAmB,CAACI,IAAI,GAAGZ,6BAA6B;AACtD;AACAO,SAAS,EACT;EACEE,gBAAgB,EAAEZ,UAAU,CAACe,IAAI;EACjCF,YAAY,EAAE,SAAS;EACvBC,YAAY,EAAE;IACZE,KAAK,EAAE;MAAEC,UAAU,EAAE;IAAS;EAChC;AACF,CACF,CAAC;AAED,eAAeN,mBAAmB"}
@@ -0,0 +1,19 @@
1
+ /// <reference types="react" />
2
+ import type { ActionCompConstraint, ConfirmActionProps } from '../ConfirmAction';
3
+ import { type ActionComponentInterface } from '../ConfirmAction/withConfirmAction';
4
+ /**
5
+ * - **EN:** Wrap a component into a delete confirmation dialog component, supporting custom triggers
6
+ * and default properties
7
+ * - **CN:** 将一个组件包装成一个删除确认弹框组件,支持自定义触发器和默认属性
8
+ *
9
+ * @param actionComponent Custom trigger component | 自定义触发器组件
10
+ * @param defaultProps Default properties of the deletion confirm box | 删除确认弹框的默认属性
11
+ */
12
+ export default function withDeleteConfirmAction<P extends ActionCompConstraint, OuterTriggerProp extends object, OuterEvent extends keyof OuterTriggerProp, Ref extends object>(ActionComponent: ActionComponentInterface<P, Ref>, defaultProps?: Partial<Omit<P, keyof ActionCompConstraint> & ConfirmActionProps<OuterTriggerProp, OuterEvent>> | ((actualProps: Omit<P, keyof ActionCompConstraint> & ConfirmActionProps<OuterTriggerProp, OuterEvent>) => Partial<Omit<P, keyof ActionCompConstraint> & ConfirmActionProps<OuterTriggerProp, OuterEvent>>)): (<TriggerProp extends object, Event extends keyof TriggerProp>(props: import("react").PropsWithoutRef<Omit<P, keyof ActionCompConstraint>> & Omit<import("antd").ModalFuncProps, "onOk"> & import("../ConfirmAction").ConfirmActionTrigger<TriggerProp, Event> & {
13
+ danger?: boolean | undefined;
14
+ titleColor?: import("antd/es/typography/Base").BaseType | "primary" | undefined;
15
+ contentColor?: import("antd/es/typography/Base").BaseType | "primary" | undefined;
16
+ iconColor?: import("antd/es/typography/Base").BaseType | "primary" | undefined;
17
+ onOk?: ((...args: Parameters<TriggerProp[Event]>) => unknown) | undefined;
18
+ afterOk?: ((data?: any) => void) | undefined;
19
+ } & import("react").RefAttributes<import("../ConfirmAction").ConfirmActionRef<Ref>>) => import("react").ReactNode) & import("../ConfirmAction/withConfirmAction").TypedTriggers<P, Ref>;