@cloudbase/weda-ui 3.19.0 → 3.20.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.
- package/dist/configs/components/wd-form.d.ts +2 -2
- package/dist/configs/components/wd-form.js +2 -2
- package/dist/configs/components/wd-table.d.ts +3 -3
- package/dist/configs/index.d.ts +6 -6
- package/dist/configs/type-utils/type-form.d.ts +2 -2
- package/dist/style/weda-ui.min.css +1 -1
- package/dist/web/components/form-input-hooks/index.d.ts +3 -1
- package/dist/web/components/form-input-hooks/index.js +93 -54
- package/dist/web/components/form-rich-text/index.d.ts +3 -3
- package/dist/web/components/form-rich-text/index.js +8 -4
- package/dist/web/components/formdetail/index.d.ts +1 -1
- package/dist/web/components/formdetail/index.js +28 -42
- package/dist/web/components/richText/index.js +9 -3
- package/dist/web/components/wd-form/contexts/form-field-arr-context.d.ts +21 -0
- package/dist/web/components/wd-form/contexts/form-field-arr-context.js +10 -0
- package/dist/web/components/wd-form/contexts/form-field-context.d.ts +19 -0
- package/dist/web/components/wd-form/contexts/form-field-context.js +10 -0
- package/dist/web/components/wd-form/contexts/form-field-obj-context.d.ts +13 -0
- package/dist/web/components/wd-form/contexts/form-field-obj-context.js +10 -0
- package/dist/web/components/wd-form/index.d.ts +4 -4
- package/dist/web/components/wd-form/index.js +142 -191
- package/dist/web/components/wd-form-item/wd-form-item.d.ts +2 -2
- package/dist/web/components/wd-form-item/wd-form-item.js +96 -14
- package/dist/web/components/wd-form-obj/base-form-obj.js +66 -197
- package/dist/web/components/wd-input/wd-input.js +1 -1
- package/dist/web/components/wd-input-number/wd-input-number.js +43 -17
- package/dist/web/components/wd-rich-text/wd-rich-text.d.ts +1 -1
- package/dist/web/components/wd-rich-text/wd-rich-text.js +7 -3
- package/dist/web/components/wd-select/select/selectUI.js +9 -2
- package/dist/web/utils/widget-api/index.d.ts +0 -14
- package/dist/web/utils/widget-api/index.js +0 -7
- package/package.json +1 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { useEffect, forwardRef, useImperativeHandle, useState, useCallback, useRef
|
|
3
|
-
import { useResizeObserver
|
|
2
|
+
import { useEffect, forwardRef, useImperativeHandle, useState, useCallback, useRef } from 'react';
|
|
3
|
+
import { useResizeObserver } from '@react-hookz/web';
|
|
4
4
|
import { WdFormItem } from '../wd-form-item';
|
|
5
5
|
import classNames from '../../utils/classnames';
|
|
6
|
-
import { usePlatform, randomStr
|
|
6
|
+
import { usePlatform, randomStr } from '../../utils/platform';
|
|
7
7
|
import isObjectEqual from '../../utils/isObjectEqual';
|
|
8
8
|
import { useFormInputTrait, useParentForm } from '../form-input-hooks';
|
|
9
9
|
import { FormDetailStatusContext } from '../../utils/widget-api';
|
|
@@ -45,9 +45,7 @@ export const reorderContext = (data, name, isPureArray) => data.map((i, index) =
|
|
|
45
45
|
Object.keys(i).forEach((j) => {
|
|
46
46
|
var _a;
|
|
47
47
|
if ((_a = item[j]) === null || _a === void 0 ? void 0 : _a.name) {
|
|
48
|
-
item[j].name = isPureArray
|
|
49
|
-
? `${name}[${index}]`
|
|
50
|
-
: `${name}[${index}].${j}`;
|
|
48
|
+
item[j].name = isPureArray ? `${name}[${index}]` : `${name}[${index}].${j}`;
|
|
51
49
|
}
|
|
52
50
|
});
|
|
53
51
|
item.index = index;
|
|
@@ -65,7 +63,7 @@ export const newContextItem = (childFormItem, name, isPureArray, parent) => {
|
|
|
65
63
|
});
|
|
66
64
|
return mock;
|
|
67
65
|
};
|
|
68
|
-
export const changeHandle = ({ type, name, data, childFormItem, isPureArray, params, parent
|
|
66
|
+
export const changeHandle = ({ type, name, data, childFormItem, isPureArray, params, parent }) => {
|
|
69
67
|
switch (type) {
|
|
70
68
|
case 'add': {
|
|
71
69
|
const mock = newContextItem(childFormItem, name, isPureArray, parent);
|
|
@@ -118,9 +116,8 @@ const FormDetailCom = forwardRef(function FormDetail(props, ref) {
|
|
|
118
116
|
});
|
|
119
117
|
const tableRef = useRef(null);
|
|
120
118
|
const [isTableView, setIsTableView] = useState(false);
|
|
121
|
-
const [detailValue, setDetailValue] = useState([]);
|
|
119
|
+
const [detailValue, setDetailValue] = useState(props.value || []);
|
|
122
120
|
const [contextData, setContextData] = useState([]);
|
|
123
|
-
const [isInit, setIsInit] = useState(false);
|
|
124
121
|
const [childFormItem, setChildFormItem] = useState([]);
|
|
125
122
|
const [hasScroll, setHasScroll] = useState(false);
|
|
126
123
|
const platform = usePlatform();
|
|
@@ -163,6 +160,9 @@ const FormDetailCom = forwardRef(function FormDetail(props, ref) {
|
|
|
163
160
|
}
|
|
164
161
|
const mock = newContextItem(childFormItem, name, isPureArray, parent);
|
|
165
162
|
let data = (initialValues === null || initialValues === void 0 ? void 0 : initialValues.length) ? initialValues : [mock];
|
|
163
|
+
if (!(childFormItem === null || childFormItem === void 0 ? void 0 : childFormItem.length)) {
|
|
164
|
+
data = [];
|
|
165
|
+
}
|
|
166
166
|
// 新的明细组件,开放初始值,根据初始值设置上下文
|
|
167
167
|
if (isWdFormDetail) {
|
|
168
168
|
data = initialValues;
|
|
@@ -194,30 +194,29 @@ const FormDetailCom = forwardRef(function FormDetail(props, ref) {
|
|
|
194
194
|
setChildFormItem(childFormItem);
|
|
195
195
|
}
|
|
196
196
|
}, [initDetailValue, isPureArray, name, (_a = parent === null || parent === void 0 ? void 0 : parent.dataSourceProfile) === null || _a === void 0 ? void 0 : _a.name]);
|
|
197
|
-
const setFormDetailValue = useCallback((value) => {
|
|
198
|
-
if (!isObjectEqual(value, detailValue) &&
|
|
197
|
+
const setFormDetailValue = useCallback((value, _childFormItem = childFormItem) => {
|
|
198
|
+
if (!isObjectEqual(value, detailValue) && _childFormItem.length > 0) {
|
|
199
199
|
setDetailValue(value || []);
|
|
200
200
|
init(value || [], isWdFormDetail);
|
|
201
|
-
setIsInit(true);
|
|
201
|
+
// setIsInit(true);
|
|
202
202
|
}
|
|
203
203
|
}, [childFormItem, detailValue, init, isWdFormDetail]);
|
|
204
204
|
// 初始化context的值
|
|
205
205
|
useEffect(() => {
|
|
206
206
|
logger.debug('initDetailValue', initDetailValue);
|
|
207
|
-
|
|
207
|
+
let _childFormItem = childFormItem;
|
|
208
|
+
if ((_childFormItem === null || _childFormItem === void 0 ? void 0 : _childFormItem.length) === 0) {
|
|
209
|
+
_childFormItem = getChildFormItem({
|
|
210
|
+
isPureArray,
|
|
211
|
+
name,
|
|
212
|
+
parent,
|
|
213
|
+
defaultValue: initDetailValue,
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
setFormDetailValue(initDetailValue, _childFormItem);
|
|
208
217
|
// 只有initDetailValue的值改变的时候才执行
|
|
209
218
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
210
219
|
}, [initDetailValue]);
|
|
211
|
-
useDebouncedEffect(() => {
|
|
212
|
-
var _a;
|
|
213
|
-
// 子表单默认值变化时,若form值不同步,则主动同步(默认值为变量的情况)
|
|
214
|
-
if (isInit &&
|
|
215
|
-
detailValue &&
|
|
216
|
-
!isObjectEqual((_a = parent === null || parent === void 0 ? void 0 : parent.value) === null || _a === void 0 ? void 0 : _a[name], detailValue)) {
|
|
217
|
-
parent.__setValueImmediate__({ [name]: detailValue }, false);
|
|
218
|
-
setIsInit(false);
|
|
219
|
-
}
|
|
220
|
-
}, [detailValue, isInit, name], 15);
|
|
221
220
|
useEffect(() => {
|
|
222
221
|
var _a;
|
|
223
222
|
const childFormItem = getChildFormItem({
|
|
@@ -228,11 +227,12 @@ const FormDetailCom = forwardRef(function FormDetail(props, ref) {
|
|
|
228
227
|
});
|
|
229
228
|
setChildFormItem(childFormItem);
|
|
230
229
|
// 只有在编辑器里,或存在初始值的时候,或新明细组件(wdFormDetail),才初始化明细单项
|
|
231
|
-
if (
|
|
230
|
+
if (hasInitValue || isWdFormDetail) {
|
|
232
231
|
setDetailValue(initDetailValue || []);
|
|
233
232
|
init(initDetailValue, isWdFormDetail);
|
|
234
233
|
}
|
|
235
234
|
else {
|
|
235
|
+
setDetailValue([]);
|
|
236
236
|
(_a = events === null || events === void 0 ? void 0 : events.onDataChange) === null || _a === void 0 ? void 0 : _a.call(events, { data: [] });
|
|
237
237
|
}
|
|
238
238
|
// 组件卸载时触发
|
|
@@ -261,10 +261,7 @@ const FormDetailCom = forwardRef(function FormDetail(props, ref) {
|
|
|
261
261
|
}, [_onChange, childFormItem, isPureArray]);
|
|
262
262
|
const onChange = useCallback((type, params) => {
|
|
263
263
|
var _a;
|
|
264
|
-
if (disabled ||
|
|
265
|
-
readOnly ||
|
|
266
|
-
!(fieldAuth === null || fieldAuth === void 0 ? void 0 : fieldAuth.includes('w')) ||
|
|
267
|
-
(parent === null || parent === void 0 ? void 0 : parent.formType) === 'read') {
|
|
264
|
+
if (disabled || readOnly || !(fieldAuth === null || fieldAuth === void 0 ? void 0 : fieldAuth.includes('w')) || (parent === null || parent === void 0 ? void 0 : parent.formType) === 'read') {
|
|
268
265
|
return;
|
|
269
266
|
}
|
|
270
267
|
let data;
|
|
@@ -291,9 +288,9 @@ const FormDetailCom = forwardRef(function FormDetail(props, ref) {
|
|
|
291
288
|
parent,
|
|
292
289
|
});
|
|
293
290
|
if (!isObjectEqual(data, contextData)) {
|
|
294
|
-
updateFormDetailValue(data);
|
|
295
291
|
setContextData(data);
|
|
296
292
|
(_a = events === null || events === void 0 ? void 0 : events.onDataChange) === null || _a === void 0 ? void 0 : _a.call(events, { data });
|
|
293
|
+
updateFormDetailValue(data);
|
|
297
294
|
}
|
|
298
295
|
}, [
|
|
299
296
|
disabled,
|
|
@@ -353,18 +350,7 @@ const FormDetailCom = forwardRef(function FormDetail(props, ref) {
|
|
|
353
350
|
disabled,
|
|
354
351
|
readOnly,
|
|
355
352
|
};
|
|
356
|
-
}, [
|
|
357
|
-
innerHandle,
|
|
358
|
-
onChange,
|
|
359
|
-
isTableView,
|
|
360
|
-
name,
|
|
361
|
-
detailValue,
|
|
362
|
-
label,
|
|
363
|
-
visible,
|
|
364
|
-
disabled,
|
|
365
|
-
readOnly,
|
|
366
|
-
setFormDetailValue,
|
|
367
|
-
]);
|
|
353
|
+
}, [innerHandle, onChange, isTableView, name, detailValue, label, visible, disabled, readOnly, setFormDetailValue]);
|
|
368
354
|
// useEffect(() => {
|
|
369
355
|
// const initArr = lodashGet(parent, 'initialValues.name', null);
|
|
370
356
|
// logger.debug('initialValue', initArr, name);
|
|
@@ -413,6 +399,6 @@ const FormDetailCom = forwardRef(function FormDetail(props, ref) {
|
|
|
413
399
|
const layout = platform === 'h5' ? 'vertical' : _currentLayout;
|
|
414
400
|
const formItemProps = { ...props, classRoot, layout, isWdFormDetail };
|
|
415
401
|
// 组件规范化后再考虑是否改动
|
|
416
|
-
return isWdFormDetail ?
|
|
402
|
+
return isWdFormDetail ? _jsx(WdFormItem, { ...formItemProps, children: formDetailRender() }) : formDetailRender();
|
|
417
403
|
});
|
|
418
404
|
export default FormDetailCom;
|
|
@@ -83,7 +83,7 @@ initialContent, placeholder, iconPack, maxSize, cloudPath, visible, }) {
|
|
|
83
83
|
cloudToHttpsMap: {},
|
|
84
84
|
});
|
|
85
85
|
const previousValueRef = React.useRef();
|
|
86
|
-
const onDataChange =
|
|
86
|
+
const onDataChange = React.useCallback((value) => {
|
|
87
87
|
var _a;
|
|
88
88
|
if (previousValueRef.current !== value) {
|
|
89
89
|
previousValueRef.current = value;
|
|
@@ -97,7 +97,7 @@ initialContent, placeholder, iconPack, maxSize, cloudPath, visible, }) {
|
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
|
-
};
|
|
100
|
+
}, [events, onChange]);
|
|
101
101
|
const isSizeAccept = (file) => {
|
|
102
102
|
if (file.size > maxSize * 1024 * 1024) {
|
|
103
103
|
alertErrorMessage({
|
|
@@ -313,8 +313,14 @@ initialContent, placeholder, iconPack, maxSize, cloudPath, visible, }) {
|
|
|
313
313
|
ref.current.editor.setHTML(tempValue);
|
|
314
314
|
}
|
|
315
315
|
window.setTimeout(() => {
|
|
316
|
+
var _a, _b;
|
|
316
317
|
if (currentCursor) {
|
|
317
|
-
|
|
318
|
+
try {
|
|
319
|
+
(_b = (_a = ref.current) === null || _a === void 0 ? void 0 : _a.editor) === null || _b === void 0 ? void 0 : _b.selection(currentCursor, currentCursor);
|
|
320
|
+
}
|
|
321
|
+
catch {
|
|
322
|
+
// 避免组件销毁,执行报错
|
|
323
|
+
}
|
|
318
324
|
}
|
|
319
325
|
}, 0);
|
|
320
326
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
interface FormFieldArrContext {
|
|
3
|
+
isInformArrContainer?: boolean;
|
|
4
|
+
namePath?: string[];
|
|
5
|
+
status?: 'edit' | 'disabled' | 'readOnly';
|
|
6
|
+
getFieldValue?: (arg: {
|
|
7
|
+
namePath: string[];
|
|
8
|
+
initialValue?: any;
|
|
9
|
+
}) => any;
|
|
10
|
+
setFieldValue?: (arg: {
|
|
11
|
+
namePath: string[];
|
|
12
|
+
value?: any;
|
|
13
|
+
}) => void;
|
|
14
|
+
}
|
|
15
|
+
interface FormFieldArrContextProviderProps extends FormFieldArrContext {
|
|
16
|
+
children?: React.ReactNode;
|
|
17
|
+
}
|
|
18
|
+
declare const FormFieldArrContext: React.Context<FormFieldArrContext>;
|
|
19
|
+
export declare function FormFieldArrProvider({ children, isInformArrContainer, namePath, status, setFieldValue, getFieldValue, }: FormFieldArrContextProviderProps): JSX.Element;
|
|
20
|
+
export declare function useFormFieldArr(): FormFieldArrContext | null;
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useContext, useMemo } from 'react';
|
|
3
|
+
import { createContext } from '../../../utils/global-context';
|
|
4
|
+
const FormFieldArrContext = createContext(null, 'FormFieldArrContext');
|
|
5
|
+
export function FormFieldArrProvider({ children, isInformArrContainer, namePath, status, setFieldValue, getFieldValue, }) {
|
|
6
|
+
return (_jsx(FormFieldArrContext.Provider, { value: useMemo(() => ({ status, isInformArrContainer, namePath, setFieldValue, getFieldValue }), [status, isInformArrContainer, namePath, setFieldValue, getFieldValue]), children: children }));
|
|
7
|
+
}
|
|
8
|
+
export function useFormFieldArr() {
|
|
9
|
+
return useContext(FormFieldArrContext);
|
|
10
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
interface FormFieldContext {
|
|
3
|
+
setFieldValue: (arg: {
|
|
4
|
+
namePath: string[];
|
|
5
|
+
value?: any;
|
|
6
|
+
}) => void;
|
|
7
|
+
getFieldValue: (arg: {
|
|
8
|
+
namePath: string[];
|
|
9
|
+
initialValue?: any;
|
|
10
|
+
}) => any;
|
|
11
|
+
isInformContainer?: boolean;
|
|
12
|
+
}
|
|
13
|
+
interface FormFieldContextProviderProps extends FormFieldContext {
|
|
14
|
+
children?: React.ReactNode;
|
|
15
|
+
}
|
|
16
|
+
export declare const FormFieldContext: React.Context<FormFieldContext>;
|
|
17
|
+
export declare function FormFieldProvider({ children, isInformContainer, setFieldValue, getFieldValue, }: FormFieldContextProviderProps): JSX.Element;
|
|
18
|
+
export declare function useFormField(): FormFieldContext | null;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useContext, useMemo } from 'react';
|
|
3
|
+
import { createContext } from '../../../utils/global-context';
|
|
4
|
+
export const FormFieldContext = createContext(null, 'FormFieldContext');
|
|
5
|
+
export function FormFieldProvider({ children, isInformContainer, setFieldValue, getFieldValue, }) {
|
|
6
|
+
return (_jsx(FormFieldContext.Provider, { value: useMemo(() => ({ setFieldValue, isInformContainer, getFieldValue }), [setFieldValue, isInformContainer, getFieldValue]), children: children }));
|
|
7
|
+
}
|
|
8
|
+
export function useFormField() {
|
|
9
|
+
return useContext(FormFieldContext);
|
|
10
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
interface FormFieldObjContext {
|
|
3
|
+
namePath?: string[];
|
|
4
|
+
status?: 'edit' | 'disabled' | 'readOnly';
|
|
5
|
+
objType?: string;
|
|
6
|
+
}
|
|
7
|
+
interface FormFieldObjContextProviderProps extends FormFieldObjContext {
|
|
8
|
+
children?: React.ReactNode;
|
|
9
|
+
}
|
|
10
|
+
declare const FormFieldObjContext: React.Context<FormFieldObjContext>;
|
|
11
|
+
export declare function FormFieldObjProvider({ children, namePath, status, objType }: FormFieldObjContextProviderProps): JSX.Element;
|
|
12
|
+
export declare function useFormFieldObj(): FormFieldObjContext | null;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useContext, useMemo } from 'react';
|
|
3
|
+
import { createContext } from '../../../utils/global-context';
|
|
4
|
+
const FormFieldObjContext = createContext(null, 'FormFieldObjContext');
|
|
5
|
+
export function FormFieldObjProvider({ children, namePath, status, objType }) {
|
|
6
|
+
return (_jsx(FormFieldObjContext.Provider, { value: useMemo(() => ({ objType, status, namePath }), [objType, status, namePath]), children: children }));
|
|
7
|
+
}
|
|
8
|
+
export function useFormFieldObj() {
|
|
9
|
+
return useContext(FormFieldObjContext);
|
|
10
|
+
}
|
|
@@ -14,17 +14,17 @@ declare const _default: React.MemoExoticComponent<React.ForwardRefExoticComponen
|
|
|
14
14
|
layout: "vertical" | "horizontal";
|
|
15
15
|
dataSourceName: string;
|
|
16
16
|
labelAlign: "left" | "right";
|
|
17
|
-
|
|
17
|
+
datasourceType: "connector" | "custom-connector" | "model" | "expression";
|
|
18
|
+
methodGetItem: string;
|
|
19
|
+
paramGetItem: Record<string, unknown>;
|
|
18
20
|
methodCreate: string;
|
|
19
21
|
methodUpdate: string;
|
|
22
|
+
isDisabledSubmit: boolean;
|
|
20
23
|
formType_bind: boolean;
|
|
21
|
-
datasourceType: "connector" | "model" | "expression" | "custom-connector";
|
|
22
24
|
fields: {
|
|
23
25
|
name: string;
|
|
24
26
|
componentType: string;
|
|
25
27
|
}[];
|
|
26
|
-
methodGetItem: string;
|
|
27
|
-
paramGetItem: Record<string, unknown>;
|
|
28
28
|
colNum: never;
|
|
29
29
|
lgWidth: "lg" | "sm" | "md" | "hundred";
|
|
30
30
|
initialValues: Record<string, unknown>;
|