@cloudbase/weda-ui 3.7.9 → 3.7.11

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.
@@ -86,9 +86,6 @@ export function PureSelect({ params, selectedValue, updateValue, placeholder, si
86
86
  requestFatherRelated(searchPage, searchValue);
87
87
  }
88
88
  }, [searchPage]);
89
- useEffect(() => {
90
- recycleBack === null || recycleBack === void 0 ? void 0 : recycleBack(options);
91
- }, [options]);
92
89
  const requestFatherRelated = (pageNo, searchValue) => {
93
90
  requestFatherRelatedOption(params, pageNo, RequestOptionType.SEARCH, searchValue)
94
91
  .then((value) => {
@@ -132,6 +129,9 @@ export function PureSelect({ params, selectedValue, updateValue, placeholder, si
132
129
  const option = isSearch && staticSearchable ? searchOptions : options;
133
130
  return platform === 'h5' ? option : transFormatTeaSelectKey(option);
134
131
  }, [isSearch, searchOptions, options, platform, staticSearchable]);
132
+ useEffect(() => {
133
+ recycleBack === null || recycleBack === void 0 ? void 0 : recycleBack(currentOption);
134
+ }, [currentOption]);
135
135
  const handleSearch = () => {
136
136
  // 本地搜索
137
137
  if (!isTurnPages || options.length < PAGE_SIZE) {
@@ -48,7 +48,7 @@ events = emptyObject, defaultValue, uploadPath = 'weda-uploader', single = true,
48
48
  // 两次默认值不同, 需要刷新
49
49
  const prevDefaultRef = React.useRef([]);
50
50
  const fileRef = React.useRef(fileIDList);
51
- const maxSizeLimit = maxSize > 500 ? 500 : maxSize;
51
+ const maxSizeLimit = maxSize;
52
52
  const formType = ((_a = getParentForm($node)) === null || _a === void 0 ? void 0 : _a.formType) || 'create';
53
53
  const changeTypeRef = React.useRef('');
54
54
  React.useEffect(() => {
@@ -51,7 +51,7 @@ acceptTypes = emptyArray, downloadVisible = true, deleteVisible = true, uploadPa
51
51
  // 两次默认值不同, 需要刷新
52
52
  const prevDefaultRef = React.useRef([]);
53
53
  const fileRef = React.useRef(fileIDList);
54
- const maxSizeLimit = maxSize > 500 ? 500 : maxSize;
54
+ const maxSizeLimit = maxSize;
55
55
  const formType = ((_a = getParentForm($node)) === null || _a === void 0 ? void 0 : _a.formType) || 'create';
56
56
  const changeTypeRef = React.useRef(''); // 判断当前更新来自手动还是value变化
57
57
  React.useEffect(() => {
@@ -53,8 +53,13 @@ export default function RichTextView({ value = '', className, style, id, }) {
53
53
  useEffect(() => {
54
54
  if (richTextRef.current) {
55
55
  richTextRef.current.querySelectorAll('a').forEach((a) => {
56
+ const url = a.href;
57
+ // 若非同域 默认新页面打开
58
+ if (/https?:\/\//.test(url) &&
59
+ !url.startsWith(window.location.origin)) {
60
+ a.target = a.target || '_blank';
61
+ }
56
62
  a.addEventListener('click', (e) => {
57
- const url = a.href;
58
63
  getOnClick({ url })(e);
59
64
  });
60
65
  });
@@ -1,6 +1,6 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  /* eslint-disable @typescript-eslint/no-magic-numbers */
3
- import { useState, useRef, useEffect } from 'react';
3
+ import { useState, useRef, useEffect, useMemo } from 'react';
4
4
  import { useConfig } from '../../utils/config-context';
5
5
  import { Modal } from '../wd-date/elements/Modal.h5';
6
6
  import { noop } from '../../utils/constant';
@@ -39,10 +39,12 @@ export function CascaderH5(props) {
39
39
  const focusRef = useRef();
40
40
  const [inputFocus, setInputFocus] = useState(false);
41
41
  const [searchValue, setSearchValue] = useState('');
42
- const data = transformTabData(_data);
42
+ const data = useMemo(() => {
43
+ return transformTabData(_data);
44
+ }, [_data]);
43
45
  const [tabData, setTabData] = useState(initTabData(data, _value, placeholderItem));
44
46
  const [listOptions, setListOptions] = useState(initListOptions(data, _value));
45
- const pickerValueRef = useRef(_value); // 弹窗中临时值
47
+ const pickerValueRef = useRef({ data, value: _value }); // 弹窗中临时值
46
48
  const handleOk = () => {
47
49
  const value = tabData
48
50
  .map((item) => item.value)
@@ -100,7 +102,7 @@ export function CascaderH5(props) {
100
102
  setListOptions(_listOptions);
101
103
  }
102
104
  // 更新tab数据
103
- const newTabData = [...tabData.filter((i) => i.level < item.level), item];
105
+ const newTabData = [...tabData.filter((i) => (i === null || i === void 0 ? void 0 : i.level) < item.level), item];
104
106
  updateTabData(newTabData, item);
105
107
  };
106
108
  // 点击tab项,更新列表选项
@@ -116,8 +118,9 @@ export function CascaderH5(props) {
116
118
  setListOptions(listOptions);
117
119
  };
118
120
  useEffect(() => {
119
- if (!isObjectEqual(pickerValueRef.current, _value)) {
120
- pickerValueRef.current = _value;
121
+ if (!isObjectEqual(pickerValueRef.current.value, _value) ||
122
+ !isObjectEqual(pickerValueRef.current.data, data)) {
123
+ pickerValueRef.current = { value: _value, data };
121
124
  setTabData(initTabData(data, _value, placeholderItem));
122
125
  setListOptions(initListOptions(data, _value));
123
126
  }
@@ -1,5 +1,5 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import React, { forwardRef, useState, useCallback, useMemo } from 'react';
2
+ import React, { forwardRef, useState, useCallback, useMemo, useEffect, } from 'react';
3
3
  import { Cascader, ConfigProvider } from 'tea-component';
4
4
  import { useHandleClear, useFixedIcon, SELECT_ICON_H5, SELECT_ICON_PC, } from '../../utils/hooks/useFormLegacy';
5
5
  import { useFormInputTrait } from '../../components/form-input-hooks';
@@ -39,8 +39,11 @@ export const WdCascader = forwardRef(function WdCascader(props, ref) {
39
39
  iconPc: SELECT_ICON_PC,
40
40
  });
41
41
  const delayEvents = useDelayEvents(events);
42
- const [selectedOptions, setSelectedOptions] = useState(value === null || value === void 0 ? void 0 : value.map((i) => getSelectedOptions(data, i)));
43
- const readValue = useMemo(() => { var _a; return ((_a = selectedOptions === null || selectedOptions === void 0 ? void 0 : selectedOptions.map((i) => i === null || i === void 0 ? void 0 : i.label)) === null || _a === void 0 ? void 0 : _a.join(' / ')) || value; }, [selectedOptions, value]);
42
+ const [selectedOptions, setSelectedOptions] = useState(value === null || value === void 0 ? void 0 : value.map((i) => getSelectedOptions(data, i) || { label: i, value: i }));
43
+ useEffect(() => {
44
+ setSelectedOptions(value === null || value === void 0 ? void 0 : value.map((i) => getSelectedOptions(data, i) || { label: i, value: i }));
45
+ }, [data, value]);
46
+ const readValue = useMemo(() => { var _a; return (_a = selectedOptions === null || selectedOptions === void 0 ? void 0 : selectedOptions.map((i) => (i === null || i === void 0 ? void 0 : i.label) || (i === null || i === void 0 ? void 0 : i.value))) === null || _a === void 0 ? void 0 : _a.join(' / '); }, [selectedOptions]);
44
47
  const onClearChange = useCallback((v) => {
45
48
  var _a;
46
49
  setSelectedOptions([]);
@@ -93,5 +96,5 @@ export const WdCascader = forwardRef(function WdCascader(props, ref) {
93
96
  };
94
97
  if (!visible)
95
98
  return null;
96
- return (_jsx(WdFormItem, { ...formItemProps, children: _jsx(WdInputGroup, { ...inputGroupProps, children: _jsx(WdInputWrap, { ...inputWrapProps, children: _jsx(ConfigProvider, { classPrefix: "wd", children: platform === 'h5' ? (_jsx(CascaderH5, { inputId: inputId, name: props.name, data: data, multiple: multiple, onChange: handleChange, value: value !== null && value !== void 0 ? value : [], placeholder: placeholder, onSearch: onSearchValueInput, disabled: disabled || readOnly, readValue: readValue })) : (_jsx(Cascader, { clearable: true, className: sizeClassName, type: "menu", expandTrigger: "hover", data: data, multiple: multiple, onChange: handleChange, value: value !== null && value !== void 0 ? value : [], defaultValue: value !== null && value !== void 0 ? value : [], placeholder: placeholder, onSearch: onSearchValueInput, disabled: disabled || readOnly })) }) }) }) }));
99
+ return (_jsx(WdFormItem, { ...formItemProps, children: _jsx(WdInputGroup, { ...inputGroupProps, children: _jsx(WdInputWrap, { ...inputWrapProps, children: _jsx(ConfigProvider, { classPrefix: "wd", children: platform === 'h5' ? (_jsx(CascaderH5, { inputId: inputId, name: props.name, data: data, multiple: multiple, onChange: handleChange, value: value !== null && value !== void 0 ? value : [], placeholder: placeholder, onSearch: onSearchValueInput, disabled: disabled || readOnly, readValue: readValue })) : (_jsx(Cascader, { changeOnSelect: true, clearable: true, className: sizeClassName, type: "menu", expandTrigger: "hover", data: data, multiple: multiple, onChange: handleChange, value: value !== null && value !== void 0 ? value : [], defaultValue: value !== null && value !== void 0 ? value : [], placeholder: placeholder, onSearch: onSearchValueInput, disabled: disabled || readOnly })) }) }) }) }));
97
100
  });
@@ -29,20 +29,24 @@ export const setSelectedValue = (data, value) => {
29
29
  if (!Array.isArray(data))
30
30
  return [];
31
31
  const _value = [].concat(value);
32
- return data.map((item) => {
32
+ return data
33
+ .map((item) => {
34
+ if (!item)
35
+ return null;
33
36
  item.selected = !!_value.find((i) => i === (item === null || item === void 0 ? void 0 : item.value));
34
37
  if (item.children) {
35
38
  item.children = setSelectedValue(item.children, value);
36
39
  }
37
- return item;
38
- });
40
+ return { ...item };
41
+ })
42
+ .filter((i) => i);
39
43
  };
40
44
  export const initTabData = (data, value, placeholderItem) => {
41
45
  if (!Array.isArray(data))
42
46
  return [];
43
47
  let tabDataRes = [placeholderItem];
44
- if (value.length) {
45
- const selectedOptions = (value === null || value === void 0 ? void 0 : value.map((i) => getSelectedOptions(data, i))) || [];
48
+ const selectedOptions = (value === null || value === void 0 ? void 0 : value.map((i) => getSelectedOptions(data, i)).filter((i) => i)) || [];
49
+ if (value.length && selectedOptions.length) {
46
50
  const selectedItem = selectedOptions[selectedOptions.length - 1];
47
51
  tabDataRes = setSelectedValue(selectedOptions, selectedItem === null || selectedItem === void 0 ? void 0 : selectedItem.value);
48
52
  }
@@ -53,11 +57,11 @@ export const initListOptions = (data, value) => {
53
57
  if (!Array.isArray(data))
54
58
  return [];
55
59
  let listOptionsRes = deepClone(data);
56
- if (value.length) {
57
- const selectedOptions = (value === null || value === void 0 ? void 0 : value.map((i) => getSelectedOptions(data, i))) || [];
60
+ const selectedOptions = (value === null || value === void 0 ? void 0 : value.map((i) => getSelectedOptions(data, i)).filter((i) => i)) || [];
61
+ if (value.length && selectedOptions.length) {
58
62
  const selectedItem = selectedOptions[selectedOptions.length - 1];
59
63
  listOptionsRes =
60
- ((_a = getSelectedOptions(data, selectedItem.pid)) === null || _a === void 0 ? void 0 : _a.children) || data;
64
+ ((_a = getSelectedOptions(data, selectedItem === null || selectedItem === void 0 ? void 0 : selectedItem.pid)) === null || _a === void 0 ? void 0 : _a.children) || data;
61
65
  }
62
66
  return listOptionsRes;
63
67
  };
@@ -47,6 +47,7 @@ export const BaseFormObj = forwardRef(function BaseFormObj(props, ref) {
47
47
  const formItemProps = {
48
48
  ...props,
49
49
  classRoot,
50
+ className: classNames(props.className, `${classPrefix}-form-obj-item`),
50
51
  LabelContainer,
51
52
  };
52
53
  const initValue = { arr: [], obj: {} }[props.objType];
@@ -124,7 +125,7 @@ export const BaseFormObj = forwardRef(function BaseFormObj(props, ref) {
124
125
  value = deepClone(objValue);
125
126
  // 触发添加操作,则增加一个undefined值
126
127
  if (params.type === 'add') {
127
- value.push(undefined);
128
+ value.push(props.addDefaultValue);
128
129
  }
129
130
  // 触发删除操作,则删除对应索引的值
130
131
  if (params.type === 'remove') {
@@ -179,9 +179,11 @@ export const WdInputNumber = forwardRef(function WdInputNumber(props, ref) {
179
179
  const toShow = getShowValue(`${value}`, props.format);
180
180
  const toReal = getRealValue(toShow);
181
181
  setShowValue(toShow);
182
+ if (toReal === realValue)
183
+ return;
182
184
  setRealValue(toReal);
183
185
  changeForm(toReal);
184
- }, [changeForm, getRealValue, getShowValue, props.format]);
186
+ }, [changeForm, getRealValue, getShowValue, props.format, realValue]);
185
187
  // 与计算值相关的配置变化时,去重新计算显示值和真实值
186
188
  useEffect(() => {
187
189
  dealValueChange(isNumber(value) ? value : props.inputValue);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudbase/weda-ui",
3
- "version": "3.7.9",
3
+ "version": "3.7.11",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index",
6
6
  "miniprogram": "mpdist",