@rc-component/cascader 1.12.0 → 1.13.0

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.
@@ -190,7 +190,7 @@ export default function Column({
190
190
  }
191
191
  }), /*#__PURE__*/React.createElement("div", {
192
192
  className: `${menuItemPrefixCls}-content`
193
- }, optionRender ? optionRender(option) : label), !isLoading && expandIcon && !isMergedLeaf && /*#__PURE__*/React.createElement("div", {
193
+ }, optionRender && value !== '__EMPTY__' ? optionRender(option) : label), !isLoading && expandIcon && !isMergedLeaf && /*#__PURE__*/React.createElement("div", {
194
194
  className: `${menuItemPrefixCls}-expand-icon`
195
195
  }, expandIcon), isLoading && loadingIcon && /*#__PURE__*/React.createElement("div", {
196
196
  className: `${menuItemPrefixCls}-loading-icon`
@@ -1,6 +1,10 @@
1
1
  import type { useBaseProps } from '@rc-component/select';
2
2
  import type { RefOptionListProps } from '@rc-component/select/lib/OptionList';
3
3
  import * as React from 'react';
4
- export type RawOptionListProps = Pick<ReturnType<typeof useBaseProps>, 'prefixCls' | 'multiple' | 'searchValue' | 'toggleOpen' | 'notFoundContent' | 'direction' | 'open' | 'disabled'>;
5
- declare const RawOptionList: React.ForwardRefExoticComponent<RawOptionListProps & React.RefAttributes<RefOptionListProps>>;
4
+ export type RawOptionListProps = Pick<ReturnType<typeof useBaseProps>, 'prefixCls' | 'multiple' | 'searchValue' | 'toggleOpen' | 'notFoundContent' | 'direction' | 'open' | 'disabled'> & {
5
+ lockOptions?: boolean;
6
+ };
7
+ declare const RawOptionList: React.ForwardRefExoticComponent<Pick<import("@rc-component/select/lib/hooks/useBaseProps").BaseSelectContextProps, "disabled" | "prefixCls" | "multiple" | "searchValue" | "direction" | "notFoundContent" | "open" | "toggleOpen"> & {
8
+ lockOptions?: boolean | undefined;
9
+ } & React.RefAttributes<RefOptionListProps>>;
6
10
  export default RawOptionList;
@@ -2,10 +2,10 @@ function _extends() { _extends = Object.assign ? Object.assign.bind() : function
2
2
  /* eslint-disable default-case */
3
3
  import { clsx } from 'clsx';
4
4
  import * as React from 'react';
5
+ import useMemo from "@rc-component/util/es/hooks/useMemo";
5
6
  import CascaderContext from "../context";
6
7
  import { getFullPathKeys, isLeaf, scrollIntoParentView, toPathKey, toPathKeys, toPathValueStr } from "../utils/commonUtil";
7
8
  import { toPathOptions } from "../utils/treeUtil";
8
- import CacheContent from "./CacheContent";
9
9
  import Column, { FIX_LABEL } from "./Column";
10
10
  import useActive from "./useActive";
11
11
  import useKeyboard from "./useKeyboard";
@@ -18,7 +18,8 @@ const RawOptionList = /*#__PURE__*/React.forwardRef((props, ref) => {
18
18
  notFoundContent,
19
19
  direction,
20
20
  open,
21
- disabled
21
+ disabled,
22
+ lockOptions = false
22
23
  } = props;
23
24
  const containerRef = React.useRef(null);
24
25
  const rtl = direction === 'rtl';
@@ -103,13 +104,16 @@ const RawOptionList = /*#__PURE__*/React.forwardRef((props, ref) => {
103
104
  };
104
105
 
105
106
  // ========================== Option ==========================
106
- const mergedOptions = React.useMemo(() => {
107
+ const filteredOptions = React.useMemo(() => {
107
108
  if (searchValue) {
108
109
  return searchOptions;
109
110
  }
110
111
  return options;
111
112
  }, [searchValue, searchOptions, options]);
112
113
 
114
+ // Update only when open or lockOptions
115
+ const mergedOptions = useMemo(() => filteredOptions, [open, lockOptions], (prev, next) => !!next[0] && !next[1]);
116
+
113
117
  // ========================== Column ==========================
114
118
  const optionColumns = React.useMemo(() => {
115
119
  const optionList = [{
@@ -199,15 +203,13 @@ const RawOptionList = /*#__PURE__*/React.forwardRef((props, ref) => {
199
203
  });
200
204
 
201
205
  // >>>>> Render
202
- return /*#__PURE__*/React.createElement(CacheContent, {
203
- open: open
204
- }, /*#__PURE__*/React.createElement("div", {
206
+ return /*#__PURE__*/React.createElement("div", {
205
207
  className: clsx(`${mergedPrefixCls}-menus`, {
206
208
  [`${mergedPrefixCls}-menu-empty`]: isEmpty,
207
209
  [`${mergedPrefixCls}-rtl`]: rtl
208
210
  }),
209
211
  ref: containerRef
210
- }, columnNodes));
212
+ }, columnNodes);
211
213
  });
212
214
  if (process.env.NODE_ENV !== 'production') {
213
215
  RawOptionList.displayName = 'RawOptionList';
@@ -3,10 +3,14 @@ import { useBaseProps } from '@rc-component/select';
3
3
  import * as React from 'react';
4
4
  import RawOptionList from "./List";
5
5
  const RefOptionList = /*#__PURE__*/React.forwardRef((props, ref) => {
6
- const baseProps = useBaseProps();
6
+ const {
7
+ lockOptions,
8
+ ...baseProps
9
+ } = useBaseProps();
7
10
 
8
11
  // >>>>> Render
9
12
  return /*#__PURE__*/React.createElement(RawOptionList, _extends({}, props, baseProps, {
13
+ lockOptions: lockOptions,
10
14
  ref: ref
11
15
  }));
12
16
  });
@@ -200,7 +200,7 @@ function Column({
200
200
  }
201
201
  }), /*#__PURE__*/React.createElement("div", {
202
202
  className: `${menuItemPrefixCls}-content`
203
- }, optionRender ? optionRender(option) : label), !isLoading && expandIcon && !isMergedLeaf && /*#__PURE__*/React.createElement("div", {
203
+ }, optionRender && value !== '__EMPTY__' ? optionRender(option) : label), !isLoading && expandIcon && !isMergedLeaf && /*#__PURE__*/React.createElement("div", {
204
204
  className: `${menuItemPrefixCls}-expand-icon`
205
205
  }, expandIcon), isLoading && loadingIcon && /*#__PURE__*/React.createElement("div", {
206
206
  className: `${menuItemPrefixCls}-loading-icon`
@@ -1,6 +1,10 @@
1
1
  import type { useBaseProps } from '@rc-component/select';
2
2
  import type { RefOptionListProps } from '@rc-component/select/lib/OptionList';
3
3
  import * as React from 'react';
4
- export type RawOptionListProps = Pick<ReturnType<typeof useBaseProps>, 'prefixCls' | 'multiple' | 'searchValue' | 'toggleOpen' | 'notFoundContent' | 'direction' | 'open' | 'disabled'>;
5
- declare const RawOptionList: React.ForwardRefExoticComponent<RawOptionListProps & React.RefAttributes<RefOptionListProps>>;
4
+ export type RawOptionListProps = Pick<ReturnType<typeof useBaseProps>, 'prefixCls' | 'multiple' | 'searchValue' | 'toggleOpen' | 'notFoundContent' | 'direction' | 'open' | 'disabled'> & {
5
+ lockOptions?: boolean;
6
+ };
7
+ declare const RawOptionList: React.ForwardRefExoticComponent<Pick<import("@rc-component/select/lib/hooks/useBaseProps").BaseSelectContextProps, "disabled" | "prefixCls" | "multiple" | "searchValue" | "direction" | "notFoundContent" | "open" | "toggleOpen"> & {
8
+ lockOptions?: boolean | undefined;
9
+ } & React.RefAttributes<RefOptionListProps>>;
6
10
  export default RawOptionList;
@@ -6,10 +6,10 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.default = void 0;
7
7
  var _clsx = require("clsx");
8
8
  var React = _interopRequireWildcard(require("react"));
9
+ var _useMemo = _interopRequireDefault(require("@rc-component/util/lib/hooks/useMemo"));
9
10
  var _context = _interopRequireDefault(require("../context"));
10
11
  var _commonUtil = require("../utils/commonUtil");
11
12
  var _treeUtil = require("../utils/treeUtil");
12
- var _CacheContent = _interopRequireDefault(require("./CacheContent"));
13
13
  var _Column = _interopRequireWildcard(require("./Column"));
14
14
  var _useActive = _interopRequireDefault(require("./useActive"));
15
15
  var _useKeyboard = _interopRequireDefault(require("./useKeyboard"));
@@ -26,7 +26,8 @@ const RawOptionList = /*#__PURE__*/React.forwardRef((props, ref) => {
26
26
  notFoundContent,
27
27
  direction,
28
28
  open,
29
- disabled
29
+ disabled,
30
+ lockOptions = false
30
31
  } = props;
31
32
  const containerRef = React.useRef(null);
32
33
  const rtl = direction === 'rtl';
@@ -111,13 +112,16 @@ const RawOptionList = /*#__PURE__*/React.forwardRef((props, ref) => {
111
112
  };
112
113
 
113
114
  // ========================== Option ==========================
114
- const mergedOptions = React.useMemo(() => {
115
+ const filteredOptions = React.useMemo(() => {
115
116
  if (searchValue) {
116
117
  return searchOptions;
117
118
  }
118
119
  return options;
119
120
  }, [searchValue, searchOptions, options]);
120
121
 
122
+ // Update only when open or lockOptions
123
+ const mergedOptions = (0, _useMemo.default)(() => filteredOptions, [open, lockOptions], (prev, next) => !!next[0] && !next[1]);
124
+
121
125
  // ========================== Column ==========================
122
126
  const optionColumns = React.useMemo(() => {
123
127
  const optionList = [{
@@ -207,15 +211,13 @@ const RawOptionList = /*#__PURE__*/React.forwardRef((props, ref) => {
207
211
  });
208
212
 
209
213
  // >>>>> Render
210
- return /*#__PURE__*/React.createElement(_CacheContent.default, {
211
- open: open
212
- }, /*#__PURE__*/React.createElement("div", {
214
+ return /*#__PURE__*/React.createElement("div", {
213
215
  className: (0, _clsx.clsx)(`${mergedPrefixCls}-menus`, {
214
216
  [`${mergedPrefixCls}-menu-empty`]: isEmpty,
215
217
  [`${mergedPrefixCls}-rtl`]: rtl
216
218
  }),
217
219
  ref: containerRef
218
- }, columnNodes));
220
+ }, columnNodes);
219
221
  });
220
222
  if (process.env.NODE_ENV !== 'production') {
221
223
  RawOptionList.displayName = 'RawOptionList';
@@ -12,10 +12,14 @@ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return
12
12
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
13
13
  function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
14
14
  const RefOptionList = /*#__PURE__*/React.forwardRef((props, ref) => {
15
- const baseProps = (0, _select.useBaseProps)();
15
+ const {
16
+ lockOptions,
17
+ ...baseProps
18
+ } = (0, _select.useBaseProps)();
16
19
 
17
20
  // >>>>> Render
18
21
  return /*#__PURE__*/React.createElement(_List.default, _extends({}, props, baseProps, {
22
+ lockOptions: lockOptions,
19
23
  ref: ref
20
24
  }));
21
25
  });
@@ -2,7 +2,7 @@ import type { RefOptionListProps } from '@rc-component/select/lib/OptionList';
2
2
  import * as React from 'react';
3
3
  import type { DefaultOptionType, InternalFieldNames, LegacyKey, SingleValueType } from '../Cascader';
4
4
  declare const _default: (ref: React.Ref<RefOptionListProps>, options: DefaultOptionType[], fieldNames: InternalFieldNames, activeValueCells: LegacyKey[], setActiveValueCells: (activeValueCells: LegacyKey[]) => void, onKeyBoardSelect: (valueCells: SingleValueType, option: DefaultOptionType) => void, contextProps: {
5
- direction?: "rtl" | "ltr" | undefined;
5
+ direction?: "ltr" | "rtl" | undefined;
6
6
  searchValue: string;
7
7
  toggleOpen: (open?: boolean) => void;
8
8
  open?: boolean | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rc-component/cascader",
3
- "version": "1.12.0",
3
+ "version": "1.13.0",
4
4
  "description": "cascade select ui component for react",
5
5
  "keywords": [
6
6
  "react",
@@ -43,7 +43,7 @@
43
43
  "test": "rc-test"
44
44
  },
45
45
  "dependencies": {
46
- "@rc-component/select": "~1.5.0",
46
+ "@rc-component/select": "~1.5.2",
47
47
  "@rc-component/tree": "~1.2.0",
48
48
  "@rc-component/util": "^1.4.0",
49
49
  "clsx": "^2.1.1"
@@ -1,7 +0,0 @@
1
- import * as React from 'react';
2
- export interface CacheContentProps {
3
- children?: React.ReactNode;
4
- open?: boolean;
5
- }
6
- declare const CacheContent: React.MemoExoticComponent<({ children }: CacheContentProps) => React.ReactElement<unknown, string | React.JSXElementConstructor<any>>>;
7
- export default CacheContent;
@@ -1,8 +0,0 @@
1
- import * as React from 'react';
2
- const CacheContent = /*#__PURE__*/React.memo(({
3
- children
4
- }) => children, (_, next) => !next.open);
5
- if (process.env.NODE_ENV !== 'production') {
6
- CacheContent.displayName = 'CacheContent';
7
- }
8
- export default CacheContent;
@@ -1,7 +0,0 @@
1
- import * as React from 'react';
2
- export interface CacheContentProps {
3
- children?: React.ReactNode;
4
- open?: boolean;
5
- }
6
- declare const CacheContent: React.MemoExoticComponent<({ children }: CacheContentProps) => React.ReactElement<unknown, string | React.JSXElementConstructor<any>>>;
7
- export default CacheContent;
@@ -1,16 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- var React = _interopRequireWildcard(require("react"));
8
- function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
9
- function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
10
- const CacheContent = /*#__PURE__*/React.memo(({
11
- children
12
- }) => children, (_, next) => !next.open);
13
- if (process.env.NODE_ENV !== 'production') {
14
- CacheContent.displayName = 'CacheContent';
15
- }
16
- var _default = exports.default = CacheContent;