one-design-next 0.0.64 → 0.0.65

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.
@@ -1,27 +1,27 @@
1
- import _extends from "@babel/runtime/helpers/esm/extends";
2
- import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
3
- import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
4
- import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
5
- import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
6
- var _excluded = ["id", "prefixCls", "fieldNames", "defaultValue", "value", "changeOnSelect", "onChange", "displayRender", "checkable", "autoClearSearchValue", "searchValue", "onSearch", "showSearch", "expandTrigger", "options", "dropdownPrefixCls", "loadData", "popupVisible", "open", "popupClassName", "dropdownClassName", "dropdownMenuColumnStyle", "dropdownStyle", "popupPlacement", "placement", "onDropdownVisibleChange", "onPopupVisibleChange", "onOpenChange", "expandIcon", "loadingIcon", "children", "dropdownMatchSelectWidth", "showCheckedStrategy", "optionRender", "checkStrictly"];
7
- import { BaseSelect } from 'rc-select';
8
- import useId from "rc-select/es/hooks/useId";
9
- import useEvent from "rc-util/es/hooks/useEvent";
10
- import useMergedState from "rc-util/es/hooks/useMergedState";
11
- import * as React from 'react';
1
+ import _extends from '@babel/runtime/helpers/esm/extends';
2
+ import _objectSpread from '@babel/runtime/helpers/esm/objectSpread2';
3
+ import _objectWithoutProperties from '@babel/runtime/helpers/esm/objectWithoutProperties';
4
+ import _slicedToArray from '@babel/runtime/helpers/esm/slicedToArray';
5
+ import _toConsumableArray from '@babel/runtime/helpers/esm/toConsumableArray';
12
6
  import CascaderContext from 'rc-cascader/es/context';
13
7
  import useDisplayValues from 'rc-cascader/es/hooks/useDisplayValues';
14
8
  import useMissingValues from 'rc-cascader/es/hooks/useMissingValues';
15
9
  import useOptions from 'rc-cascader/es/hooks/useOptions';
16
10
  import useSearchConfig from 'rc-cascader/es/hooks/useSearchConfig';
17
11
  import useSearchOptions from 'rc-cascader/es/hooks/useSearchOptions';
12
+ import { fillFieldNames, SHOW_CHILD, SHOW_PARENT, toPathKeys, toRawValues } from 'rc-cascader/es/utils/commonUtil';
13
+ import { formatStrategyValues, toPathOptions } from 'rc-cascader/es/utils/treeUtil';
14
+ import warningProps, { warningNullOptions } from 'rc-cascader/es/utils/warningPropsUtil';
15
+ import { BaseSelect } from 'rc-select';
16
+ import useId from 'rc-select/es/hooks/useId';
17
+ import useEvent from 'rc-util/es/hooks/useEvent';
18
+ import useMergedState from 'rc-util/es/hooks/useMergedState';
19
+ import * as React from 'react';
18
20
  import useSelect from "./hooks/useSelect";
19
21
  import useValues from "./hooks/useValues";
20
22
  import OptionList from "./OptionList";
21
23
  import Panel from "./Panel";
22
- import { fillFieldNames, SHOW_CHILD, SHOW_PARENT, toPathKeys, toRawValues } from 'rc-cascader/es/utils/commonUtil';
23
- import { formatStrategyValues, toPathOptions } from 'rc-cascader/es/utils/treeUtil';
24
- import warningProps, { warningNullOptions } from 'rc-cascader/es/utils/warningPropsUtil';
24
+ var _excluded = ['id', 'prefixCls', 'fieldNames', 'defaultValue', 'value', 'changeOnSelect', 'onChange', 'displayRender', 'checkable', 'autoClearSearchValue', 'searchValue', 'onSearch', 'showSearch', 'showInnerSearch', 'expandTrigger', 'options', 'dropdownPrefixCls', 'loadData', 'popupVisible', 'open', 'popupClassName', 'dropdownClassName', 'dropdownMenuColumnStyle', 'dropdownStyle', 'popupPlacement', 'placement', 'onDropdownVisibleChange', 'onPopupVisibleChange', 'onOpenChange', 'expandIcon', 'loadingIcon', 'children', 'dropdownMatchSelectWidth', 'showCheckedStrategy', 'optionRender', 'checkStrictly'];
25
25
  var Cascader = /*#__PURE__*/React.forwardRef(function (props, ref) {
26
26
  var id = props.id,
27
27
  _props$prefixCls = props.prefixCls,
@@ -38,6 +38,7 @@ var Cascader = /*#__PURE__*/React.forwardRef(function (props, ref) {
38
38
  searchValue = props.searchValue,
39
39
  onSearch = props.onSearch,
40
40
  showSearch = props.showSearch,
41
+ showInnerSearch = props.showInnerSearch,
41
42
  expandTrigger = props.expandTrigger,
42
43
  options = props.options,
43
44
  dropdownPrefixCls = props.dropdownPrefixCls,
@@ -81,8 +82,7 @@ var Cascader = /*#__PURE__*/React.forwardRef(function (props, ref) {
81
82
  // ========================= FieldNames =========================
82
83
  var mergedFieldNames = React.useMemo(function () {
83
84
  return fillFieldNames(fieldNames);
84
- }, /* eslint-disable react-hooks/exhaustive-deps */
85
- [JSON.stringify(fieldNames)]
85
+ } /* eslint-disable react-hooks/exhaustive-deps */, [JSON.stringify(fieldNames)]
86
86
  /* eslint-enable react-hooks/exhaustive-deps */);
87
87
 
88
88
  // =========================== Option ===========================
@@ -231,34 +231,24 @@ var Cascader = /*#__PURE__*/React.forwardRef(function (props, ref) {
231
231
  prefixCls: prefixCls,
232
232
  autoClearSearchValue: autoClearSearchValue,
233
233
  dropdownMatchSelectWidth: dropdownMatchSelectWidth,
234
- dropdownStyle: _objectSpread(_objectSpread({}, dropdownStyle), customDropdownStyle)
234
+ dropdownStyle: _objectSpread(_objectSpread({}, dropdownStyle), customDropdownStyle),
235
235
  // Value
236
- ,
237
-
238
236
  displayValues: displayValues,
239
237
  onDisplayValuesChange: onDisplayValuesChange,
240
- mode: multiple ? 'multiple' : undefined
238
+ mode: multiple ? 'multiple' : undefined,
241
239
  // Search
242
- ,
243
-
244
240
  searchValue: mergedSearchValue,
245
241
  onSearch: onInternalSearch,
246
- showSearch: mergedShowSearch
242
+ showSearch: showInnerSearch ? false : mergedShowSearch,
247
243
  // Options
248
- ,
249
-
250
244
  OptionList: OptionList,
251
- emptyOptions: emptyOptions
245
+ emptyOptions: emptyOptions,
252
246
  // Open
253
- ,
254
-
255
247
  open: mergedOpen,
256
248
  dropdownClassName: mergedDropdownClassName,
257
249
  placement: mergedPlacement,
258
- onDropdownVisibleChange: onInternalDropdownVisibleChange
250
+ onDropdownVisibleChange: onInternalDropdownVisibleChange,
259
251
  // Children
260
- ,
261
-
262
252
  getRawInputElement: function getRawInputElement() {
263
253
  return children;
264
254
  }
@@ -15,6 +15,5 @@ export interface ColumnProps {
15
15
  loadingKeys: string[];
16
16
  isSelectable: (option: DefaultOptionType) => boolean;
17
17
  disabled?: boolean;
18
- motionEnter?: boolean;
19
18
  }
20
- export default function Column({ prefixCls, multiple, options, activeValue, prevValuePath, onToggleOpen, onSelect, onActive, checkedSet, halfCheckedSet, loadingKeys, isSelectable, disabled: propsDisabled, motionEnter, }: ColumnProps): React.JSX.Element;
19
+ export default function Column({ prefixCls, multiple, options, activeValue, prevValuePath, onToggleOpen, onSelect, onActive, checkedSet, halfCheckedSet, loadingKeys, isSelectable, disabled: propsDisabled, }: ColumnProps): React.JSX.Element;
@@ -20,8 +20,7 @@ export default function Column(_ref) {
20
20
  halfCheckedSet = _ref.halfCheckedSet,
21
21
  loadingKeys = _ref.loadingKeys,
22
22
  isSelectable = _ref.isSelectable,
23
- propsDisabled = _ref.disabled,
24
- motionEnter = _ref.motionEnter;
23
+ propsDisabled = _ref.disabled;
25
24
  var menuPrefixCls = "".concat(prefixCls, "-menu");
26
25
  var menuItemPrefixCls = "".concat(prefixCls, "-menu-item");
27
26
  var _ref2 = React.useContext(CascaderContext),
@@ -72,7 +71,7 @@ export default function Column(_ref) {
72
71
  });
73
72
  }, [options, checkedSet, fieldNames, halfCheckedSet, loadingKeys, prevValuePath]);
74
73
  return /*#__PURE__*/React.createElement("ul", {
75
- className: clsx(menuPrefixCls, _defineProperty({}, "".concat(menuPrefixCls, "-enter"), motionEnter)),
74
+ className: menuPrefixCls,
76
75
  role: "menu"
77
76
  }, optionInfoList.map(function (_ref3) {
78
77
  var disabled = _ref3.disabled,
@@ -1,18 +1,18 @@
1
- import _extends from "@babel/runtime/helpers/esm/extends";
2
- import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
3
- import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
4
- import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
5
- import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
1
+ import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
2
+ import _extends from '@babel/runtime/helpers/esm/extends';
3
+ import _objectSpread from '@babel/runtime/helpers/esm/objectSpread2';
4
+ import _slicedToArray from '@babel/runtime/helpers/esm/slicedToArray';
5
+ import _toConsumableArray from '@babel/runtime/helpers/esm/toConsumableArray';
6
6
  /* eslint-disable default-case */
7
7
  import classNames from 'classnames';
8
- import * as React from 'react';
9
8
  import CascaderContext from 'rc-cascader/es/context';
9
+ import CacheContent from 'rc-cascader/es/OptionList/CacheContent';
10
+ import useKeyboard from 'rc-cascader/es/OptionList/useKeyboard';
10
11
  import { getFullPathKeys, isLeaf, scrollIntoParentView, toPathKey, toPathKeys, toPathValueStr } from 'rc-cascader/es/utils/commonUtil';
11
12
  import { toPathOptions } from 'rc-cascader/es/utils/treeUtil';
12
- import CacheContent from 'rc-cascader/es/OptionList/CacheContent';
13
+ import * as React from 'react';
13
14
  import Column, { FIX_LABEL } from "./Column";
14
15
  import useActive from "./useActive";
15
- import useKeyboard from 'rc-cascader/es/OptionList/useKeyboard';
16
16
  var RawOptionList = /*#__PURE__*/React.forwardRef(function (props, ref) {
17
17
  var _optionColumns$, _ref3, _classNames;
18
18
  var prefixCls = props.prefixCls,
@@ -180,7 +180,7 @@ var RawOptionList = /*#__PURE__*/React.forwardRef(function (props, ref) {
180
180
  var _containerRef$current;
181
181
  var cellPath = activeValueCells.slice(0, i + 1);
182
182
  var cellKeyPath = toPathKey(cellPath);
183
- var ele = (_containerRef$current = containerRef.current) === null || _containerRef$current === void 0 ? void 0 : _containerRef$current.querySelector("li[data-path-key=\"".concat(cellKeyPath.replace(/\\{0,2}"/g, '\\"'), "\"]") // matches unescaped double quotes
183
+ var ele = (_containerRef$current = containerRef.current) === null || _containerRef$current === void 0 ? void 0 : _containerRef$current.querySelector('li[data-path-key="'.concat(cellKeyPath.replace(/\\{0,2}"/g, '\\"'), '"]') // matches unescaped double quotes
184
184
  );
185
185
  if (ele) {
186
186
  scrollIntoParentView(ele);
@@ -191,7 +191,7 @@ var RawOptionList = /*#__PURE__*/React.forwardRef(function (props, ref) {
191
191
  // ========================== Render ==========================
192
192
  // >>>>> Empty
193
193
  var isEmpty = !((_optionColumns$ = optionColumns[0]) !== null && _optionColumns$ !== void 0 && (_optionColumns$ = _optionColumns$.options) !== null && _optionColumns$ !== void 0 && _optionColumns$.length);
194
- var emptyList = [(_ref3 = {}, _defineProperty(_ref3, fieldNames.value, '__EMPTY__'), _defineProperty(_ref3, FIX_LABEL, notFoundContent), _defineProperty(_ref3, "disabled", true), _ref3)];
194
+ var emptyList = [(_ref3 = {}, _defineProperty(_ref3, fieldNames.value, '__EMPTY__'), _defineProperty(_ref3, FIX_LABEL, notFoundContent), _defineProperty(_ref3, 'disabled', true), _ref3)];
195
195
  var columnProps = _objectSpread(_objectSpread({}, props), {}, {
196
196
  multiple: !isEmpty && multiple,
197
197
  onSelect: onPathSelect,
@@ -207,88 +207,6 @@ var RawOptionList = /*#__PURE__*/React.forwardRef(function (props, ref) {
207
207
  var mergedOptionColumns = isEmpty ? [{
208
208
  options: emptyList
209
209
  }] : optionColumns;
210
-
211
- // 面板已展开时,列数变化驱动宽度过渡;仅新增的那一列做进入动效
212
- var prevOpenRef = React.useRef(false);
213
- var prevColCountRef = React.useRef(0);
214
- var prevWidthRef = React.useRef(null);
215
- var widthMotionEndRef = React.useRef(null);
216
- var colCount = mergedOptionColumns.length;
217
- var _React$useStateEnter = React.useState(-1),
218
- _React$useStateEnter2 = _slicedToArray(_React$useStateEnter, 2),
219
- enterColumnIndex = _React$useStateEnter2[0],
220
- setEnterColumnIndex = _React$useStateEnter2[1];
221
- React.useLayoutEffect(function () {
222
- var el = containerRef.current;
223
- var wasOpen = prevOpenRef.current;
224
- var prevColCount = prevColCountRef.current;
225
- prevOpenRef.current = !!open;
226
- prevColCountRef.current = open ? colCount : 0;
227
- if (!el) {
228
- return undefined;
229
- }
230
- if (!open) {
231
- prevWidthRef.current = null;
232
- el.style.width = '';
233
- el.style.transition = '';
234
- el.style.overflow = '';
235
- setEnterColumnIndex(-1);
236
- return undefined;
237
- }
238
- var nextWidth = el.offsetWidth;
239
- var prevWidth = prevWidthRef.current;
240
- prevWidthRef.current = nextWidth;
241
- var reduceMotion = typeof window !== 'undefined' && window.matchMedia('(prefers-reduced-motion: reduce)').matches;
242
- var timers = [];
243
- // 已展开时新增列:给新列进入动效
244
- if (wasOpen && !reduceMotion && colCount > prevColCount) {
245
- setEnterColumnIndex(colCount - 1);
246
- timers.push(window.setTimeout(function () {
247
- setEnterColumnIndex(-1);
248
- }, 220));
249
- }
250
- // 首次打开不动画,避免整板滑入;仅在已展开时宽度变化过渡
251
- if (!wasOpen || reduceMotion || prevWidth == null || prevWidth === nextWidth) {
252
- return function () {
253
- timers.forEach(function (id) {
254
- return window.clearTimeout(id);
255
- });
256
- };
257
- }
258
- if (widthMotionEndRef.current) {
259
- el.removeEventListener('transitionend', widthMotionEndRef.current);
260
- widthMotionEndRef.current = null;
261
- }
262
- el.style.transition = 'none';
263
- el.style.overflow = 'hidden';
264
- el.style.width = "".concat(prevWidth, "px");
265
- // force reflow
266
- el.offsetWidth;
267
- el.style.transition = "width var(--odn-cascader-panel-motion-duration, 0.22s) var(--odn-cascader-panel-motion-ease, cubic-bezier(0.32, 0.72, 0, 1))";
268
- el.style.width = "".concat(nextWidth, "px");
269
- var onEnd = function onEnd(event) {
270
- if (event.target !== el || event.propertyName !== 'width') {
271
- return;
272
- }
273
- el.style.width = '';
274
- el.style.transition = '';
275
- el.style.overflow = '';
276
- el.removeEventListener('transitionend', onEnd);
277
- widthMotionEndRef.current = null;
278
- prevWidthRef.current = el.offsetWidth;
279
- };
280
- widthMotionEndRef.current = onEnd;
281
- el.addEventListener('transitionend', onEnd);
282
- return function () {
283
- timers.forEach(function (id) {
284
- return window.clearTimeout(id);
285
- });
286
- el.removeEventListener('transitionend', onEnd);
287
- if (widthMotionEndRef.current === onEnd) {
288
- widthMotionEndRef.current = null;
289
- }
290
- };
291
- }, [colCount, searchValue, open, isEmpty]);
292
210
  var columnNodes = mergedOptionColumns.map(function (col, index) {
293
211
  var prevValuePath = activeValueCells.slice(0, index);
294
212
  var activeValue = activeValueCells[index];
@@ -298,16 +216,15 @@ var RawOptionList = /*#__PURE__*/React.forwardRef(function (props, ref) {
298
216
  prefixCls: mergedPrefixCls,
299
217
  options: col.options,
300
218
  prevValuePath: prevValuePath,
301
- activeValue: activeValue,
302
- motionEnter: index === enterColumnIndex
219
+ activeValue: activeValue
303
220
  }));
304
221
  });
305
222
 
306
223
  // >>>>> Render
307
224
  return /*#__PURE__*/React.createElement(CacheContent, {
308
225
  open: open
309
- }, /*#__PURE__*/React.createElement("div", {
310
- className: classNames("".concat(mergedPrefixCls, "-menus"), (_classNames = {}, _defineProperty(_classNames, "".concat(mergedPrefixCls, "-menu-empty"), isEmpty), _defineProperty(_classNames, "".concat(mergedPrefixCls, "-rtl"), rtl), _classNames)),
226
+ }, /*#__PURE__*/React.createElement('div', {
227
+ className: classNames(''.concat(mergedPrefixCls, '-menus'), (_classNames = {}, _defineProperty(_classNames, ''.concat(mergedPrefixCls, '-menu-empty'), isEmpty), _defineProperty(_classNames, ''.concat(mergedPrefixCls, '-rtl'), rtl), _classNames)),
311
228
  ref: containerRef
312
229
  }, columnNodes));
313
230
  });
@@ -1,4 +1,4 @@
1
- import _extends from "@babel/runtime/helpers/esm/extends";
1
+ import _extends from '@babel/runtime/helpers/esm/extends';
2
2
  import { useBaseProps } from 'rc-select';
3
3
  import * as React from 'react';
4
4
  import RawOptionList from "./List";
@@ -1,6 +1,12 @@
1
1
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
- import * as React from 'react';
3
2
  import CascaderContext from 'rc-cascader/es/context';
3
+ import * as React from 'react';
4
+ var getStrictActivePath = function getStrictActivePath(path) {
5
+ if (!(path !== null && path !== void 0 && path.length)) {
6
+ return [];
7
+ }
8
+ return path.slice(0, -1);
9
+ };
4
10
 
5
11
  /**
6
12
  * Control the active open options path.
@@ -17,31 +23,51 @@ var useActive = function useActive(multiple, open) {
17
23
  activeValueCells = _React$useState2[0],
18
24
  setActiveValueCells = _React$useState2[1];
19
25
  var prevOpenRef = React.useRef(open);
20
- React.useEffect(function () {
21
- var justOpened = open && !prevOpenRef.current;
22
- prevOpenRef.current = open;
26
+ var justOpened = open && !prevOpenRef.current;
27
+ prevOpenRef.current = open;
28
+ React.useLayoutEffect(function () {
23
29
  if (checkStrictly) {
24
30
  if (multiple) {
25
- // 多选:仅在打开面板时定位到选中值所在层级,勾选不重置展开路径
26
31
  if (justOpened) {
27
- var path = firstValueCells || [];
28
- setActiveValueCells(path.slice(0, -1));
32
+ setActiveValueCells(getStrictActivePath(firstValueCells));
29
33
  }
30
34
  return;
31
35
  }
32
- // 单选:打开或值变化时定位(选中后会收起面板)
33
36
  if (open) {
34
- var _path = firstValueCells || [];
35
- setActiveValueCells(_path.slice(0, -1));
37
+ setActiveValueCells(getStrictActivePath(firstValueCells));
36
38
  }
37
39
  return;
38
40
  }
39
- if (!multiple) {
41
+ if (!multiple && (justOpened || open)) {
40
42
  setActiveValueCells(firstValueCells || []);
41
43
  }
42
- },
43
- // eslint-disable-next-line react-hooks/exhaustive-deps
44
- [open, firstValueCells, checkStrictly, multiple]);
45
- return [activeValueCells, setActiveValueCells];
44
+ }, [open, firstValueCells, checkStrictly, multiple, justOpened]);
45
+
46
+ // 打开首帧即用目标路径渲染列,避免弹层先窄后宽导致定位跳动
47
+ var mergedActiveValueCells = React.useMemo(function () {
48
+ if (!open) {
49
+ return activeValueCells;
50
+ }
51
+ if (checkStrictly) {
52
+ if (justOpened) {
53
+ return getStrictActivePath(firstValueCells);
54
+ }
55
+ if (activeValueCells.length > 0) {
56
+ return activeValueCells;
57
+ }
58
+ return getStrictActivePath(firstValueCells);
59
+ }
60
+ if (multiple) {
61
+ return activeValueCells;
62
+ }
63
+ if (justOpened) {
64
+ return firstValueCells || [];
65
+ }
66
+ if (activeValueCells.length > 0) {
67
+ return activeValueCells;
68
+ }
69
+ return firstValueCells || [];
70
+ }, [activeValueCells, checkStrictly, firstValueCells, justOpened, multiple, open]);
71
+ return [mergedActiveValueCells, setActiveValueCells];
46
72
  };
47
73
  export default useActive;
@@ -1,16 +1,16 @@
1
- import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
- import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
1
+ import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
2
+ import _slicedToArray from '@babel/runtime/helpers/esm/slicedToArray';
3
3
  import classNames from 'classnames';
4
- import { useEvent, useMergedState } from 'rc-util';
5
- import * as React from 'react';
6
4
  import CascaderContext from 'rc-cascader/es/context';
7
5
  import useMissingValues from 'rc-cascader/es/hooks/useMissingValues';
8
6
  import useOptions from 'rc-cascader/es/hooks/useOptions';
7
+ import { fillFieldNames, toRawValues } from 'rc-cascader/es/utils/commonUtil';
8
+ import { toPathOptions } from 'rc-cascader/es/utils/treeUtil';
9
+ import { useEvent, useMergedState } from 'rc-util';
10
+ import * as React from 'react';
9
11
  import useSelect from "./hooks/useSelect";
10
12
  import useValues from "./hooks/useValues";
11
13
  import RawOptionList from "./OptionList/List";
12
- import { fillFieldNames, toRawValues } from 'rc-cascader/es/utils/commonUtil';
13
- import { toPathOptions } from 'rc-cascader/es/utils/treeUtil';
14
14
  function noop() {}
15
15
  export default function Panel(props) {
16
16
  var _classNames;
@@ -54,8 +54,7 @@ export default function Panel(props) {
54
54
  // ========================= FieldNames =========================
55
55
  var mergedFieldNames = React.useMemo(function () {
56
56
  return fillFieldNames(fieldNames);
57
- }, /* eslint-disable react-hooks/exhaustive-deps */
58
- [JSON.stringify(fieldNames)]
57
+ } /* eslint-disable react-hooks/exhaustive-deps */, [JSON.stringify(fieldNames)]
59
58
  /* eslint-enable react-hooks/exhaustive-deps */);
60
59
 
61
60
  // =========================== Option ===========================
@@ -121,16 +120,16 @@ export default function Panel(props) {
121
120
  }, [mergedOptions, mergedFieldNames, checkedValues, halfCheckedValues, mergedChangeOnSelect, onInternalSelect, checkable, checkStrictly, loadData, expandTrigger, expandIcon, loadingIcon]);
122
121
 
123
122
  // ========================= Render =========================
124
- var panelPrefixCls = "".concat(prefixCls, "-panel");
123
+ var panelPrefixCls = ''.concat(prefixCls, '-panel');
125
124
  var isEmpty = !mergedOptions.length;
126
125
  return /*#__PURE__*/React.createElement(CascaderContext.Provider, {
127
126
  value: cascaderContext
128
- }, /*#__PURE__*/React.createElement("div", {
129
- className: classNames(panelPrefixCls, (_classNames = {}, _defineProperty(_classNames, "".concat(panelPrefixCls, "-rtl"), direction === 'rtl'), _defineProperty(_classNames, "".concat(panelPrefixCls, "-empty"), isEmpty), _classNames), className),
127
+ }, /*#__PURE__*/React.createElement('div', {
128
+ className: classNames(panelPrefixCls, (_classNames = {}, _defineProperty(_classNames, ''.concat(panelPrefixCls, '-rtl'), direction === 'rtl'), _defineProperty(_classNames, ''.concat(panelPrefixCls, '-empty'), isEmpty), _classNames), className),
130
129
  style: style
131
130
  }, isEmpty ? notFoundContent : /*#__PURE__*/React.createElement(RawOptionList, {
132
131
  prefixCls: prefixCls,
133
- searchValue: "",
132
+ searchValue: '',
134
133
  multiple: multiple,
135
134
  toggleOpen: noop,
136
135
  open: true,
@@ -1,7 +1,4 @@
1
- import type {
2
- CascaderProps,
3
- DefaultOptionType,
4
- } from 'rc-cascader';
1
+ import type { CascaderProps, DefaultOptionType } from 'rc-cascader';
5
2
  import type * as React from 'react';
6
3
 
7
4
  export { SHOW_CHILD, SHOW_PARENT } from 'rc-cascader';
@@ -12,6 +9,8 @@ export type ForkCascaderProps<
12
9
  Multiple extends boolean | React.ReactNode = false,
13
10
  > = CascaderProps<OptionType, ValueField, Multiple> & {
14
11
  checkStrictly?: boolean;
12
+ /** 下拉内搜索:为 true 时不占用 selector 内的搜索后缀宽度 */
13
+ showInnerSearch?: boolean;
15
14
  };
16
15
 
17
16
  type CascaderComponent = (<
@@ -3,7 +3,6 @@ import React from 'react';
3
3
  import '../select/style';
4
4
  import CascaderPanel from './Panel';
5
5
  import './style';
6
- import { type ExpandDirection } from './utils';
7
6
  export interface BaseCascaderProps extends Omit<RcCascaderProps<DefaultOptionType, 'value', false>, 'prefixCls' | 'onChange' | 'value' | 'defaultValue' | 'showCheckedStrategy' | 'changeOnSelect'> {
8
7
  /** 组件尺寸 */
9
8
  size?: 'small' | 'medium' | 'large';
@@ -52,14 +51,6 @@ export interface BaseCascaderProps extends Omit<RcCascaderProps<DefaultOptionTyp
52
51
  * 点击选项或勾选控件选中,仅点击展开图标展开下一级;多选时父子节点选择互不影响(无半选)。
53
52
  */
54
53
  crossLevelSelect?: boolean;
55
- /**
56
- * 弹层生长方向(不影响列阅读顺序,层级始终从左到右加深,展开 Icon 不翻转):
57
- * - `ltr` 左对齐,整体向右生长
58
- * - `rtl` 右对齐,整体向左生长(避免靠右时超出屏幕)
59
- * - `auto` 根据 selector 相对视口位置自动选择
60
- * `crossLevelSelect` 时默认 `auto`,否则默认 `ltr`。
61
- */
62
- expandDirection?: ExpandDirection;
63
54
  }
64
55
  export type CascaderProps<V = (string | number)[] | null> = BaseCascaderProps & {
65
56
  mode?: 'single' | 'multiple';
@@ -1,13 +1,12 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import _typeof from "@babel/runtime/helpers/esm/typeof";
3
- import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
4
3
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
4
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
5
5
  import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
6
6
  import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
7
- var _excluded = ["size", "disabled", "placeholder", "allowClear", "showSearch", "className", "style", "light", "visible", "onVisibleChange", "onChange", "value", "defaultValue", "suffixIcon", "mode", "options", "optionPopoverProps", "showInnerSearch", "searchValue", "onSearch", "autoClearSearchValue", "searchFilter", "searchRender", "searchLimit", "notFoundContent", "showCheckedStrategy", "displayRender", "dropdownClassName", "dropdownMatchSelectWidth", "separator", "optionRender", "changeOnSelect", "crossLevelSelect", "expandDirection", "maxTagCount", "maxTagPlaceholder", "direction", "placement", "getPopupContainer"];
7
+ var _excluded = ["size", "disabled", "placeholder", "allowClear", "showSearch", "className", "style", "light", "visible", "onVisibleChange", "onChange", "value", "defaultValue", "suffixIcon", "mode", "options", "optionPopoverProps", "showInnerSearch", "searchValue", "onSearch", "autoClearSearchValue", "searchFilter", "searchRender", "searchLimit", "notFoundContent", "showCheckedStrategy", "displayRender", "dropdownClassName", "dropdownMatchSelectWidth", "separator", "optionRender", "changeOnSelect", "crossLevelSelect", "maxTagCount", "maxTagPlaceholder", "direction", "placement", "getPopupContainer"];
8
8
  import clsx from 'clsx';
9
9
  import React, { useEffect, useMemo, useRef, useState } from 'react';
10
- import { flushSync } from 'react-dom';
11
10
  import Icon from "../icon";
12
11
  import "../select/style";
13
12
  import useIcons from "../select/useIcons";
@@ -16,7 +15,7 @@ import RcCascader, { SHOW_CHILD, SHOW_PARENT } from "./fork";
16
15
  import CascaderPanel from "./Panel";
17
16
  import SelectedSummary from "./SelectedSummary";
18
17
  import "./style";
19
- import { calculateOptionsDepth, DEFAULT_FIELD_NAMES, getExpandBuiltinPlacements, processOptions, resolveExpandDirection } from "./utils";
18
+ import { DEFAULT_FIELD_NAMES, processOptions } from "./utils";
20
19
  function getPathLeafLabel(path, optionList, valueField, childrenField) {
21
20
  var current = optionList;
22
21
  var leaf;
@@ -104,7 +103,6 @@ function CascaderInner(_ref) {
104
103
  changeOnSelectProp = _ref.changeOnSelect,
105
104
  _ref$crossLevelSelect = _ref.crossLevelSelect,
106
105
  crossLevelSelect = _ref$crossLevelSelect === void 0 ? false : _ref$crossLevelSelect,
107
- expandDirectionProp = _ref.expandDirection,
108
106
  maxTagCountProp = _ref.maxTagCount,
109
107
  maxTagPlaceholderProp = _ref.maxTagPlaceholder,
110
108
  directionProp = _ref.direction,
@@ -115,13 +113,6 @@ function CascaderInner(_ref) {
115
113
  var showInnerSearch = showInnerSearchProp !== null && showInnerSearchProp !== void 0 ? showInnerSearchProp : crossLevelSelect;
116
114
  // 跨层级多选:勾选后不自动清空搜索,避免搜索结果被收起
117
115
  var autoClearSearchValue = autoClearSearchValueProp !== null && autoClearSearchValueProp !== void 0 ? autoClearSearchValueProp : !(crossLevelSelect && mode === 'multiple');
118
- // 跨层级默认按位置自动适配展开方向
119
- var expandDirection = expandDirectionProp !== null && expandDirectionProp !== void 0 ? expandDirectionProp : crossLevelSelect ? 'auto' : 'ltr';
120
- var instanceId = React.useId().replace(/:/g, '');
121
- var _useState = useState(expandDirection === 'rtl' ? 'rtl' : 'ltr'),
122
- _useState2 = _slicedToArray(_useState, 2),
123
- resolvedDirection = _useState2[0],
124
- setResolvedDirection = _useState2[1];
125
116
 
126
117
  // 默认 fieldNames.label 为 labelWithPopover,下拉展示带 Popover 的节点,用户传入的 label 保留
127
118
  var mergedFieldNames = React.useMemo(function () {
@@ -149,37 +140,6 @@ function CascaderInner(_ref) {
149
140
  var processedOptions = React.useMemo(function () {
150
141
  return processOptions(options, mergedFieldNames, optionPopoverProps);
151
142
  }, [options, mergedFieldNames, optionPopoverProps]);
152
- var optionsDepth = useMemo(function () {
153
- return calculateOptionsDepth(processedOptions, mergedFieldNames);
154
- }, [processedOptions, mergedFieldNames]);
155
-
156
- // expandDirection 只控制弹层锚点(靠右时向左生长),列阅读顺序始终从左到右、层级加深向右
157
- var panelExpandSide = expandDirection === 'auto' ? resolvedDirection : expandDirection;
158
- var mergedDirection = directionProp !== null && directionProp !== void 0 ? directionProp : 'ltr';
159
-
160
- /**
161
- * rtl:弹层右对齐 trigger、向左生长。打开前(pointerdown / onOpenChange)
162
- * 已算好方向,配合 bottomRight + adjustX:0 避免首帧横向跳动。
163
- * 弹层默认仍挂 document.body(不传 getPopupContainer 时)。
164
- */
165
- var mergedPlacement = placementProp !== null && placementProp !== void 0 ? placementProp : panelExpandSide === 'rtl' ? 'bottomRight' : 'bottomLeft';
166
- var builtinPlacements = useMemo(function () {
167
- return getExpandBuiltinPlacements();
168
- }, []);
169
- var syncAutoExpandDirection = function syncAutoExpandDirection() {
170
- var _ref2, _root$querySelector;
171
- if (expandDirection !== 'auto') {
172
- return;
173
- }
174
- var root = document.querySelector(".odn-cascader-uid-".concat(instanceId));
175
- var selector = (_ref2 = (_root$querySelector = root === null || root === void 0 ? void 0 : root.querySelector('.odn-select-selector')) !== null && _root$querySelector !== void 0 ? _root$querySelector : root) !== null && _ref2 !== void 0 ? _ref2 : null;
176
- var nextDirection = resolveExpandDirection(selector, optionsDepth);
177
- flushSync(function () {
178
- setResolvedDirection(function (prev) {
179
- return prev === nextDirection ? prev : nextDirection;
180
- });
181
- });
182
- };
183
143
  var prefixCls = 'odn-select';
184
144
  var _useIcons = useIcons(_objectSpread(_objectSpread({}, restProps), {}, {
185
145
  hasFeedback: false,
@@ -191,44 +151,17 @@ function CascaderInner(_ref) {
191
151
  suffixIcon = _useIcons.suffixIcon,
192
152
  removeIcon = _useIcons.removeIcon,
193
153
  clearIcon = _useIcons.clearIcon;
194
- var cascaderClassName = [prefixCls, "".concat(prefixCls, "-").concat(size), disabled && "".concat(prefixCls, "-disabled"), light && "".concat(prefixCls, "-light"), !light && "".concat(prefixCls, "-outlined"), "".concat(prefixCls, "-show-arrow"), showInnerSearch && "".concat(prefixCls, "-show-inner-search"), 'odn-cascader', crossLevelSelect && 'odn-cascader-cross-level', "odn-cascader-uid-".concat(instanceId), panelExpandSide === 'rtl' && 'odn-cascader-expand-rtl', className].filter(Boolean).join(' ');
195
- var _useState3 = useState(visibleProp),
154
+ var cascaderClassName = [prefixCls, "".concat(prefixCls, "-").concat(size), disabled && "".concat(prefixCls, "-disabled"), light && "".concat(prefixCls, "-light"), !light && "".concat(prefixCls, "-outlined"), "".concat(prefixCls, "-show-arrow"), showInnerSearch && "".concat(prefixCls, "-show-inner-search"), 'odn-cascader', crossLevelSelect && 'odn-cascader-cross-level', className].filter(Boolean).join(' ');
155
+ var _useState = useState(visibleProp),
156
+ _useState2 = _slicedToArray(_useState, 2),
157
+ visible = _useState2[0],
158
+ setVisible = _useState2[1];
159
+ var _useState3 = useState(searchValueProp || ''),
196
160
  _useState4 = _slicedToArray(_useState3, 2),
197
- visible = _useState4[0],
198
- setVisible = _useState4[1];
199
- var _useState5 = useState(searchValueProp || ''),
200
- _useState6 = _slicedToArray(_useState5, 2),
201
- searchValue = _useState6[0],
202
- setSearchValue = _useState6[1];
161
+ searchValue = _useState4[0],
162
+ setSearchValue = _useState4[1];
203
163
  var dropdownSearchInputRef = useRef(null);
204
- useEffect(function () {
205
- if (expandDirection === 'ltr' || expandDirection === 'rtl') {
206
- setResolvedDirection(expandDirection);
207
- }
208
- }, [expandDirection]);
209
-
210
- // 在打开前(pointerdown)就算好 auto 方向,避免打开后再切换 rtl class / placement
211
- useEffect(function () {
212
- if (expandDirection !== 'auto') {
213
- return undefined;
214
- }
215
- var root = document.querySelector(".odn-cascader-uid-".concat(instanceId));
216
- if (!root) {
217
- return undefined;
218
- }
219
- var onPointerDown = function onPointerDown() {
220
- syncAutoExpandDirection();
221
- };
222
- root.addEventListener('pointerdown', onPointerDown, true);
223
- return function () {
224
- root.removeEventListener('pointerdown', onPointerDown, true);
225
- };
226
- // eslint-disable-next-line react-hooks/exhaustive-deps -- 仅在关键参数变化时重绑
227
- }, [expandDirection, instanceId, optionsDepth]);
228
164
  var handleVisibleChange = function handleVisibleChange(bool) {
229
- if (bool && expandDirection === 'auto') {
230
- syncAutoExpandDirection();
231
- }
232
165
  if (visibleProp === undefined) {
233
166
  setVisible(bool);
234
167
  }
@@ -315,8 +248,11 @@ function CascaderInner(_ref) {
315
248
  return optionList;
316
249
  };
317
250
  var mergedShowSearch = React.useMemo(function () {
251
+ if (!showInnerSearch && !showSearch) {
252
+ return false;
253
+ }
318
254
  if (!showInnerSearch) {
319
- return showInnerSearch;
255
+ return showSearch;
320
256
  }
321
257
  var searchConfig = {
322
258
  filter: searchFilter || function (inputValue, path) {
@@ -328,8 +264,8 @@ function CascaderInner(_ref) {
328
264
  limit: searchLimit
329
265
  };
330
266
  return searchConfig;
331
- }, [showInnerSearch, searchFilter, searchRender, searchLimit]);
332
- var commonProps = _objectSpread(_objectSpread(_objectSpread({}, restProps), {}, {
267
+ }, [showInnerSearch, showSearch, searchFilter, searchRender, searchLimit]);
268
+ var commonProps = _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, restProps), {}, {
333
269
  fieldNames: mergedFieldNames,
334
270
  prefixCls: prefixCls,
335
271
  disabled: disabled,
@@ -394,14 +330,15 @@ function CascaderInner(_ref) {
394
330
  optionRender: optionRenderProp,
395
331
  changeOnSelect: !!changeOnSelectProp || crossLevelSelect,
396
332
  checkStrictly: crossLevelSelect,
333
+ showInnerSearch: showInnerSearch,
397
334
  maxTagCount: mergedMaxTagCount,
398
- maxTagPlaceholder: mergedMaxTagPlaceholder,
399
- direction: mergedDirection,
400
- placement: mergedPlacement
401
- }, getPopupContainerProp ? {
335
+ maxTagPlaceholder: mergedMaxTagPlaceholder
336
+ }, directionProp ? {
337
+ direction: directionProp
338
+ } : {}), placementProp ? {
339
+ placement: placementProp
340
+ } : {}), getPopupContainerProp ? {
402
341
  getPopupContainer: getPopupContainerProp
403
- } : {}), panelExpandSide === 'rtl' ? {
404
- builtinPlacements: builtinPlacements
405
342
  } : {});
406
343
  var dropdownRender = showInnerSearch ? function (menu) {
407
344
  var searchNode = /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
@@ -3,8 +3,6 @@ html {
3
3
  --odn-cascader-control-width: 184px;
4
4
  --odn-cascader-control-item-width: 200px;
5
5
  --odn-cascader-dropdown-height: 232px;
6
- --odn-cascader-panel-motion-duration: 0.22s;
7
- --odn-cascader-panel-motion-ease: cubic-bezier(0.32, 0.72, 0, 1);
8
6
  --odn-cascader-option-selected-bg: var(--odn-color-blue-1);
9
7
  --odn-cascader-option-selected-font-weight: 400;
10
8
  --odn-cascader-option-padding-block: 7px;
@@ -15,6 +13,7 @@ html {
15
13
  --odn-cascader-panel-border-radius: 6px;
16
14
  }
17
15
 
16
+ /* stylelint-disable no-descending-specificity, no-duplicate-selectors */
18
17
  .odn-cascader {
19
18
  width: var(--odn-cascader-control-width);
20
19
  }
@@ -12,51 +12,3 @@ export declare const DEFAULT_FIELD_NAMES: FieldNames;
12
12
  export declare const processOptions: (options: DefaultOptionType[] | undefined, fieldNames?: FieldNames, optionPopoverProps?: Record<string, unknown>) => DefaultOptionType[] | undefined;
13
13
  export declare const calculateOptionsDepth: (options: DefaultOptionType[] | undefined, fieldNames?: FieldNames) => number;
14
14
  export declare const generateCommonStyle: (depth: number, autoMaxWidth: boolean, customStyle?: React.CSSProperties) => React.CSSProperties;
15
- export type ExpandDirection = 'ltr' | 'rtl' | 'auto';
16
- /**
17
- * Cascader 自管水平锚点(expandDirection),关闭 adjustX,
18
- * 避免 Trigger 首帧按溢出翻转后再纠正造成「先错后对」。
19
- */
20
- export declare const getExpandBuiltinPlacements: () => {
21
- bottomLeft: {
22
- points: [string, string];
23
- offset: number[];
24
- overflow: {
25
- adjustX: number;
26
- adjustY: number;
27
- };
28
- htmlRegion: "scroll";
29
- };
30
- bottomRight: {
31
- points: [string, string];
32
- offset: number[];
33
- overflow: {
34
- adjustX: number;
35
- adjustY: number;
36
- };
37
- htmlRegion: "scroll";
38
- };
39
- topLeft: {
40
- points: [string, string];
41
- offset: number[];
42
- overflow: {
43
- adjustX: number;
44
- adjustY: number;
45
- };
46
- htmlRegion: "scroll";
47
- };
48
- topRight: {
49
- points: [string, string];
50
- offset: number[];
51
- overflow: {
52
- adjustX: number;
53
- adjustY: number;
54
- };
55
- htmlRegion: "scroll";
56
- };
57
- };
58
- /**
59
- * 根据 selector 相对视口的位置,决定弹层左对齐向右生长(ltr)
60
- * 还是右对齐向左生长(rtl)。列阅读顺序始终从左到右。
61
- */
62
- export declare const resolveExpandDirection: (triggerEl: Element | null | undefined, depth: number, columnMinWidth?: number) => 'ltr' | 'rtl';
@@ -47,7 +47,7 @@ export var processOptions = function processOptions(options, fieldNames, optionP
47
47
  });
48
48
 
49
49
  // 记录一个自定义的固定的属性,用以处理 search 逻辑
50
- processedOption['labelForSearch'] = displayContent != null && (typeof displayContent === 'string' || typeof displayContent === 'number') ? String(displayContent) : '';
50
+ processedOption['labelForSearch'] = displayContent !== null && displayContent !== undefined && (typeof displayContent === 'string' || typeof displayContent === 'number') ? String(displayContent) : '';
51
51
 
52
52
  // 递归处理 children
53
53
  var childrenField = (fieldNames === null || fieldNames === void 0 ? void 0 : fieldNames.children) || 'children';
@@ -96,75 +96,4 @@ export var generateCommonStyle = function generateCommonStyle(depth, autoMaxWidt
96
96
  return _objectSpread({
97
97
  '--odn-cascader-panel-column-flex': autoMaxWidth ? "0 0 ".concat(100 / depth, "%") : '1 1 0%'
98
98
  }, customStyle);
99
- };
100
- var DEFAULT_COLUMN_MIN_WIDTH = 200;
101
-
102
- /**
103
- * Cascader 自管水平锚点(expandDirection),关闭 adjustX,
104
- * 避免 Trigger 首帧按溢出翻转后再纠正造成「先错后对」。
105
- */
106
- export var getExpandBuiltinPlacements = function getExpandBuiltinPlacements() {
107
- var adjustX = 0;
108
- var adjustY = 1;
109
- return {
110
- bottomLeft: {
111
- points: ['tl', 'bl'],
112
- offset: [0, 4],
113
- overflow: {
114
- adjustX: adjustX,
115
- adjustY: adjustY
116
- },
117
- htmlRegion: 'scroll'
118
- },
119
- bottomRight: {
120
- points: ['tr', 'br'],
121
- offset: [0, 4],
122
- overflow: {
123
- adjustX: adjustX,
124
- adjustY: adjustY
125
- },
126
- htmlRegion: 'scroll'
127
- },
128
- topLeft: {
129
- points: ['bl', 'tl'],
130
- offset: [0, -4],
131
- overflow: {
132
- adjustX: adjustX,
133
- adjustY: adjustY
134
- },
135
- htmlRegion: 'scroll'
136
- },
137
- topRight: {
138
- points: ['br', 'tr'],
139
- offset: [0, -4],
140
- overflow: {
141
- adjustX: adjustX,
142
- adjustY: adjustY
143
- },
144
- htmlRegion: 'scroll'
145
- }
146
- };
147
- };
148
-
149
- /**
150
- * 根据 selector 相对视口的位置,决定弹层左对齐向右生长(ltr)
151
- * 还是右对齐向左生长(rtl)。列阅读顺序始终从左到右。
152
- */
153
- export var resolveExpandDirection = function resolveExpandDirection(triggerEl, depth) {
154
- var columnMinWidth = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : DEFAULT_COLUMN_MIN_WIDTH;
155
- if (!triggerEl || typeof window === 'undefined') {
156
- return 'ltr';
157
- }
158
- var rect = triggerEl.getBoundingClientRect();
159
- var columns = Math.max(1, Math.min(depth, 4));
160
- var neededWidth = columns * columnMinWidth;
161
- var spaceRight = window.innerWidth - rect.left;
162
- var spaceLeft = rect.right;
163
- if (spaceRight >= neededWidth) {
164
- return 'ltr';
165
- }
166
- if (spaceLeft > spaceRight) {
167
- return 'rtl';
168
- }
169
- return 'ltr';
170
99
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "one-design-next",
3
- "version": "0.0.64",
3
+ "version": "0.0.65",
4
4
  "description": "One Design Next from TAD@tencent.com",
5
5
  "license": "MIT",
6
6
  "type": "module",