@zat-design/sisyphus-react 4.7.0 → 4.7.2-beta.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.
@@ -65,7 +65,7 @@ const LineFields = (props) => {
65
65
  ...listeners,
66
66
  className: "pro-form-list-drag-handle",
67
67
  ref: setActivatorNodeRef,
68
- children: /* @__PURE__ */ jsx(ProIcon, { component: dragSvg, size: 20, color: "#949599" })
68
+ children: /* @__PURE__ */ jsx(ProIcon, { component: dragSvg, size: 16 })
69
69
  }
70
70
  ),
71
71
  /* @__PURE__ */ jsx(Row, { className: "pro-form-list-fields", gutter: isLess ? 0 : 24, children: /* @__PURE__ */ jsx(
@@ -35,12 +35,17 @@
35
35
 
36
36
  .pro-form-list-drag-handle {
37
37
  display: flex;
38
+ flex-shrink: 0;
38
39
  align-items: center;
39
40
  height: 32px;
40
41
  margin-bottom: calc(var(--zaui-space-size-md; 16px) * var(--zaui-size; 1));
41
42
  padding: 0;
42
43
  padding-right: @zaui-space-size-sm;
43
44
  border: none;
45
+
46
+ .pro-icon {
47
+ cursor: move;
48
+ }
44
49
  }
45
50
 
46
51
  > .pro-form-list-fields {
@@ -1,7 +1,7 @@
1
1
  import { Fragment, jsx } from "react/jsx-runtime";
2
2
  import isFunction from "lodash/isFunction";
3
3
  import isObject from "lodash/isObject";
4
- import React from "react";
4
+ import React, { useLayoutEffect, useRef, useState } from "react";
5
5
  import { Modal } from "antd";
6
6
  import ProForm from "../../index";
7
7
  import locale from "../../../locale";
@@ -9,45 +9,154 @@ const defaultConfirmProps = {
9
9
  title: locale.ProForm.confirmTitle,
10
10
  content: locale.ProForm.confirmContent
11
11
  };
12
+ const isTextEvent = (event) => {
13
+ const target = event == null ? void 0 : event.target;
14
+ return (target == null ? void 0 : target.tagName) === "TEXTAREA" || (target == null ? void 0 : target.tagName) === "INPUT" && ["text", "search", "password", "email", "tel", "url"].includes(target.type);
15
+ };
12
16
  const ConfirmWrapper = (props) => {
13
17
  const { onChange, children, confirm, otherProps, ...rest } = props;
14
18
  const { form, namePath, name, index, listName } = ProForm.useFieldProps() || {};
19
+ const [draft, setDraft] = useState();
20
+ const composing = useRef(false);
21
+ const compositionValue = useRef(void 0);
22
+ const revision = useRef(0);
23
+ useLayoutEffect(() => {
24
+ revision.current += 1;
25
+ composing.current = false;
26
+ compositionValue.current = void 0;
27
+ setDraft(void 0);
28
+ return () => {
29
+ revision.current += 1;
30
+ };
31
+ }, [rest.value]);
15
32
  const handleChange = async (value, ...other) => {
16
- const _value = (value == null ? void 0 : value.target) ? value.target.value : value;
17
- const confirmProps = isFunction(confirm) ? await confirm(value, form.getFieldsValue(), {
18
- option: other[0],
19
- form,
20
- namePath,
21
- name,
22
- index,
23
- preValue: form.getFieldValue(listName || name)
24
- }) : confirm;
25
- if (confirmProps === false) {
33
+ var _a;
34
+ const target = typeof value === "object" && value !== null && "target" in value ? value.target : void 0;
35
+ const _value = typeof target === "object" && target !== null ? "value" in target ? target.value : void 0 : value;
36
+ const text = isTextEvent(value);
37
+ const currentRevision = text ? ++revision.current : revision.current;
38
+ const isCurrent = () => !text || currentRevision === revision.current;
39
+ const rollback = () => {
40
+ if (text && isCurrent())
41
+ setDraft(void 0);
42
+ };
43
+ const cancel = () => {
44
+ rollback();
45
+ if (text && isCurrent())
46
+ revision.current += 1;
47
+ };
48
+ const commit = () => {
49
+ if (!isCurrent())
50
+ return;
51
+ rollback();
26
52
  onChange == null ? void 0 : onChange(_value, ...other);
53
+ };
54
+ if (text) {
55
+ setDraft(value.target.value);
56
+ if (composing.current)
57
+ return;
58
+ }
59
+ try {
60
+ const confirmProps = isFunction(confirm) ? await confirm(value, form.getFieldsValue(), {
61
+ option: other[0],
62
+ form,
63
+ namePath,
64
+ name,
65
+ index,
66
+ preValue: form.getFieldValue(listName || name)
67
+ }) : confirm;
68
+ if (!isCurrent())
69
+ return;
70
+ if (confirmProps === false) {
71
+ commit();
72
+ } else if (confirmProps === true) {
73
+ Modal.confirm({
74
+ ...defaultConfirmProps,
75
+ onOk: commit,
76
+ ...text ? { onCancel: cancel } : {}
77
+ });
78
+ } else if (isObject(confirmProps)) {
79
+ Modal.confirm({
80
+ ..."title" in confirmProps || "content" in confirmProps ? {} : defaultConfirmProps,
81
+ ...confirmProps,
82
+ ...text ? {
83
+ // Modal uses callback arity to decide who closes the dialog.
84
+ onCancel: ((_a = confirmProps.onCancel) == null ? void 0 : _a.length) ? (close) => {
85
+ var _a2;
86
+ cancel();
87
+ return (_a2 = confirmProps.onCancel) == null ? void 0 : _a2.call(confirmProps, close);
88
+ } : () => {
89
+ var _a2;
90
+ cancel();
91
+ return (_a2 = confirmProps.onCancel) == null ? void 0 : _a2.call(confirmProps);
92
+ }
93
+ } : {},
94
+ onOk: async (...arg) => {
95
+ var _a2;
96
+ if (!isCurrent())
97
+ return;
98
+ try {
99
+ await ((_a2 = confirmProps.onOk) == null ? void 0 : _a2.call(confirmProps, ...arg));
100
+ commit();
101
+ } catch (error) {
102
+ rollback();
103
+ throw error;
104
+ }
105
+ }
106
+ });
107
+ } else {
108
+ rollback();
109
+ }
110
+ } catch (error) {
111
+ rollback();
112
+ throw error;
113
+ }
114
+ };
115
+ const childProps = React.isValidElement(children) ? children.props : {};
116
+ const onCompositionStart = (event) => {
117
+ var _a;
118
+ if (isTextEvent(event)) {
119
+ revision.current += 1;
120
+ composing.current = true;
121
+ compositionValue.current = void 0;
122
+ setDraft(event.currentTarget.value);
27
123
  }
28
- if (confirmProps === true) {
29
- Modal.confirm({
30
- ...defaultConfirmProps,
31
- onOk: () => onChange == null ? void 0 : onChange(_value, ...other)
32
- });
124
+ (_a = rest.onCompositionStart ?? childProps.onCompositionStart) == null ? void 0 : _a(event);
125
+ };
126
+ const onCompositionEnd = (event) => {
127
+ var _a;
128
+ let result;
129
+ if (isTextEvent(event) && composing.current) {
130
+ composing.current = false;
131
+ compositionValue.current = event.currentTarget.value;
132
+ result = handleChange(event);
133
+ }
134
+ (_a = rest.onCompositionEnd ?? childProps.onCompositionEnd) == null ? void 0 : _a(event);
135
+ return result;
136
+ };
137
+ const onInputChange = (value, ...other) => {
138
+ if (isTextEvent(value) && compositionValue.current !== void 0) {
139
+ const previousComposition = compositionValue.current;
140
+ compositionValue.current = void 0;
141
+ if (value.target.value === previousComposition)
142
+ return;
33
143
  }
34
- if (isObject(confirmProps)) {
35
- Modal.confirm({
36
- ..."title" in confirmProps || "content" in confirmProps ? {} : defaultConfirmProps,
37
- ...confirmProps,
38
- onOk: async (...arg) => {
39
- var _a;
40
- await ((_a = confirmProps.onOk) == null ? void 0 : _a.call(confirmProps, ...arg));
41
- onChange == null ? void 0 : onChange(_value, ...other);
42
- }
43
- });
144
+ return handleChange(value, ...other);
145
+ };
146
+ const onKeyPress = (event) => {
147
+ var _a;
148
+ if (isTextEvent(event) && event.key === "Enter" && (composing.current || event.nativeEvent.isComposing || event.keyCode === 229)) {
149
+ event.stopPropagation();
44
150
  }
151
+ (_a = rest.onKeyPress ?? childProps.onKeyPress) == null ? void 0 : _a(event);
45
152
  };
46
153
  return /* @__PURE__ */ jsx(Fragment, { children: React.isValidElement(children) && React.cloneElement(children, {
47
154
  ...rest,
48
- // @ts-ignore
49
- value: rest.value === void 0 ? null : rest.value,
50
- onChange: handleChange
155
+ value: draft !== void 0 ? draft : rest.value === void 0 ? null : rest.value,
156
+ onChange: onInputChange,
157
+ onCompositionStart,
158
+ onCompositionEnd,
159
+ onKeyPress
51
160
  }) });
52
161
  };
53
162
  var ConfirmWrapper_default = ConfirmWrapper;
@@ -279,7 +279,17 @@ const Render = (props) => {
279
279
  const internalItemRender = {
280
280
  mark: "pro_table_render",
281
281
  render: (inputProps, doms) => /* @__PURE__ */ jsxs(Fragment, { children: [
282
- /* @__PURE__ */ jsx(Space, { size: 0, style: { marginTop: 8 }, children: formItemProps.above }),
282
+ /* @__PURE__ */ jsx(
283
+ Space,
284
+ {
285
+ size: 0,
286
+ style: {
287
+ marginTop: 8,
288
+ marginBottom: type === "ProUpload" && lastComponentProps.uploadType === "image" ? 8 : void 0
289
+ },
290
+ children: formItemProps.above
291
+ }
292
+ ),
283
293
  /* @__PURE__ */ jsxs(
284
294
  "div",
285
295
  {
@@ -5,6 +5,7 @@ import { SortableContext, rectSortingStrategy } from "@dnd-kit/sortable";
5
5
  import { CloudUploadOutlined } from "@ant-design/icons";
6
6
  import { FileItem } from "./FileItem";
7
7
  import { DraggableUploadListItem } from "./DraggableUploadListItem";
8
+ import { isEmptyReactNode } from "../../utils";
8
9
  import locale from "../../locale";
9
10
  const ButtonRender = (props) => {
10
11
  var _a, _b;
@@ -46,13 +47,14 @@ const ButtonRender = (props) => {
46
47
  ) });
47
48
  }
48
49
  };
50
+ const tipText = typeof extraTipText === "function" ? extraTipText() : extraTipText;
49
51
  return /* @__PURE__ */ jsxs("div", { className: "pro-upload-button", children: [
50
52
  /* @__PURE__ */ jsx(DndContext, { sensors: [sensor], onDragEnd, children: /* @__PURE__ */ jsx(SortableContext, { items: fileList.map((i) => i.uid), strategy: rectSortingStrategy, children: /* @__PURE__ */ jsx(Upload, { ...buttonUploadProps, children: !isView && /* @__PURE__ */ jsxs("div", { className: "pro-upload-button-inner", children: [
51
53
  /* @__PURE__ */ jsxs(Button, { ...buttonProps, disabled: disabled || isView, children: [
52
54
  /* @__PURE__ */ jsx(CloudUploadOutlined, {}),
53
55
  buttonText
54
56
  ] }),
55
- afterRender ? /* @__PURE__ */ jsx(
57
+ !isEmptyReactNode(afterRender) ? /* @__PURE__ */ jsx(
56
58
  "div",
57
59
  {
58
60
  className: "pro-upload-button-inner-right",
@@ -61,7 +63,7 @@ const ButtonRender = (props) => {
61
63
  }
62
64
  ) : null
63
65
  ] }) }) }) }),
64
- extraTipText && /* @__PURE__ */ jsx("div", { className: "upload-tip-txt", children: typeof extraTipText === "function" ? extraTipText() : extraTipText })
66
+ !isEmptyReactNode(tipText) && /* @__PURE__ */ jsx("div", { className: "upload-tip-txt", children: tipText })
65
67
  ] });
66
68
  };
67
69
  var ButtonRender_default = ButtonRender;
@@ -6,6 +6,7 @@ import { SortableContext, rectSortingStrategy } from "@dnd-kit/sortable";
6
6
  import { CloudUploadOutlined } from "@ant-design/icons";
7
7
  import { DragSingleFileItem, FileItem, getFileExt, getFileIcon } from "./FileItem";
8
8
  import { DraggableUploadListItem } from "./DraggableUploadListItem";
9
+ import { isEmptyReactNode } from "../../utils";
9
10
  import locale from "../../locale";
10
11
  const { Dragger } = Upload;
11
12
  const DragRender = (props) => {
@@ -88,9 +89,11 @@ const DragRender = (props) => {
88
89
  disabled,
89
90
  openFileDialogOnClick: !showDraggerSingleRender
90
91
  };
92
+ const header = headerRender();
93
+ const footer = footerRender();
91
94
  return /* @__PURE__ */ jsxs("div", { className: "pro-upload-dragger", children: [
92
95
  /* @__PURE__ */ jsxs("div", { className: "pro-upload-handle-box", children: [
93
- /* @__PURE__ */ jsx("div", { className: "pro-upload-dragger-header", children: headerRender() }),
96
+ !isEmptyReactNode(header) && /* @__PURE__ */ jsx("div", { className: "pro-upload-dragger-header", children: header }),
94
97
  /* @__PURE__ */ jsx(Dragger, { ...dragUploadProps, children: /* @__PURE__ */ jsxs("div", { className: "drag-upload-inner", ref: refReSelect, children: [
95
98
  !showDraggerSingleRender && /* @__PURE__ */ jsxs("div", { className: "upload-dragger-control", children: [
96
99
  /* @__PURE__ */ jsxs("div", { className: "dragger-txt-line1", children: [
@@ -108,11 +111,11 @@ const DragRender = (props) => {
108
111
  ":",
109
112
  extExt.length > 0 ? extExt.join("、") : `${(_h = (_g = locale) == null ? void 0 : _g.ProUpload) == null ? void 0 : _h.draggerLimitless}`
110
113
  ] }),
111
- customTextRender && /* @__PURE__ */ jsx("p", { className: "file-ext", children: customTextRender })
114
+ !isEmptyReactNode(customTextRender) && /* @__PURE__ */ jsx("p", { className: "file-ext", children: customTextRender })
112
115
  ] }),
113
116
  /* @__PURE__ */ jsx("div", { className: "dragger-file-show", children: showDraggerSingleRender && draggerSingleRender(fileList[0]) })
114
117
  ] }) }),
115
- /* @__PURE__ */ jsx("div", { className: "pro-upload-dragger-footer", children: footerRender() })
118
+ !isEmptyReactNode(footer) && /* @__PURE__ */ jsx("div", { className: "pro-upload-dragger-footer", children: footer })
116
119
  ] }),
117
120
  /* @__PURE__ */ jsx("div", { className: "pro-upload-file-list", children: /* @__PURE__ */ jsx(DndContext, { sensors: [sensor], onDragEnd, children: /* @__PURE__ */ jsx(SortableContext, { items: fileList.map((i) => i.uid), strategy: rectSortingStrategy, children: maxCount > 1 && fileList.map((file) => {
118
121
  return /* @__PURE__ */ jsx(DraggableUploadListItem, { file, children: /* @__PURE__ */ jsx(
@@ -9,6 +9,7 @@ import { PlusOutlined } from "@ant-design/icons";
9
9
  import { Example } from "./Example";
10
10
  import { getFileExt, getFileIcon } from "./FileItem";
11
11
  import { DraggableUploadListItem } from "./DraggableUploadListItem";
12
+ import { isEmptyReactNode } from "../../utils";
12
13
  import lookSvg from "../../assets/look.svg";
13
14
  import deleteSvg from "../../assets/delete.svg";
14
15
  import downloadSvg from "../../assets/download.svg";
@@ -149,31 +150,37 @@ const ImageRender = (props) => {
149
150
  ) });
150
151
  }
151
152
  };
152
- return /* @__PURE__ */ jsxs(Space, { orientation: "vertical", size: 8, className: "pro-upload-image", children: [
153
- headerRender(),
154
- /* @__PURE__ */ jsxs("div", { className: "pro-upload-image", children: [
155
- /* @__PURE__ */ jsx(DndContext, { sensors: [sensor], onDragEnd, children: /* @__PURE__ */ jsx(SortableContext, { items: fileList.map((i) => i.uid), strategy: rectSortingStrategy, children: /* @__PURE__ */ jsx(Upload, { ...imageUploadProps, children: fileList.length < maxCount && !isView && (centerRender ? isFunction(centerRender) ? centerRender() : centerRender : /* @__PURE__ */ jsxs(
156
- "div",
157
- {
158
- className: `pro-upload-image-inner ${disabled ? "pro-upload-image-disabled" : ""} `,
159
- children: [
160
- /* @__PURE__ */ jsx(PlusOutlined, {}),
161
- /* @__PURE__ */ jsx("div", { style: { marginTop: 8 }, children: (_b = (_a = locale) == null ? void 0 : _a.ProUpload) == null ? void 0 : _b.buttonText })
162
- ]
163
- }
164
- )) }) }) }),
165
- showExampleContent && !isView && /* @__PURE__ */ jsx(
166
- Example,
167
- {
168
- className: "image-example",
169
- exampleTitle,
170
- exampleContent,
171
- exampleModalProps
172
- }
173
- ),
174
- extraTipText && /* @__PURE__ */ jsx("div", { className: "upload-tip-txt", children: extraTipText })
153
+ const footer = footerRender();
154
+ const hasFooter = !isEmptyReactNode(footer);
155
+ const hasCenterRender = typeof centerRender === "function" || !isEmptyReactNode(centerRender);
156
+ const tipText = typeof extraTipText === "function" ? extraTipText() : extraTipText;
157
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
158
+ /* @__PURE__ */ jsxs(Space, { orientation: "vertical", size: 8, className: "pro-upload-image", children: [
159
+ headerRender(),
160
+ /* @__PURE__ */ jsxs("div", { className: "pro-upload-image", children: [
161
+ /* @__PURE__ */ jsx(DndContext, { sensors: [sensor], onDragEnd, children: /* @__PURE__ */ jsx(SortableContext, { items: fileList.map((i) => i.uid), strategy: rectSortingStrategy, children: /* @__PURE__ */ jsx(Upload, { ...imageUploadProps, children: fileList.length < maxCount && !isView && (hasCenterRender ? isFunction(centerRender) ? centerRender() : centerRender : /* @__PURE__ */ jsxs(
162
+ "div",
163
+ {
164
+ className: `pro-upload-image-inner ${disabled ? "pro-upload-image-disabled" : ""} `,
165
+ children: [
166
+ /* @__PURE__ */ jsx(PlusOutlined, {}),
167
+ /* @__PURE__ */ jsx("div", { style: { marginTop: 8 }, children: (_b = (_a = locale) == null ? void 0 : _a.ProUpload) == null ? void 0 : _b.buttonText })
168
+ ]
169
+ }
170
+ )) }) }) }),
171
+ showExampleContent && !isView && /* @__PURE__ */ jsx(
172
+ Example,
173
+ {
174
+ className: "image-example",
175
+ exampleTitle,
176
+ exampleContent,
177
+ exampleModalProps
178
+ }
179
+ ),
180
+ !isEmptyReactNode(tipText) && /* @__PURE__ */ jsx("div", { className: "upload-tip-txt", children: tipText })
181
+ ] }),
182
+ hasFooter && /* @__PURE__ */ jsx("div", { className: "pro-upload-image-footer", children: footer })
175
183
  ] }),
176
- /* @__PURE__ */ jsx("div", { className: "pro-upload-image-footer", children: footerRender() }),
177
184
  /* @__PURE__ */ jsx(
178
185
  Modal,
179
186
  {
@@ -4,6 +4,11 @@
4
4
  // 将拖拽项的内部层级限制在上传组件内,避免覆盖相邻字段的下拉浮层。
5
5
  isolation: isolate;
6
6
 
7
+ > .pro-upload-image {
8
+ // 图片布局不参与文本基线对齐,避免顶部出现额外行盒留白。
9
+ vertical-align: top;
10
+ }
11
+
7
12
  // display: inline-flex;
8
13
 
9
14
  // 拖拽上传
@@ -1,3 +1,4 @@
1
+ import React from 'react';
1
2
  export declare const customEqualForFunction: (value: any, other: any) => boolean;
2
3
  /**
3
4
  * 兼容 React17/18 的 startTransition。
@@ -10,6 +11,8 @@ export declare function compatStartTransition(cb: () => void): void;
10
11
  * 空值 或者 仅包含空值的数组视为空
11
12
  */
12
13
  export declare const isEmpty: (value: any, emptyValue?: string) => boolean;
14
+ /** 判断 React 节点是否没有可渲染内容,保留数字 0 */
15
+ export declare const isEmptyReactNode: (value: React.ReactNode) => boolean;
13
16
  /**
14
17
  * 生成用于 UI 元素的随机短 ID(非安全用途)
15
18
  */
package/es/utils/index.js CHANGED
@@ -32,6 +32,12 @@ const isEmpty = (value, emptyValue) => {
32
32
  }
33
33
  return false;
34
34
  };
35
+ const isEmptyReactNode = (value) => {
36
+ if (Array.isArray(value)) {
37
+ return value.every(isEmptyReactNode);
38
+ }
39
+ return value === void 0 || value === null || typeof value === "boolean" || value === "";
40
+ };
35
41
  const generateId = () => Math.random().toString(36).slice(-6);
36
42
  const isEllipsisActive = (element) => {
37
43
  if (!element)
@@ -47,5 +53,6 @@ export {
47
53
  customEqualForFunction,
48
54
  generateId,
49
55
  isEllipsisActive,
50
- isEmpty
56
+ isEmpty,
57
+ isEmptyReactNode
51
58
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zat-design/sisyphus-react",
3
- "version": "4.7.0",
3
+ "version": "4.7.2-beta.1",
4
4
  "license": "MIT",
5
5
  "publishConfig": {
6
6
  "access": "public",