@kaiheila/ui-components 1.0.1 → 1.0.2

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.
@@ -2205,7 +2205,8 @@ const OptionList = _ref => {
2205
2205
  labelKey = "label",
2206
2206
  valueKey = "value",
2207
2207
  loadComponent,
2208
- onSelect
2208
+ onSelect,
2209
+ onReachBottom
2209
2210
  } = _ref;
2210
2211
  const containerRef = (0,external_react_namespaceObject.useRef)(null);
2211
2212
  const ids = (0,external_react_namespaceObject.useMemo)(() => filterData.map(item => item[valueKey]), [filterData, valueKey]);
@@ -2213,9 +2214,16 @@ const OptionList = _ref => {
2213
2214
  visibleRange
2214
2215
  } = (0,logic_models_react_namespaceObject.useListVirtualScroll)({
2215
2216
  ids,
2216
- heightRender: 34 // 注意:这里需要手动维护跟样式上的高度一致,如果不能维护一致的话就需要写动态高度逻辑
2217
+ heightRender: id => {
2218
+ if ((0,logic_models_react_namespaceObject.isSentinelId)(id)) {
2219
+ // 所有元素必须有高度,否则滚动位置无法计算到该元素
2220
+ return 1;
2221
+ }
2222
+ return 34;
2223
+ } // 注意:这里需要手动维护跟样式上的高度一致,如果不能维护一致的话就需要写动态高度逻辑
2217
2224
  }, {
2218
- containerRef
2225
+ containerRef,
2226
+ onReachBottom
2219
2227
  });
2220
2228
  return /*#__PURE__*/external_react_default().createElement("ul", {
2221
2229
  className: "selector-search-option theme-scroll-bar",
@@ -2235,6 +2243,9 @@ const OptionList = _ref => {
2235
2243
  transform: "translateY(".concat(visibleRange === null || visibleRange === void 0 ? void 0 : visibleRange.topSpace, "px)")
2236
2244
  }
2237
2245
  }, (visibleRange === null || visibleRange === void 0 || (_visibleRange$visible = visibleRange.visibleIds) === null || _visibleRange$visible === void 0 ? void 0 : _visibleRange$visible.length) > 0 ? visibleRange === null || visibleRange === void 0 ? void 0 : visibleRange.visibleIds.map((id, i) => {
2246
+ if ((0,logic_models_react_namespaceObject.isSentinelId)(id)) {
2247
+ return null;
2248
+ }
2238
2249
  const item = filterData.find(item => item[valueKey] === id);
2239
2250
  const label = item === null || item === void 0 ? void 0 : item[labelKey];
2240
2251
  const value = item === null || item === void 0 ? void 0 : item[valueKey];
@@ -2279,7 +2290,9 @@ function selector_search_toPrimitive(t, r) { if ("object" != typeof t || !t) ret
2279
2290
 
2280
2291
  class SelectorSearch extends external_react_namespaceObject.Component {
2281
2292
  constructor(props) {
2293
+ var _this;
2282
2294
  super(props);
2295
+ _this = this;
2283
2296
  selector_search_defineProperty(this, "calcOptionsStyle", () => {
2284
2297
  const {
2285
2298
  current
@@ -2302,7 +2315,7 @@ class SelectorSearch extends external_react_namespaceObject.Component {
2302
2315
  showList: false,
2303
2316
  keyword: ''
2304
2317
  }, () => {
2305
- this.changeFilterData();
2318
+ this.changeFilterData(true);
2306
2319
  });
2307
2320
  document.removeEventListener('click', this.hide);
2308
2321
  });
@@ -2328,7 +2341,7 @@ class SelectorSearch extends external_react_namespaceObject.Component {
2328
2341
  this.setState({
2329
2342
  keyword: ''
2330
2343
  }, () => {
2331
- this.changeFilterData();
2344
+ this.changeFilterData(true);
2332
2345
  });
2333
2346
  document.removeEventListener('click', this.hide);
2334
2347
  }
@@ -2345,10 +2358,10 @@ class SelectorSearch extends external_react_namespaceObject.Component {
2345
2358
  event.nativeEvent.stopImmediatePropagation();
2346
2359
  return;
2347
2360
  }
2348
- this.hide();
2349
2361
  this.setState({
2350
- keyword: ''
2362
+ currentItem: this.props.data.find(item => item[this.props.valueKey] == value)
2351
2363
  });
2364
+ this.hide();
2352
2365
  const {
2353
2366
  onChange
2354
2367
  } = this.props;
@@ -2361,6 +2374,12 @@ class SelectorSearch extends external_react_namespaceObject.Component {
2361
2374
  data = [],
2362
2375
  value
2363
2376
  } = this.props;
2377
+ const {
2378
+ currentItem
2379
+ } = this.state;
2380
+ if (currentItem && currentItem[valueKey] == value) {
2381
+ return currentItem[labelKey] || '';
2382
+ }
2364
2383
  return (data.find(item => {
2365
2384
  if (item[valueKey] === value) {
2366
2385
  return item;
@@ -2371,16 +2390,24 @@ class SelectorSearch extends external_react_namespaceObject.Component {
2371
2390
  this.setState({
2372
2391
  keyword: value
2373
2392
  }, () => {
2374
- this.changeFilterData();
2393
+ this.changeFilterData(true);
2375
2394
  });
2376
2395
  });
2377
- selector_search_defineProperty(this, "changeFilterData", () => {
2378
- const keyword = this.state.keyword.trim().toLocaleLowerCase();
2396
+ selector_search_defineProperty(this, "changeFilterData", function () {
2397
+ let updateFilterData = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
2398
+ const keyword = _this.state.keyword.trim().toLocaleLowerCase();
2399
+
2400
+ // 受控模式下,组件渲染后的状态变更由受控逻辑接管,直接调用 keywordChange 回调
2401
+ if (_this.props.controlled && updateFilterData) {
2402
+ var _this$props$keywordCh, _this$props;
2403
+ (_this$props$keywordCh = (_this$props = _this.props).keywordChange) === null || _this$props$keywordCh === void 0 || _this$props$keywordCh.call(_this$props, keyword);
2404
+ return;
2405
+ }
2379
2406
  let filterData = [];
2380
2407
  const {
2381
2408
  getData,
2382
2409
  onSearchResultChange
2383
- } = this.props;
2410
+ } = _this.props;
2384
2411
  if (typeof getData == 'function') {
2385
2412
  getData({
2386
2413
  keyword
@@ -2388,21 +2415,21 @@ class SelectorSearch extends external_react_namespaceObject.Component {
2388
2415
  let {
2389
2416
  list
2390
2417
  } = _ref;
2391
- this.setState({
2418
+ _this.setState({
2392
2419
  filterData: list
2393
2420
  });
2394
2421
  });
2395
2422
  return;
2396
2423
  }
2397
2424
  if (keyword == '') {
2398
- filterData = this.props.data || [];
2425
+ filterData = _this.props.data || [];
2399
2426
  } else {
2400
- filterData = (this.props.data || []).filter(item => {
2401
- let label = item[this.props.labelKey || 'label'];
2427
+ filterData = (_this.props.data || []).filter(item => {
2428
+ let label = item[_this.props.labelKey || 'label'];
2402
2429
  return label.toLocaleLowerCase().includes(keyword);
2403
2430
  });
2404
2431
  }
2405
- this.setState({
2432
+ _this.setState({
2406
2433
  filterData
2407
2434
  });
2408
2435
 
@@ -2437,7 +2464,8 @@ class SelectorSearch extends external_react_namespaceObject.Component {
2437
2464
  showList: false,
2438
2465
  keyword: '',
2439
2466
  filterData: [],
2440
- optionsStyle: {}
2467
+ optionsStyle: {},
2468
+ currentItem: null
2441
2469
  };
2442
2470
  this.selectRef = /*#__PURE__*/external_react_default().createRef();
2443
2471
  }
@@ -2474,6 +2502,7 @@ class SelectorSearch extends external_react_namespaceObject.Component {
2474
2502
  placeholder,
2475
2503
  renderOption,
2476
2504
  disabledValues = [],
2505
+ onReachBottom,
2477
2506
  labelKey = 'label',
2478
2507
  valueKey = 'value',
2479
2508
  loadComponent
@@ -2515,7 +2544,8 @@ class SelectorSearch extends external_react_namespaceObject.Component {
2515
2544
  labelKey: labelKey,
2516
2545
  valueKey: valueKey,
2517
2546
  loadComponent: loadComponent,
2518
- onSelect: this.select
2547
+ onSelect: this.select,
2548
+ onReachBottom: onReachBottom
2519
2549
  }) : null);
2520
2550
  }
2521
2551
  }
@@ -2531,7 +2561,10 @@ selector_search_defineProperty(SelectorSearch, "propTypes", {
2531
2561
  onSearchResultChange: (external_prop_types_default()).func,
2532
2562
  // 搜索结果change
2533
2563
  onBlur: (external_prop_types_default()).func,
2534
- onFocus: (external_prop_types_default()).func
2564
+ onFocus: (external_prop_types_default()).func,
2565
+ controlled: (external_prop_types_default()).bool,
2566
+ keywordChange: (external_prop_types_default()).func
2567
+ // loading: PropTypes.bool, // 如果是loading 则在filter面板显示 转圈
2535
2568
  });
2536
2569
  ;// ./src/components/selector-search/index.js
2537
2570
 
@@ -5615,7 +5648,7 @@ class TimeSelector extends external_react_namespaceObject.Component {
5615
5648
 
5616
5649
  /* harmony default export */ const time_selector = (TimeSelector);
5617
5650
  ;// ./package.json
5618
- const package_namespaceObject = {"rE":"1.0.1"};
5651
+ const package_namespaceObject = {"rE":"1.0.2"};
5619
5652
  ;// ./src/index.js
5620
5653
 
5621
5654
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kaiheila/ui-components",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "开黑啦 UI Components",
5
5
  "main": "dist/ui-components.js",
6
6
  "scripts": {
@@ -20,7 +20,7 @@
20
20
  "@babel/core": "^7.15.5",
21
21
  "@babel/preset-env": "^7.15.6",
22
22
  "@babel/preset-react": "^7.14.5",
23
- "@kookapp/logic-models-react": "^1.0.1",
23
+ "@kookapp/logic-models-react": "1.0.7",
24
24
  "babel-loader": "^8.2.2",
25
25
  "classnames": "^2.3.1",
26
26
  "css-loader": "^6.7.1",
@@ -38,7 +38,7 @@
38
38
  "webpack-dev-server": "^4.11.1"
39
39
  },
40
40
  "peerDependencies": {
41
- "@kookapp/logic-models-react": "^1.0.1",
41
+ "@kookapp/logic-models-react": "^1.0.7",
42
42
  "react": "^18",
43
43
  "react-dom": "^18"
44
44
  },