@cloudbase/weda-ui 3.6.3 → 3.7.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 (92) hide show
  1. package/dist/configs/components/form-location.d.ts +2 -2
  2. package/dist/configs/components/wd-card.d.ts +14 -14
  3. package/dist/configs/components/wd-card.js +38 -32
  4. package/dist/configs/components/wd-cascader.d.ts +276 -0
  5. package/dist/configs/components/wd-cascader.js +183 -0
  6. package/dist/configs/components/wd-code-editor.d.ts +245 -0
  7. package/dist/configs/components/wd-code-editor.js +92 -0
  8. package/dist/configs/components/wd-form-arr.d.ts +193 -0
  9. package/dist/configs/components/wd-form-arr.js +206 -0
  10. package/dist/configs/components/wd-form-obj.d.ts +181 -0
  11. package/dist/configs/components/wd-form-obj.js +107 -0
  12. package/dist/configs/components/wd-form.d.ts +2 -2
  13. package/dist/configs/components/wd-image.js +1 -1
  14. package/dist/configs/components/wd-table.d.ts +3 -3
  15. package/dist/configs/components/wd-upload-file.d.ts +1 -0
  16. package/dist/configs/components/wd-upload-file.js +4 -1
  17. package/dist/configs/components/wd-upload-image.d.ts +2 -0
  18. package/dist/configs/components/wd-upload-image.js +4 -1
  19. package/dist/configs/components/web-view.d.ts +20 -1
  20. package/dist/configs/components/web-view.js +22 -1
  21. package/dist/configs/index.d.ts +1604 -28
  22. package/dist/configs/index.js +8 -0
  23. package/dist/configs/type-utils/type-form.d.ts +22 -0
  24. package/dist/configs/type-utils/type-form.js +58 -1
  25. package/dist/configs/type-utils/x-runtime-default.d.ts +3 -0
  26. package/dist/configs/type-utils/x-runtime-default.js +3 -0
  27. package/dist/enum/index.d.ts +8 -0
  28. package/dist/enum/index.js +11 -0
  29. package/dist/style/index.scss +1 -1
  30. package/dist/web/components/container/index.js +49 -1
  31. package/dist/web/components/form/uploader/uploader.h5.js +3 -3
  32. package/dist/web/components/form/uploader/uploader.pc.js +3 -3
  33. package/dist/web/components/form-input-hooks/index.js +14 -7
  34. package/dist/web/components/form-input-hooks/validator.js +2 -2
  35. package/dist/web/components/form-location/index.d.ts +1 -1
  36. package/dist/web/components/index.d.ts +4 -0
  37. package/dist/web/components/index.js +6 -0
  38. package/dist/web/components/richTextView/index.css +2 -1
  39. package/dist/web/components/wd-cascader/cascader.d.ts +6 -0
  40. package/dist/web/components/wd-cascader/cascader.h5.d.ts +2 -0
  41. package/dist/web/components/wd-cascader/cascader.h5.js +132 -0
  42. package/dist/web/components/wd-cascader/cascader.js +97 -0
  43. package/dist/web/components/wd-cascader/index.d.ts +4 -0
  44. package/dist/web/components/wd-cascader/index.js +3 -0
  45. package/dist/web/components/wd-cascader/interface.d.ts +26 -0
  46. package/dist/web/components/wd-cascader/interface.js +1 -0
  47. package/dist/web/components/wd-cascader/utils.d.ts +6 -0
  48. package/dist/web/components/wd-cascader/utils.js +63 -0
  49. package/dist/web/components/wd-code-editor/index.d.ts +3 -0
  50. package/dist/web/components/wd-code-editor/index.js +3 -0
  51. package/dist/web/components/wd-code-editor/lang/index.d.ts +17 -0
  52. package/dist/web/components/wd-code-editor/lang/index.js +21 -0
  53. package/dist/web/components/wd-code-editor/lang/mongodb/complete.d.ts +8 -0
  54. package/dist/web/components/wd-code-editor/lang/mongodb/complete.js +222 -0
  55. package/dist/web/components/wd-code-editor/lang/mongodb/index.d.ts +2 -0
  56. package/dist/web/components/wd-code-editor/lang/mongodb/index.js +60 -0
  57. package/dist/web/components/wd-code-editor/lang/mongodb/snippets.d.ts +6 -0
  58. package/dist/web/components/wd-code-editor/lang/mongodb/snippets.js +189 -0
  59. package/dist/web/components/wd-code-editor/theme.d.ts +4 -0
  60. package/dist/web/components/wd-code-editor/theme.js +5 -0
  61. package/dist/web/components/wd-code-editor/wd-code-editor.d.ts +9 -0
  62. package/dist/web/components/wd-code-editor/wd-code-editor.js +66 -0
  63. package/dist/web/components/wd-date/elements/Modal.h5.d.ts +2 -0
  64. package/dist/web/components/wd-date/elements/Modal.h5.js +4 -2
  65. package/dist/web/components/wd-form/form-utils.js +1 -1
  66. package/dist/web/components/wd-form/index.d.ts +4 -4
  67. package/dist/web/components/wd-form-arr/index.d.ts +4 -0
  68. package/dist/web/components/wd-form-arr/index.js +3 -0
  69. package/dist/web/components/wd-form-arr/wd-form-arr.d.ts +8 -0
  70. package/dist/web/components/wd-form-arr/wd-form-arr.js +6 -0
  71. package/dist/web/components/wd-form-item/wd-form-item.js +3 -3
  72. package/dist/web/components/wd-form-obj/base-form-obj.d.ts +13 -0
  73. package/dist/web/components/wd-form-obj/base-form-obj.js +351 -0
  74. package/dist/web/components/wd-form-obj/index.d.ts +4 -0
  75. package/dist/web/components/wd-form-obj/index.js +3 -0
  76. package/dist/web/components/wd-form-obj/wd-form-obj.d.ts +9 -0
  77. package/dist/web/components/wd-form-obj/wd-form-obj.js +7 -0
  78. package/dist/web/components/wd-input/wd-input.d.ts +2 -2
  79. package/dist/web/components/wd-input-phone/wd-input-phone.js +2 -2
  80. package/dist/web/components/wd-table/utils/index.js +20 -8
  81. package/dist/web/components/wd-table/wd-table.js +4 -2
  82. package/dist/web/components/wd-tabs/tabs.d.ts +1 -1
  83. package/dist/web/components/wd-textarea/calcTextareaHeight.d.ts +1 -0
  84. package/dist/web/components/wd-textarea/calcTextareaHeight.js +45 -0
  85. package/dist/web/components/wd-textarea/wd-textarea.js +4 -6
  86. package/dist/web/components/wd-unified-link/index.js +2 -2
  87. package/dist/web/components/web-view/web-view.js +15 -4
  88. package/dist/web/utils/tool.d.ts +1 -0
  89. package/dist/web/utils/tool.js +4 -1
  90. package/dist/web/utils/widget-api/index.d.ts +20 -0
  91. package/dist/web/utils/widget-api/index.js +14 -0
  92. package/package.json +8 -1
@@ -0,0 +1,3 @@
1
+ import { WdFormArr } from './wd-form-arr';
2
+ export { WdFormArr } from './wd-form-arr';
3
+ export default WdFormArr;
@@ -0,0 +1,8 @@
1
+ import React from 'react';
2
+ import type { CommonPropsType } from '../../types';
3
+ import type { DataType } from '../../../configs/components/wd-form-arr';
4
+ export declare const WdFormArr: React.ForwardRefExoticComponent<WdFormArrProps & React.RefAttributes<any>>;
5
+ export interface WdFormArrProps extends CommonPropsType, DataType {
6
+ disabled: boolean;
7
+ readOnly: boolean;
8
+ }
@@ -0,0 +1,6 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { forwardRef } from 'react';
3
+ import { BaseFormObj } from '../wd-form-obj/base-form-obj';
4
+ export const WdFormArr = forwardRef(function WdFormArr(props, ref) {
5
+ return _jsx(BaseFormObj, { objType: "arr", ...props, ref: ref });
6
+ });
@@ -1,4 +1,4 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  import classNames from '../../utils/classnames';
3
3
  import { useConfig } from '../../utils/config-context';
4
4
  import { WdIcon } from '../wd-icon';
@@ -11,7 +11,7 @@ import { X_RUNTIME_DEFAULT } from '../../../configs/type-utils/x-runtime-default
11
11
  * 表单项包裹,包括标题、文本提示、校验
12
12
  */
13
13
  export function WdFormItem(props) {
14
- const { id, className, style, label, labelVisible = X_RUNTIME_DEFAULT.labelVisible, labelTips = X_RUNTIME_DEFAULT.labelTips, labelWidth: _labelWidth = X_RUNTIME_DEFAULT.labelWidth, labelWrap = X_RUNTIME_DEFAULT.labelWrap, extra = X_RUNTIME_DEFAULT.extra, required = X_RUNTIME_DEFAULT.required, readOnly, children, testId, requiredFlag = X_RUNTIME_DEFAULT.requiredFlag, validateState, validateErrorMsg, readValue, borderedH5 = X_RUNTIME_DEFAULT.borderedH5, borderedPc = X_RUNTIME_DEFAULT.borderedPc, classRoot, controlAlign, inputId, isWdFormDetail, before, after, readBeforeAfter = true, visible = true, } = props;
14
+ const { id, className, style, label, labelVisible = X_RUNTIME_DEFAULT.labelVisible, labelTips = X_RUNTIME_DEFAULT.labelTips, labelWidth: _labelWidth = X_RUNTIME_DEFAULT.labelWidth, labelWrap = X_RUNTIME_DEFAULT.labelWrap, extra = X_RUNTIME_DEFAULT.extra, required = X_RUNTIME_DEFAULT.required, readOnly, children, testId, requiredFlag = X_RUNTIME_DEFAULT.requiredFlag, validateState, validateErrorMsg, readValue, borderedH5 = X_RUNTIME_DEFAULT.borderedH5, borderedPc = X_RUNTIME_DEFAULT.borderedPc, classRoot, controlAlign, inputId, isWdFormDetail, before, after, readBeforeAfter = true, visible = true, LabelContainer = null, } = props;
15
15
  const { classPrefix } = useConfig();
16
16
  const platform = usePlatform();
17
17
  const labelAlign = useLabelAlign(props);
@@ -62,5 +62,5 @@ export function WdFormItem(props) {
62
62
  const Message = validateErrorMsg && (_jsx("p", { className: `${item}__help`, children: _jsx("span", { className: `${classPrefix}-g-text-${validateState} ${root}__error`, children: textToString(validateErrorMsg) }) }));
63
63
  if (!visible)
64
64
  return null;
65
- return (_jsxs("div", { className: cls, id: id, style: style, children: [_jsxs("div", { className: itemWrap, children: [Label, Item] }), Message, Help] }));
65
+ return (_jsxs("div", { className: cls, id: id, style: style, children: [_jsx("div", { className: itemWrap, children: LabelContainer ? (_jsx(LabelContainer, { Label: Label, Item: Item })) : (_jsxs(_Fragment, { children: [Label, Item] })) }), Message, Help] }));
66
66
  }
@@ -0,0 +1,13 @@
1
+ import React from 'react';
2
+ import type { CommonPropsType } from '../../types';
3
+ import type { DataType as ObjDataType } from '../../../configs/components/wd-form-obj';
4
+ import type { DataType as ArrDataType } from '../../../configs/components/wd-form-arr';
5
+ import '../style';
6
+ export declare const BaseFormObj: React.ForwardRefExoticComponent<BaseFormObjProps & React.RefAttributes<any>>;
7
+ type DataType = ObjDataType & ArrDataType;
8
+ export interface BaseFormObjProps extends CommonPropsType, DataType {
9
+ disabled: boolean;
10
+ readOnly: boolean;
11
+ objType: 'arr' | 'obj';
12
+ }
13
+ export {};
@@ -0,0 +1,351 @@
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ /* eslint-disable @typescript-eslint/no-magic-numbers */
3
+ import React, { forwardRef, useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState, } from 'react';
4
+ import { useConfig } from '../../utils/config-context';
5
+ import { WdFormItem } from '../wd-form-item';
6
+ import { usePlatform } from '../../utils/platform';
7
+ import classNames from '../../utils/classnames';
8
+ import { FormObjContext, FormObjWidgetContext, useFormObjWidget, } from '../../utils/widget-api';
9
+ import { noop } from '../../utils/constant';
10
+ import lodashSet from 'lodash.set';
11
+ import lodashGet from 'lodash.get';
12
+ import { useFormInputTrait, useParentForm } from '../form-input-hooks';
13
+ import { deepClone } from '../../utils/tool';
14
+ import isObjectEqual from '../../utils/isObjectEqual';
15
+ import { WdIcon } from '../wd-icon';
16
+ import { WdCard } from '../wd-card';
17
+ import '../style';
18
+ import useDebouncedCallback from '../../utils/hooks/use-debounced-callback';
19
+ import { useMap } from '@react-hookz/web';
20
+ import { isNil } from '../../utils/lodash';
21
+ const classRoot = 'form-obj';
22
+ /**
23
+ * 获取待操作的数据路径,嵌套表单中子组件的名称是按lodashSet形式拼接的,在更新嵌套表单值时,要去除掉当前嵌套表单的路径名称
24
+ * @param operateName 待操作的表单项名称
25
+ * @param currentName 当前表单项名称
26
+ * @returns
27
+ */
28
+ const getValueName = (operateName, currentName) => operateName.replace(new RegExp(`^${currentName}(\\.)?`), '');
29
+ const LabelContainer = (props) => {
30
+ const { Label, Item } = props || {};
31
+ const cardRef = React.createRef();
32
+ const [iconName, setIconName] = useState('chevronup');
33
+ const headerSlot = (_jsxs(_Fragment, { children: [_jsx(WdIcon, { name: iconName, events: {
34
+ tap: () => {
35
+ setIconName(iconName === 'chevrondown' ? 'chevronup' : 'chevrondown');
36
+ },
37
+ } }), Label] }));
38
+ return (_jsx(WdCard, { ref: cardRef, className: iconName === 'chevrondown' ? 'wd-card-content__hidden' : '', showContent: true, headerSlot: headerSlot, contentSlot: Item, events: { tap: () => { } } }));
39
+ };
40
+ export const BaseFormObj = forwardRef(function BaseFormObj(props, ref) {
41
+ const { classPrefix } = useConfig();
42
+ const platform = usePlatform();
43
+ const cls = classNames({
44
+ [`${classPrefix}-form-obj`]: true,
45
+ [`${classPrefix}-${platform}-form-obj`]: true,
46
+ [props.className]: true,
47
+ });
48
+ const formItemProps = {
49
+ ...props,
50
+ classRoot,
51
+ LabelContainer,
52
+ };
53
+ const initValue = { arr: [], obj: {} }[props.objType];
54
+ // 嵌套表单状态
55
+ const [status, updateStatus] = useState('edit');
56
+ const [innerHandle, setInnerHandle] = useState({});
57
+ const inputRef = useRef({});
58
+ // 嵌套表单的最终值
59
+ const [objValue, setObjValue] = useState(initValue);
60
+ // 父级普通表单对象
61
+ const parentForm = useParentForm(props.$widget);
62
+ // 父级嵌套表单对象
63
+ const parentFormObj = useFormObjWidget();
64
+ // 嵌套表单内的子组件实例对象集合,在form-input-hooks中会调用addFormItem添加关联上
65
+ const formsItemMap = useMap([]);
66
+ const { name, value, readOnly, disabled, visible,
67
+ // onChange: _onChange,
68
+ } = useFormInputTrait({
69
+ label: props.label,
70
+ value: props.value,
71
+ name: props.name,
72
+ inputRef,
73
+ readOnly: props.readOnly,
74
+ disabled: props.disabled,
75
+ status: props.status,
76
+ required: false,
77
+ requiredMsg: '',
78
+ $widget: props.$widget,
79
+ setInnerHandle,
80
+ onChange: noop,
81
+ $node: props.$node,
82
+ });
83
+ useEffect(() => {
84
+ setObjValue(value || {});
85
+ }, [value]);
86
+ useEffect(() => {
87
+ if (readOnly) {
88
+ updateStatus('readOnly');
89
+ }
90
+ else if (disabled) {
91
+ updateStatus('disabled');
92
+ }
93
+ else {
94
+ updateStatus('edit');
95
+ }
96
+ }, [disabled, readOnly]);
97
+ /**
98
+ * 对外触发嵌套表单的onDataChange事件
99
+ */
100
+ const triggerOnDataChange = useDebouncedCallback(useCallback((value) => {
101
+ var _a, _b;
102
+ (_b = (_a = props.events) === null || _a === void 0 ? void 0 : _a.onDataChange) === null || _b === void 0 ? void 0 : _b.call(_a, { data: value });
103
+ }, [props.events]), 500);
104
+ /**
105
+ * 不在表单容器中使用时,更新子组件值
106
+ */
107
+ const updateChildValue = useDebouncedCallback(useCallback((value) => {
108
+ formsItemMap.forEach((items, childName) => {
109
+ var _a;
110
+ const newValue = lodashGet(value, getValueName(childName, name));
111
+ if (!Array.isArray(items)) {
112
+ items = [items];
113
+ }
114
+ (_a = items === null || items === void 0 ? void 0 : items.forEach) === null || _a === void 0 ? void 0 : _a.call(items, (item) => {
115
+ if (item.setValue && !isObjectEqual(item.value, newValue)) {
116
+ item.setValue(newValue);
117
+ }
118
+ });
119
+ });
120
+ }, [formsItemMap, name]), 0);
121
+ const dealArrChange = (params, objValue) => {
122
+ let value;
123
+ // 顶层为数组类型
124
+ if (Array.isArray(objValue) && ['add', 'remove'].includes(params.type)) {
125
+ value = deepClone(objValue);
126
+ // 触发添加操作,则增加一个undefined值
127
+ if (params.type === 'add') {
128
+ value.push({});
129
+ }
130
+ // 触发删除操作,则删除对应索引的值
131
+ if (params.type === 'remove') {
132
+ value = [
133
+ ...value.slice(0, params.value),
134
+ ...value.slice(params.value + 1),
135
+ ];
136
+ }
137
+ }
138
+ return value;
139
+ };
140
+ const dealObjChange = (params, objValue) => {
141
+ var _a;
142
+ let value;
143
+ if ((_a = Object.keys(objValue || {})) === null || _a === void 0 ? void 0 : _a.length) {
144
+ value = deepClone({ ...objValue, ...params.value });
145
+ }
146
+ return value;
147
+ };
148
+ /**
149
+ * 更新值
150
+ * @param params
151
+ * @param param1.isUpdateParentForm 是否更新父级表单,因子组件值变化调用change时不去触发父表单的更新,因为子组件自己会触发;因为外部设置了值,则触发父表单更新
152
+ * @param param1.isUpdateChildValue 是否更新子组件值, 因子组件值变化调用change时不去触发updateChildValueWithoutForm;因为外部设置了值,则触发updateChildValueWithoutForm去更新子组件值
153
+ * @returns
154
+ */
155
+ const change = useCallback((params, { isUpdateParentForm = false, isUpdateChildValue = true } = {}) => {
156
+ var _a, _b, _c;
157
+ let value = deepClone(params.value);
158
+ if (props.objType === 'arr') {
159
+ value = dealArrChange(params, objValue) || value;
160
+ }
161
+ // 如果有更新标识,则按标识路径更新值
162
+ if (params.name) {
163
+ value = deepClone(objValue);
164
+ lodashSet(value, getValueName(params.name, name), params.value);
165
+ }
166
+ else if (props.objType === 'obj') {
167
+ value = dealObjChange(params, objValue) || value;
168
+ }
169
+ if (isObjectEqual(value, objValue)) {
170
+ return;
171
+ }
172
+ setObjValue(value || initValue);
173
+ if (isUpdateChildValue) {
174
+ // 外部设置数据,同时去更新子组件的值
175
+ updateChildValue(value);
176
+ }
177
+ if (isUpdateParentForm) {
178
+ // 触发父级普通表单值更新
179
+ (_a = parentForm === null || parentForm === void 0 ? void 0 : parentForm.__setValueImmediate__) === null || _a === void 0 ? void 0 : _a.call(parentForm, { [name]: value }, false, true);
180
+ }
181
+ if (params.name) {
182
+ // 触发父级嵌套表单值更新
183
+ (_b = parentFormObj === null || parentFormObj === void 0 ? void 0 : parentFormObj.__setValueImmediate__) === null || _b === void 0 ? void 0 : _b.call(parentFormObj, {
184
+ name: params.name,
185
+ value: params.value,
186
+ });
187
+ }
188
+ else if (parentFormObj === null || parentFormObj === void 0 ? void 0 : parentFormObj.formObjName) {
189
+ // 外部直接调用formObj.setValue的情况下,触发父级嵌套表单值更新
190
+ (_c = parentFormObj === null || parentFormObj === void 0 ? void 0 : parentFormObj.__setValueImmediate__) === null || _c === void 0 ? void 0 : _c.call(parentFormObj, { name, value });
191
+ }
192
+ triggerOnDataChange(value);
193
+ },
194
+ // eslint-disable-next-line react-hooks/exhaustive-deps
195
+ [
196
+ objValue,
197
+ updateChildValue,
198
+ name,
199
+ parentFormObj,
200
+ triggerOnDataChange,
201
+ parentForm,
202
+ props.objType,
203
+ ]);
204
+ /**
205
+ * 子组件默认值变更,触发嵌套表单值更新
206
+ */
207
+ const changeByChildFormObj = useCallback((params) => {
208
+ var _a, _b;
209
+ const value = deepClone(objValue);
210
+ lodashSet(value, getValueName(params.name, name), params.value);
211
+ if (isObjectEqual(value, objValue)) {
212
+ return;
213
+ }
214
+ if (params.name) {
215
+ // 将值同步给父级嵌套表单
216
+ (_a = parentFormObj === null || parentFormObj === void 0 ? void 0 : parentFormObj.__setValueImmediate__) === null || _a === void 0 ? void 0 : _a.call(parentFormObj, {
217
+ name: params.name,
218
+ value: params.value,
219
+ });
220
+ }
221
+ else if (parentFormObj === null || parentFormObj === void 0 ? void 0 : parentFormObj.formObjName) {
222
+ // 外部直接调用formObj.setValue的情况下,触发父级嵌套表单值更新
223
+ (_b = parentFormObj === null || parentFormObj === void 0 ? void 0 : parentFormObj.__setValueImmediate__) === null || _b === void 0 ? void 0 : _b.call(parentFormObj, { name, value });
224
+ }
225
+ setObjValue(value || initValue);
226
+ },
227
+ // eslint-disable-next-line react-hooks/exhaustive-deps
228
+ [objValue, name, parentFormObj]);
229
+ useLayoutEffect(() => {
230
+ if (!ref)
231
+ return;
232
+ ref.current = {
233
+ ...innerHandle,
234
+ /**
235
+ * 外部直接set嵌入表单的值
236
+ * @param value
237
+ */
238
+ setValue: (value) => {
239
+ change({ name: '', value }, { isUpdateParentForm: true });
240
+ },
241
+ getValue() {
242
+ return objValue;
243
+ },
244
+ getConfig() {
245
+ return {
246
+ componentType: 'formObj',
247
+ };
248
+ },
249
+ methods: {
250
+ ...(props.objType === 'arr'
251
+ ? {
252
+ add: () => {
253
+ change({ type: 'add' }, { isUpdateParentForm: false });
254
+ },
255
+ remove: ({ index = -1 } = {}) => {
256
+ change({ type: 'remove', value: index }, { isUpdateParentForm: false });
257
+ },
258
+ }
259
+ : {}),
260
+ change: (params) => {
261
+ change(params, { isUpdateParentForm: true });
262
+ },
263
+ },
264
+ label: props.label,
265
+ name: name,
266
+ value: objValue,
267
+ visible,
268
+ disabled,
269
+ readOnly,
270
+ };
271
+ // eslint-disable-next-line react-hooks/exhaustive-deps
272
+ }, [
273
+ innerHandle,
274
+ props.label,
275
+ name,
276
+ objValue,
277
+ visible,
278
+ disabled,
279
+ readOnly,
280
+ change,
281
+ props.objType,
282
+ ]);
283
+ const formObjWidgetContextProvider = useMemo(() => {
284
+ return {
285
+ formObjName: name,
286
+ /**
287
+ * 用于同步子组件的默认值
288
+ * @param params
289
+ */
290
+ __setValueImmediate__(params) {
291
+ changeByChildFormObj(params);
292
+ },
293
+ };
294
+ }, [changeByChildFormObj, name]);
295
+ const formObjContextProvider = useMemo(() => {
296
+ return {
297
+ formObjName: name,
298
+ status,
299
+ /**
300
+ * 嵌套表单内部子组件值改变时,触发嵌套表单组件的值更新
301
+ * @param params.name 子组件名称
302
+ * @param params.value 子组件值
303
+ */
304
+ valueChangeFromChild: (params = {}) => {
305
+ if (!params.name)
306
+ return;
307
+ // 由于是子组件值变更触发,所以嵌套表单值更新后不再次触发子组件值变更
308
+ change(params, { isUpdateChildValue: false });
309
+ },
310
+ /**
311
+ * 收集嵌套表单内的子组件实例,以便嵌套表单值变化时,主动触发子组件值更新
312
+ * @param childName 子组件名称
313
+ * @param formItem 子组件$widget
314
+ * @returns
315
+ */
316
+ addFormItem(childName, formItem) {
317
+ if (isNil(childName) ||
318
+ !formItem ||
319
+ (typeof childName === 'string' && childName.length === 0)) {
320
+ // childName 没设置或为空串的时候不受表单容器控制
321
+ console.warn(`组件 #${formItem === null || formItem === void 0 ? void 0 : formItem.id} 表单key(表单输入类组件 childName 属性)没设置或为空串的时候不受表单容器控制`);
322
+ return noop;
323
+ }
324
+ if (formsItemMap.has(childName)) {
325
+ formsItemMap.get(childName).push(formItem);
326
+ }
327
+ else {
328
+ formsItemMap.set(childName, [formItem]);
329
+ }
330
+ return () => {
331
+ const items = formsItemMap.get(childName);
332
+ const removedArr = items.filter((item) => item !== formItem);
333
+ if (removedArr.length <= 0) {
334
+ formsItemMap.delete(childName);
335
+ }
336
+ else {
337
+ formsItemMap.set(childName, removedArr);
338
+ }
339
+ };
340
+ },
341
+ };
342
+ }, [change, formsItemMap, name, status]);
343
+ useEffect(() => {
344
+ // 如果是最顶层的嵌套表单,则去更新子组件的值,否则自己的值更新不去触发子组件值更新,因为父级普通表单会去更新
345
+ if (!parentFormObj) {
346
+ updateChildValue(objValue);
347
+ }
348
+ // eslint-disable-next-line react-hooks/exhaustive-deps
349
+ }, [objValue, parentFormObj]);
350
+ return (_jsx(WdFormItem, { ...formItemProps, children: _jsx(FormObjWidgetContext.Provider, { value: formObjWidgetContextProvider, children: _jsx(FormObjContext.Provider, { value: formObjContextProvider, children: _jsx("fieldset", { className: cls, id: props.id, style: props.style, role: "container", "data-testid": "formObj", children: props.children }) }) }) }));
351
+ });
@@ -0,0 +1,4 @@
1
+ import { WdFormObj } from './wd-form-obj';
2
+ export { WdFormObj } from './wd-form-obj';
3
+ export type { WdFormObjProps } from './wd-form-obj';
4
+ export default WdFormObj;
@@ -0,0 +1,3 @@
1
+ import { WdFormObj } from './wd-form-obj';
2
+ export { WdFormObj } from './wd-form-obj';
3
+ export default WdFormObj;
@@ -0,0 +1,9 @@
1
+ import React from 'react';
2
+ import type { CommonPropsType } from '../../types';
3
+ import type { DataType } from '../../../configs/components/wd-form-arr';
4
+ import '../style';
5
+ export declare const WdFormObj: React.ForwardRefExoticComponent<WdFormObjProps & React.RefAttributes<any>>;
6
+ export interface WdFormObjProps extends CommonPropsType, DataType {
7
+ disabled: boolean;
8
+ readOnly: boolean;
9
+ }
@@ -0,0 +1,7 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { forwardRef } from 'react';
3
+ import '../style';
4
+ import { BaseFormObj } from './base-form-obj';
5
+ export const WdFormObj = forwardRef(function WdFormObj(props, ref) {
6
+ return _jsx(BaseFormObj, { objType: "obj", ...props, ref: ref });
7
+ });
@@ -81,10 +81,10 @@ export declare const WdInput: React.ForwardRefExoticComponent<CommonPropsType &
81
81
  }]>> & {
82
82
  wrapClassName?: string;
83
83
  classRoot?: string;
84
- inputPattern?: string;
84
+ inputPattern?: RegExp;
85
85
  } & React.RefAttributes<any>>;
86
86
  export type WdInputProps = CommonPropsType & DataType & EventsType & {
87
87
  wrapClassName?: string;
88
88
  classRoot?: string;
89
- inputPattern?: string;
89
+ inputPattern?: RegExp;
90
90
  };
@@ -9,6 +9,6 @@ const rules = [{ format: 'mobile', message: '手机校验失败' }];
9
9
  export const WdInputPhone = forwardRef(function WdInputPhone(props, ref) {
10
10
  const { classPrefix } = useConfig();
11
11
  const wrapCls = `${classPrefix}-form-input-number-wrap `;
12
- const pattern = '^[0-9\\-]{0,11}$';
13
- return (_jsx(WdInput, { ...props, inputPattern: pattern, maxLength: 11, wrapClassName: wrapCls, classRoot: "input-phone", rules: rules, ref: ref }));
12
+ const pattern = /^[()\d\s+-ext]{0,20}$/;
13
+ return (_jsx(WdInput, { ...props, inputPattern: pattern, maxLength: 20, wrapClassName: wrapCls, classRoot: "input-phone", rules: rules, ref: ref }));
14
14
  });
@@ -184,19 +184,22 @@ const getSearchValues = (searchValues) => {
184
184
  };
185
185
  });
186
186
  };
187
- const getPageParam = (_sort, params, _defaultPageSize, _defaultPageIndex, supportManyRelated, columns, isSupportMultipleSort) => {
187
+ const getPageParam = ({ defaultSort, sort: _sort, params, _defaultPageSize, _defaultPageIndex, supportManyRelated, columns, isSupportMultipleSort, }) => {
188
+ let sort = defaultSort;
189
+ // 运行态有值,以运行态为准
190
+ if ((_sort === null || _sort === void 0 ? void 0 : _sort.length) && _sort[0].order) {
191
+ params.orderBy = _sort[0].by;
192
+ params.orderType = _sort[0].order;
193
+ sort = _sort;
194
+ }
188
195
  // 后端根据业务字段排序
189
- const sort = _sort.map((n) => {
196
+ sort = sort.map((n) => {
190
197
  var _a;
191
198
  return ({
192
199
  ...n,
193
200
  by: ((_a = columns === null || columns === void 0 ? void 0 : columns.find((i) => n.by === i.slotKey)) === null || _a === void 0 ? void 0 : _a.fieldKey) || n.by,
194
201
  });
195
202
  });
196
- if ((sort === null || sort === void 0 ? void 0 : sort.length) && sort[0].order) {
197
- params.orderBy = sort[0].by;
198
- params.orderType = sort[0].order;
199
- }
200
203
  const _pageSize = parseInt(`${params.pageSize}`);
201
204
  params.pageSize = isNaN(_pageSize) ? _defaultPageSize : _pageSize;
202
205
  const _pageNo = parseInt(`${params.pageNo}`);
@@ -219,7 +222,7 @@ export const getQueryParams = ({ queryParams, wList, viewFieldsData, connectorPa
219
222
  var _a, _b;
220
223
  const _defaultPageSize = 10;
221
224
  const _defaultPageIndex = 1;
222
- const { pageIndex: pageNo, pageSize, sort } = queryParams;
225
+ const { pageIndex: pageNo, pageSize, sort, defaultSort } = queryParams;
223
226
  let params = {
224
227
  pageNo,
225
228
  pageSize,
@@ -266,7 +269,16 @@ export const getQueryParams = ({ queryParams, wList, viewFieldsData, connectorPa
266
269
  params = Object.assign({}, connectorParams, params);
267
270
  }
268
271
  // 运行态主动排序进行覆盖
269
- params = getPageParam(sort, params, _defaultPageSize, _defaultPageIndex, supportManyRelated, columns, isSupportMultipleSort);
272
+ params = getPageParam({
273
+ defaultSort,
274
+ sort,
275
+ params,
276
+ _defaultPageSize,
277
+ _defaultPageIndex,
278
+ supportManyRelated,
279
+ columns,
280
+ isSupportMultipleSort,
281
+ });
270
282
  return params;
271
283
  };
272
284
  // 获取视图
@@ -151,10 +151,11 @@ export const WdTable = forwardRef(function TableComp(tableProps, ref) {
151
151
  const [queryParams, setQueryParams] = useState({
152
152
  pageIndex: initPageIndex,
153
153
  pageSize: initPageSize,
154
- sort: _sort,
154
+ sort: [],
155
155
  searchValues: [],
156
156
  orderBy,
157
157
  orderType,
158
+ defaultSort: _sort,
158
159
  });
159
160
  const columnSetsKey = columnSets === null || columnSets === void 0 ? void 0 : columnSets.map((i) => i.key);
160
161
  // 过滤权限字段
@@ -629,7 +630,8 @@ export const WdTable = forwardRef(function TableComp(tableProps, ref) {
629
630
  pageSize: defaultPageSize,
630
631
  orderBy: orderBy,
631
632
  orderType: orderType,
632
- sort: _sort,
633
+ defaultSort: _sort,
634
+ sort: [],
633
635
  }));
634
636
  }
635
637
  else {
@@ -9,5 +9,5 @@ export interface WdTabsProps extends CommonPropsType {
9
9
  selected?: boolean;
10
10
  }[];
11
11
  direction: string;
12
- getIndex: (val: number) => void;
12
+ getIndex?: (val: number) => void;
13
13
  }
@@ -0,0 +1 @@
1
+ export declare function getHeight(id: any): number | "auto";
@@ -0,0 +1,45 @@
1
+ const HIDDEN_TEXTAREA_STYLE = `
2
+ min-height:0 !important;
3
+ max-height:none !important;
4
+ height:0 !important;
5
+ visibility:hidden !important;
6
+ overflow-y:hidden !important;
7
+ position:absolute !important;
8
+ z-index:-1000 !important;
9
+ top:0 !important;
10
+ right:0 !important
11
+ `;
12
+ const SIZING_PROPS = [
13
+ 'letter-spacing',
14
+ 'line-height',
15
+ 'padding-top',
16
+ 'padding-bottom',
17
+ 'font-family',
18
+ 'font-weight',
19
+ 'font-size',
20
+ 'font-variant',
21
+ 'text-rendering',
22
+ 'text-transform',
23
+ 'width',
24
+ 'text-indent',
25
+ 'padding-left',
26
+ 'padding-right',
27
+ 'border-width',
28
+ 'box-sizing',
29
+ ];
30
+ export function getHeight(id) {
31
+ const textarea = document.getElementById(id);
32
+ if (!textarea)
33
+ return 'auto';
34
+ const style = window.getComputedStyle(textarea);
35
+ const value = textarea.value || textarea.placeholder;
36
+ const sizingStyle = SIZING_PROPS.map((name) => `${name}:${style.getPropertyValue(name)}`).join(';');
37
+ let hiddenText = document.createElement('textarea');
38
+ hiddenText.setAttribute('style', `${sizingStyle};${HIDDEN_TEXTAREA_STYLE}`);
39
+ hiddenText.value = value;
40
+ document.body.appendChild(hiddenText);
41
+ const height = hiddenText.scrollHeight;
42
+ document.body.removeChild(hiddenText);
43
+ hiddenText = null;
44
+ return height;
45
+ }
@@ -7,6 +7,7 @@ import { useFormInputTrait } from '../form-input-hooks';
7
7
  import { filterPropsWithOn, getUuid } from '../../utils/tool';
8
8
  import { useSize } from '../../utils/hooks/useFormLegacy';
9
9
  import { X_RUNTIME_DEFAULT } from '../../../configs/type-utils/x-runtime-default';
10
+ import { getHeight } from './calcTextareaHeight';
10
11
  /**
11
12
  * 标准化:多行输入组件
12
13
  */
@@ -40,16 +41,13 @@ export const WdTextarea = forwardRef(function WdTextarea(props, ref) {
40
41
  const autoScroll = function () {
41
42
  if (!autoHeight || !textareaRef.current)
42
43
  return;
43
- textareaRef.current.style.height = 'auto';
44
- if (textareaRef.current.scrollHeight >= textareaRef.current.offsetHeight) {
45
- textareaRef.current.style.height =
46
- textareaRef.current.scrollHeight + 'px';
47
- }
44
+ const height = getHeight(inputId);
45
+ textareaRef.current.style.height = height + 'px';
48
46
  };
49
47
  useEffect(() => {
50
48
  autoScroll();
51
49
  // eslint-disable-next-line react-hooks/exhaustive-deps
52
- }, [autoHeight]);
50
+ }, [autoHeight, inputId]);
53
51
  /** 内部事件 */
54
52
  const onChange = function (e) {
55
53
  var _a;
@@ -63,7 +63,7 @@ export const WdUnifiedLink = forwardRef(function WdUnifiedLink(props, ref) {
63
63
  (_c = window === null || window === void 0 ? void 0 : window.app) === null || _c === void 0 ? void 0 : _c.navigateTo({
64
64
  pageId,
65
65
  packageName: packageName === 'main' ? '' : packageName,
66
- mode: options.target === '_blank' ? 'web' : 'weDa',
66
+ mode: (options === null || options === void 0 ? void 0 : options.target) === '_blank' ? 'web' : 'weDa',
67
67
  params,
68
68
  });
69
69
  break;
@@ -86,6 +86,6 @@ export const WdUnifiedLink = forwardRef(function WdUnifiedLink(props, ref) {
86
86
  }
87
87
  }
88
88
  };
89
- return (_jsx(ConfigProvider, { classPrefix: "wedatea2td", children: _jsx("a", { href: /https?:\/\//.test(url) ? url : 'javascript:void(0);', rel: "noopener noreferrer", className: classNames(classes, className), id: id, style: style, onClick: onClick, ...options, children: children }) }));
89
+ return (_jsx(ConfigProvider, { classPrefix: "wedatea2td", children: _jsx("a", { href: /https?:\/\//.test(url) ? url : 'javascript:void(0);', rel: "noopener noreferrer", className: classNames(classes, className), id: id, style: style, onClick: onClick, "data-testid": "wd-unified-link", ...options, children: children }) }));
90
90
  });
91
91
  export default WdUnifiedLink;