@douyinfe/semi-ui 2.50.0-alpha.1 → 2.50.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.
Files changed (43) hide show
  1. package/dist/css/semi.css +3 -0
  2. package/dist/css/semi.min.css +1 -1
  3. package/dist/umd/semi-ui.js +523 -416
  4. package/dist/umd/semi-ui.js.map +1 -1
  5. package/dist/umd/semi-ui.min.js +1 -1
  6. package/dist/umd/semi-ui.min.js.map +1 -1
  7. package/lib/cjs/datePicker/yearAndMonth.js +1 -5
  8. package/lib/cjs/form/baseForm.d.ts +1 -1
  9. package/lib/cjs/form/field.d.ts +1 -1
  10. package/lib/cjs/image/interface.d.ts +3 -3
  11. package/lib/cjs/image/previewFooter.js +5 -8
  12. package/lib/cjs/image/previewHeader.d.ts +2 -2
  13. package/lib/cjs/image/previewHeader.js +9 -8
  14. package/lib/cjs/image/previewImage.d.ts +1 -12
  15. package/lib/cjs/image/previewImage.js +23 -83
  16. package/lib/cjs/image/previewInner.d.ts +12 -3
  17. package/lib/cjs/image/previewInner.js +65 -44
  18. package/lib/cjs/index.d.ts +2 -0
  19. package/lib/cjs/index.js +14 -0
  20. package/lib/cjs/notification/index.js +6 -5
  21. package/lib/cjs/select/index.d.ts +1 -1
  22. package/lib/cjs/timePicker/TimePicker.d.ts +1 -1
  23. package/lib/cjs/treeSelect/index.d.ts +2 -2
  24. package/lib/cjs/treeSelect/index.js +117 -29
  25. package/lib/es/datePicker/yearAndMonth.js +1 -5
  26. package/lib/es/form/baseForm.d.ts +1 -1
  27. package/lib/es/form/field.d.ts +1 -1
  28. package/lib/es/image/interface.d.ts +3 -3
  29. package/lib/es/image/previewFooter.js +5 -8
  30. package/lib/es/image/previewHeader.d.ts +2 -2
  31. package/lib/es/image/previewHeader.js +4 -3
  32. package/lib/es/image/previewImage.d.ts +1 -12
  33. package/lib/es/image/previewImage.js +23 -83
  34. package/lib/es/image/previewInner.d.ts +12 -3
  35. package/lib/es/image/previewInner.js +65 -44
  36. package/lib/es/index.d.ts +2 -0
  37. package/lib/es/index.js +2 -0
  38. package/lib/es/notification/index.js +6 -5
  39. package/lib/es/select/index.d.ts +1 -1
  40. package/lib/es/timePicker/TimePicker.d.ts +1 -1
  41. package/lib/es/treeSelect/index.d.ts +2 -2
  42. package/lib/es/treeSelect/index.js +118 -30
  43. package/package.json +8 -8
@@ -17286,6 +17286,8 @@ __webpack_require__.d(__webpack_exports__, {
17286
17286
  "BackTop": () => (/* reexport */ BackTop),
17287
17287
  "Badge": () => (/* reexport */ Badge),
17288
17288
  "Banner": () => (/* reexport */ Banner),
17289
+ "BaseComponent": () => (/* reexport */ BaseComponent),
17290
+ "BaseFoundation": () => (/* reexport */ foundation),
17289
17291
  "Breadcrumb": () => (/* reexport */ breadcrumb_0),
17290
17292
  "Button": () => (/* reexport */ button_0),
17291
17293
  "ButtonGroup": () => (/* reexport */ ButtonGroup),
@@ -17375,45 +17377,12 @@ __webpack_require__.d(__webpack_exports__, {
17375
17377
 
17376
17378
  // EXTERNAL MODULE: ./_base/base.scss
17377
17379
  var base = __webpack_require__("q7sR");
17378
- // EXTERNAL MODULE: ../../node_modules/lodash/throttle.js
17379
- var throttle = __webpack_require__("Bcqe");
17380
- var throttle_default = /*#__PURE__*/__webpack_require__.n(throttle);
17381
- // EXTERNAL MODULE: ../../node_modules/lodash/debounce.js
17382
- var debounce = __webpack_require__("RNvQ");
17383
- var debounce_default = /*#__PURE__*/__webpack_require__.n(debounce);
17384
17380
  // EXTERNAL MODULE: ../../node_modules/lodash/noop.js
17385
17381
  var noop = __webpack_require__("nnm9");
17386
17382
  var noop_default = /*#__PURE__*/__webpack_require__.n(noop);
17387
- // EXTERNAL MODULE: external {"root":"React","commonjs2":"react","commonjs":"react","amd":"react"}
17388
- var external_root_React_commonjs2_react_commonjs_react_amd_react_ = __webpack_require__("neV8");
17389
- var external_root_React_commonjs2_react_commonjs_react_amd_react_default = /*#__PURE__*/__webpack_require__.n(external_root_React_commonjs2_react_commonjs_react_amd_react_);
17390
- // EXTERNAL MODULE: ../../node_modules/classnames/index.js
17391
- var classnames = __webpack_require__("O94r");
17392
- var classnames_default = /*#__PURE__*/__webpack_require__.n(classnames);
17393
- // EXTERNAL MODULE: ../../node_modules/prop-types/index.js
17394
- var prop_types = __webpack_require__("aWzz");
17395
- var prop_types_default = /*#__PURE__*/__webpack_require__.n(prop_types);
17396
- ;// CONCATENATED MODULE: ../semi-foundation/base/env.ts
17397
- const BASE_CLASS_PREFIX = 'semi';
17398
- ;// CONCATENATED MODULE: ../semi-foundation/anchor/constants.ts
17399
-
17400
- const cssClasses = {
17401
- PREFIX: `${BASE_CLASS_PREFIX}-anchor`
17402
- };
17403
- const constants_strings = {
17404
- SIZE: ['small', 'default'],
17405
- SLIDE_COLOR: ['primary', 'tertiary', 'muted'],
17406
- MAX_WIDTH: '200px',
17407
- MAX_HEIGHT: '750px',
17408
- POSITION_SET: ['top', 'topLeft', 'topRight', 'left', 'leftTop', 'leftBottom', 'right', 'rightTop', 'rightBottom', 'bottom', 'bottomLeft', 'bottomRight', 'leftTopOver', 'rightTopOver']
17409
- };
17410
-
17411
17383
  // EXTERNAL MODULE: ../../node_modules/lodash/get.js
17412
17384
  var get = __webpack_require__("2srY");
17413
17385
  var get_default = /*#__PURE__*/__webpack_require__.n(get);
17414
- // EXTERNAL MODULE: ../../node_modules/lodash/isArray.js
17415
- var isArray = __webpack_require__("wxYD");
17416
- var isArray_default = /*#__PURE__*/__webpack_require__.n(isArray);
17417
17386
  ;// CONCATENATED MODULE: ../semi-foundation/utils/log.ts
17418
17387
 
17419
17388
  const log = function (text) {
@@ -17540,6 +17509,115 @@ class BaseFoundation {
17540
17509
  }
17541
17510
  }
17542
17511
  /* harmony default export */ const foundation = (BaseFoundation);
17512
+ // EXTERNAL MODULE: external {"root":"React","commonjs2":"react","commonjs":"react","amd":"react"}
17513
+ var external_root_React_commonjs2_react_commonjs_react_amd_react_ = __webpack_require__("neV8");
17514
+ var external_root_React_commonjs2_react_commonjs_react_amd_react_default = /*#__PURE__*/__webpack_require__.n(external_root_React_commonjs2_react_commonjs_react_amd_react_);
17515
+ ;// CONCATENATED MODULE: ../semi-foundation/utils/getDataAttr.ts
17516
+ function getDataAttr(props) {
17517
+ return Object.keys(props).reduce((prev, key) => {
17518
+ if (key.substr(0, 5) === 'data-') {
17519
+ prev[key] = props[key];
17520
+ }
17521
+ return prev;
17522
+ }, {});
17523
+ }
17524
+ ;// CONCATENATED MODULE: ./_base/baseComponent.tsx
17525
+ /**
17526
+ * The Semi Foundation / Adapter architecture split was inspired by Material Component For Web. (https://github.com/material-components/material-components-web)
17527
+ * We re-implemented our own code based on the principle and added more functions we need according to actual needs.
17528
+ */
17529
+
17530
+
17531
+
17532
+ const {
17533
+ hasOwnProperty: baseComponent_hasOwnProperty
17534
+ } = Object.prototype;
17535
+ // eslint-disable-next-line
17536
+ class BaseComponent extends external_root_React_commonjs2_react_commonjs_react_amd_react_.Component {
17537
+ constructor(props) {
17538
+ super(props);
17539
+ // eslint-disable-next-line
17540
+ this.isControlled = key => Boolean(key && this.props && typeof this.props === 'object' && baseComponent_hasOwnProperty.call(this.props, key));
17541
+ this.cache = {};
17542
+ this.foundation = null;
17543
+ }
17544
+ componentDidMount() {
17545
+ this.foundation && typeof this.foundation.init === 'function' && this.foundation.init();
17546
+ }
17547
+ componentWillUnmount() {
17548
+ this.foundation && typeof this.foundation.destroy === 'function' && this.foundation.destroy();
17549
+ this.cache = {};
17550
+ }
17551
+ get adapter() {
17552
+ return {
17553
+ getContext: key => {
17554
+ if (this.context && key) {
17555
+ return this.context[key];
17556
+ }
17557
+ },
17558
+ getContexts: () => this.context,
17559
+ getProp: key => this.props[key],
17560
+ // return all props
17561
+ getProps: () => this.props,
17562
+ getState: key => this.state[key],
17563
+ getStates: () => this.state,
17564
+ setState: (states, cb) => this.setState(Object.assign({}, states), cb),
17565
+ getCache: key => key && this.cache[key],
17566
+ getCaches: () => this.cache,
17567
+ setCache: (key, value) => key && (this.cache[key] = value),
17568
+ stopPropagation: e => {
17569
+ try {
17570
+ e.stopPropagation();
17571
+ e.nativeEvent && e.nativeEvent.stopImmediatePropagation();
17572
+ } catch (error) {}
17573
+ },
17574
+ persistEvent: e => {
17575
+ e && e.persist && typeof e.persist === 'function' ? e.persist() : null;
17576
+ }
17577
+ };
17578
+ }
17579
+ log(text) {
17580
+ for (var _len = arguments.length, rest = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
17581
+ rest[_key - 1] = arguments[_key];
17582
+ }
17583
+ return utils_log(text, ...rest);
17584
+ }
17585
+ getDataAttr(props) {
17586
+ return getDataAttr(props);
17587
+ }
17588
+ }
17589
+ BaseComponent.propTypes = {};
17590
+ BaseComponent.defaultProps = {};
17591
+ // EXTERNAL MODULE: ../../node_modules/lodash/throttle.js
17592
+ var throttle = __webpack_require__("Bcqe");
17593
+ var throttle_default = /*#__PURE__*/__webpack_require__.n(throttle);
17594
+ // EXTERNAL MODULE: ../../node_modules/lodash/debounce.js
17595
+ var debounce = __webpack_require__("RNvQ");
17596
+ var debounce_default = /*#__PURE__*/__webpack_require__.n(debounce);
17597
+ // EXTERNAL MODULE: ../../node_modules/classnames/index.js
17598
+ var classnames = __webpack_require__("O94r");
17599
+ var classnames_default = /*#__PURE__*/__webpack_require__.n(classnames);
17600
+ // EXTERNAL MODULE: ../../node_modules/prop-types/index.js
17601
+ var prop_types = __webpack_require__("aWzz");
17602
+ var prop_types_default = /*#__PURE__*/__webpack_require__.n(prop_types);
17603
+ ;// CONCATENATED MODULE: ../semi-foundation/base/env.ts
17604
+ const BASE_CLASS_PREFIX = 'semi';
17605
+ ;// CONCATENATED MODULE: ../semi-foundation/anchor/constants.ts
17606
+
17607
+ const cssClasses = {
17608
+ PREFIX: `${BASE_CLASS_PREFIX}-anchor`
17609
+ };
17610
+ const constants_strings = {
17611
+ SIZE: ['small', 'default'],
17612
+ SLIDE_COLOR: ['primary', 'tertiary', 'muted'],
17613
+ MAX_WIDTH: '200px',
17614
+ MAX_HEIGHT: '750px',
17615
+ POSITION_SET: ['top', 'topLeft', 'topRight', 'left', 'leftTop', 'leftBottom', 'right', 'rightTop', 'rightBottom', 'bottom', 'bottomLeft', 'bottomRight', 'leftTopOver', 'rightTopOver']
17616
+ };
17617
+
17618
+ // EXTERNAL MODULE: ../../node_modules/lodash/isArray.js
17619
+ var isArray = __webpack_require__("wxYD");
17620
+ var isArray_default = /*#__PURE__*/__webpack_require__.n(isArray);
17543
17621
  ;// CONCATENATED MODULE: ../../node_modules/compute-scroll-into-view/dist/index.mjs
17544
17622
  function t(t){return"object"==typeof t&&null!=t&&1===t.nodeType}function e(t,e){return(!e||"hidden"!==t)&&"visible"!==t&&"clip"!==t}function n(t,n){if(t.clientHeight<t.scrollHeight||t.clientWidth<t.scrollWidth){var r=getComputedStyle(t,null);return e(r.overflowY,n)||e(r.overflowX,n)||function(t){var e=function(t){if(!t.ownerDocument||!t.ownerDocument.defaultView)return null;try{return t.ownerDocument.defaultView.frameElement}catch(t){return null}}(t);return!!e&&(e.clientHeight<t.scrollHeight||e.clientWidth<t.scrollWidth)}(t)}return!1}function r(t,e,n,r,i,o,l,d){return o<t&&l>e||o>t&&l<e?0:o<=t&&d<=n||l>=e&&d>=n?o-t-r:l>e&&d<n||o<t&&d>n?l-e+i:0}var i=function(e,i){var o=window,l=i.scrollMode,d=i.block,f=i.inline,h=i.boundary,u=i.skipOverflowHiddenElements,s="function"==typeof h?h:function(t){return t!==h};if(!t(e))throw new TypeError("Invalid target");for(var a,c,g=document.scrollingElement||document.documentElement,p=[],m=e;t(m)&&s(m);){if((m=null==(c=(a=m).parentElement)?a.getRootNode().host||null:c)===g){p.push(m);break}null!=m&&m===document.body&&n(m)&&!n(document.documentElement)||null!=m&&n(m,u)&&p.push(m)}for(var w=o.visualViewport?o.visualViewport.width:innerWidth,v=o.visualViewport?o.visualViewport.height:innerHeight,W=window.scrollX||pageXOffset,H=window.scrollY||pageYOffset,b=e.getBoundingClientRect(),y=b.height,E=b.width,M=b.top,V=b.right,x=b.bottom,I=b.left,C="start"===d||"nearest"===d?M:"end"===d?x:M+y/2,R="center"===f?I+E/2:"end"===f?V:I,T=[],k=0;k<p.length;k++){var B=p[k],D=B.getBoundingClientRect(),O=D.height,X=D.width,Y=D.top,L=D.right,S=D.bottom,j=D.left;if("if-needed"===l&&M>=0&&I>=0&&x<=v&&V<=w&&M>=Y&&x<=S&&I>=j&&V<=L)return T;var N=getComputedStyle(B),q=parseInt(N.borderLeftWidth,10),z=parseInt(N.borderTopWidth,10),A=parseInt(N.borderRightWidth,10),F=parseInt(N.borderBottomWidth,10),G=0,J=0,K="offsetWidth"in B?B.offsetWidth-B.clientWidth-q-A:0,P="offsetHeight"in B?B.offsetHeight-B.clientHeight-z-F:0,Q="offsetWidth"in B?0===B.offsetWidth?0:X/B.offsetWidth:0,U="offsetHeight"in B?0===B.offsetHeight?0:O/B.offsetHeight:0;if(g===B)G="start"===d?C:"end"===d?C-v:"nearest"===d?r(H,H+v,v,z,F,H+C,H+C+y,y):C-v/2,J="start"===f?R:"center"===f?R-w/2:"end"===f?R-w:r(W,W+w,w,q,A,W+R,W+R+E,E),G=Math.max(0,G+H),J=Math.max(0,J+W);else{G="start"===d?C-Y-z:"end"===d?C-S+F+P:"nearest"===d?r(Y,S,O,z,F+P,C,C+y,y):C-(Y+O/2)+P/2,J="start"===f?R-j-q:"center"===f?R-(j+X/2)+K/2:"end"===f?R-L+A+K:r(j,L,X,q,A+K,R,R+E,E);var Z=B.scrollLeft,$=B.scrollTop;C+=$-(G=Math.max(0,Math.min($+G/U,B.scrollHeight-O/U+P))),R+=Z-(J=Math.max(0,Math.min(Z+J/Q,B.scrollWidth-X/Q+K)))}T.push({el:B,top:G,left:J})}return T};
17545
17623
  //# sourceMappingURL=index.mjs.map
@@ -17793,82 +17871,6 @@ class AnchorFoundation extends foundation {
17793
17871
  };
17794
17872
  }
17795
17873
  }
17796
- ;// CONCATENATED MODULE: ../semi-foundation/utils/getDataAttr.ts
17797
- function getDataAttr(props) {
17798
- return Object.keys(props).reduce((prev, key) => {
17799
- if (key.substr(0, 5) === 'data-') {
17800
- prev[key] = props[key];
17801
- }
17802
- return prev;
17803
- }, {});
17804
- }
17805
- ;// CONCATENATED MODULE: ./_base/baseComponent.tsx
17806
- /**
17807
- * The Semi Foundation / Adapter architecture split was inspired by Material Component For Web. (https://github.com/material-components/material-components-web)
17808
- * We re-implemented our own code based on the principle and added more functions we need according to actual needs.
17809
- */
17810
-
17811
-
17812
-
17813
- const {
17814
- hasOwnProperty: baseComponent_hasOwnProperty
17815
- } = Object.prototype;
17816
- // eslint-disable-next-line
17817
- class BaseComponent extends external_root_React_commonjs2_react_commonjs_react_amd_react_.Component {
17818
- constructor(props) {
17819
- super(props);
17820
- // eslint-disable-next-line
17821
- this.isControlled = key => Boolean(key && this.props && typeof this.props === 'object' && baseComponent_hasOwnProperty.call(this.props, key));
17822
- this.cache = {};
17823
- this.foundation = null;
17824
- }
17825
- componentDidMount() {
17826
- this.foundation && typeof this.foundation.init === 'function' && this.foundation.init();
17827
- }
17828
- componentWillUnmount() {
17829
- this.foundation && typeof this.foundation.destroy === 'function' && this.foundation.destroy();
17830
- this.cache = {};
17831
- }
17832
- get adapter() {
17833
- return {
17834
- getContext: key => {
17835
- if (this.context && key) {
17836
- return this.context[key];
17837
- }
17838
- },
17839
- getContexts: () => this.context,
17840
- getProp: key => this.props[key],
17841
- // return all props
17842
- getProps: () => this.props,
17843
- getState: key => this.state[key],
17844
- getStates: () => this.state,
17845
- setState: (states, cb) => this.setState(Object.assign({}, states), cb),
17846
- getCache: key => key && this.cache[key],
17847
- getCaches: () => this.cache,
17848
- setCache: (key, value) => key && (this.cache[key] = value),
17849
- stopPropagation: e => {
17850
- try {
17851
- e.stopPropagation();
17852
- e.nativeEvent && e.nativeEvent.stopImmediatePropagation();
17853
- } catch (error) {}
17854
- },
17855
- persistEvent: e => {
17856
- e && e.persist && typeof e.persist === 'function' ? e.persist() : null;
17857
- }
17858
- };
17859
- }
17860
- log(text) {
17861
- for (var _len = arguments.length, rest = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
17862
- rest[_key - 1] = arguments[_key];
17863
- }
17864
- return utils_log(text, ...rest);
17865
- }
17866
- getDataAttr(props) {
17867
- return getDataAttr(props);
17868
- }
17869
- }
17870
- BaseComponent.propTypes = {};
17871
- BaseComponent.defaultProps = {};
17872
17874
  // EXTERNAL MODULE: ../../node_modules/lodash/isObject.js
17873
17875
  var isObject = __webpack_require__("tQYX");
17874
17876
  var isObject_default = /*#__PURE__*/__webpack_require__.n(isObject);
@@ -59009,11 +59011,7 @@ class YearAndMonth extends BaseComponent {
59009
59011
  const right = datePicker_constants_strings.PANEL_TYPE_RIGHT;
59010
59012
  const needDisabled = year => {
59011
59013
  if (panelType === right && currentYear[left]) {
59012
- if (currentMonth[left] <= currentMonth[right]) {
59013
- return currentYear[left] > year;
59014
- } else {
59015
- return currentYear[left] >= year;
59016
- }
59014
+ return currentYear[left] > year;
59017
59015
  }
59018
59016
  return false;
59019
59017
  };
@@ -68035,6 +68033,7 @@ class NotificationList extends BaseComponent {
68035
68033
  }
68036
68034
  static addNotice(notice) {
68037
68035
  var _a;
68036
+ notice = Object.assign(Object.assign({}, notification_defaultConfig), notice);
68038
68037
  const id = (_a = notice.id) !== null && _a !== void 0 ? _a : getUuid('notification');
68039
68038
  if (!ref) {
68040
68039
  const {
@@ -68078,27 +68077,27 @@ class NotificationList extends BaseComponent {
68078
68077
  return id;
68079
68078
  }
68080
68079
  static info(opts) {
68081
- return this.addNotice(Object.assign(Object.assign(Object.assign({}, notification_defaultConfig), opts), {
68080
+ return this.addNotice(Object.assign(Object.assign({}, opts), {
68082
68081
  type: 'info'
68083
68082
  }));
68084
68083
  }
68085
68084
  static success(opts) {
68086
- return this.addNotice(Object.assign(Object.assign(Object.assign({}, notification_defaultConfig), opts), {
68085
+ return this.addNotice(Object.assign(Object.assign({}, opts), {
68087
68086
  type: 'success'
68088
68087
  }));
68089
68088
  }
68090
68089
  static error(opts) {
68091
- return this.addNotice(Object.assign(Object.assign(Object.assign({}, notification_defaultConfig), opts), {
68090
+ return this.addNotice(Object.assign(Object.assign({}, opts), {
68092
68091
  type: 'error'
68093
68092
  }));
68094
68093
  }
68095
68094
  static warning(opts) {
68096
- return this.addNotice(Object.assign(Object.assign(Object.assign({}, notification_defaultConfig), opts), {
68095
+ return this.addNotice(Object.assign(Object.assign({}, opts), {
68097
68096
  type: 'warning'
68098
68097
  }));
68099
68098
  }
68100
68099
  static open(opts) {
68101
- return this.addNotice(Object.assign(Object.assign(Object.assign({}, notification_defaultConfig), opts), {
68100
+ return this.addNotice(Object.assign(Object.assign({}, opts), {
68102
68101
  type: 'default'
68103
68102
  }));
68104
68103
  }
@@ -69373,6 +69372,9 @@ class SelectFoundation extends foundation {
69373
69372
  const newOptions = this._filterOption(options, sugInput).filter(item => !item._inputCreateOnly);
69374
69373
  this._adapter.updateOptions(newOptions);
69375
69374
  this.toggle2SearchInput(true);
69375
+ } else {
69376
+ // whether it is a filter or not, isFocus is guaranteed to be true when open
69377
+ this._adapter.updateFocusState(true);
69376
69378
  }
69377
69379
  this._adapter.openMenu();
69378
69380
  this._setDropdownWidth();
@@ -69399,8 +69401,8 @@ class SelectFoundation extends foundation {
69399
69401
  this._adapter.setIsFocusInContainer(false);
69400
69402
  // this.unBindKeyBoardEvent();
69401
69403
  // this._notifyBlur(e);
69402
- this._adapter.unregisterClickOutsideHandler();
69403
69404
  // this._adapter.updateFocusState(false);
69405
+ this._adapter.unregisterClickOutsideHandler();
69404
69406
  const isFilterable = this._isFilterable();
69405
69407
  if (isFilterable) {
69406
69408
  this.toggle2SearchInput(false);
@@ -70087,7 +70089,6 @@ class SelectFoundation extends foundation {
70087
70089
  this._adapter.setIsFocusInContainer(false);
70088
70090
  }
70089
70091
  handleTriggerBlur(e) {
70090
- this._adapter.updateFocusState(false);
70091
70092
  const {
70092
70093
  filter,
70093
70094
  autoFocus
@@ -70100,6 +70101,7 @@ class SelectFoundation extends foundation {
70100
70101
  // But when autoFocus or the panel is close, because clickOutsideHandler is not register or unregister, you need to listen for the trigger's blur and trigger the notify callback
70101
70102
  if (isFocus && !isOpen) {
70102
70103
  this._notifyBlur(e);
70104
+ this._adapter.updateFocusState(false);
70103
70105
  }
70104
70106
  }
70105
70107
  handleInputBlur(e) {
@@ -89703,6 +89705,12 @@ class TreeSelectFoundation extends foundation {
89703
89705
  this.close(e);
89704
89706
  });
89705
89707
  };
89708
+ this.clearInputValue = () => {
89709
+ const {
89710
+ inputValue
89711
+ } = this.getStates();
89712
+ inputValue && this._adapter.updateInputValue('');
89713
+ };
89706
89714
  }
89707
89715
  init() {
89708
89716
  const {
@@ -89854,7 +89862,7 @@ class TreeSelectFoundation extends foundation {
89854
89862
  const isSearching = Boolean(inputValue);
89855
89863
  const treeNodeProps = {
89856
89864
  eventKey: key,
89857
- expanded: isSearching && !this._isExpandControlled() ? filteredExpandedKeys.has(key) : expandedKeys.has(key),
89865
+ expanded: isSearching ? filteredExpandedKeys.has(key) : expandedKeys.has(key),
89858
89866
  selected: selectedKeys.includes(key),
89859
89867
  checked: realChecked,
89860
89868
  halfChecked: realHalfChecked,
@@ -90127,8 +90135,8 @@ class TreeSelectFoundation extends foundation {
90127
90135
  expandedOptsKeys.forEach(item => newExpandedKeys.add(item));
90128
90136
  const newFlattenNodes = flattenTreeData(treeData, newExpandedKeys, keyMaps);
90129
90137
  this._adapter.updateState({
90130
- expandedKeys: isExpandControlled ? expandedKeys : newExpandedKeys,
90131
- flattenNodes: isExpandControlled ? flattenNodes : newFlattenNodes,
90138
+ expandedKeys: newExpandedKeys,
90139
+ flattenNodes: newFlattenNodes,
90132
90140
  inputValue: '',
90133
90141
  motionKeys: new Set([]),
90134
90142
  filteredKeys: new Set([]),
@@ -90177,8 +90185,8 @@ class TreeSelectFoundation extends foundation {
90177
90185
  const newFilteredExpandedKeys = new Set(expandedOptsKeys);
90178
90186
  this._adapter.notifySearch(sugInput, Array.from(newFilteredExpandedKeys));
90179
90187
  this._adapter.updateState({
90180
- expandedKeys: this._isExpandControlled() ? expandedKeys : newExpandedKeys,
90181
- flattenNodes: this._isExpandControlled() ? flattenNodes : newFlattenNodes,
90188
+ expandedKeys: newExpandedKeys,
90189
+ flattenNodes: newFlattenNodes,
90182
90190
  motionKeys: new Set([]),
90183
90191
  filteredKeys: new Set(filteredOptsKeys),
90184
90192
  filteredExpandedKeys: newFilteredExpandedKeys,
@@ -90386,7 +90394,7 @@ class TreeSelectFoundation extends foundation {
90386
90394
  return;
90387
90395
  }
90388
90396
  const isExpandControlled = this._isExpandControlled();
90389
- if (isSearching && !isExpandControlled) {
90397
+ if (isSearching) {
90390
90398
  this.handleNodeExpandInSearch(e, treeNode);
90391
90399
  return;
90392
90400
  }
@@ -91156,13 +91164,27 @@ class TreeSelect extends BaseComponent {
91156
91164
  searchAutoFocus,
91157
91165
  searchPosition
91158
91166
  } = this.props;
91159
- if (isVisible === false && Boolean(filterTreeNode)) {
91160
- this.foundation.clearInput();
91167
+ // inputValue 清空,如果有选中值的话,选中项能够快速回显
91168
+ // Clear the inputValue. If there is a selected value, the selected item can be quickly echoed.
91169
+ if (isVisible === false && filterTreeNode) {
91170
+ this.foundation.clearInputValue();
91161
91171
  }
91162
91172
  if (filterTreeNode && searchPosition === treeSelect_constants_strings.SEARCH_POSITION_DROPDOWN && isVisible && searchAutoFocus) {
91163
91173
  this.foundation.focusInput(true);
91164
91174
  }
91165
91175
  };
91176
+ this.afterClose = () => {
91177
+ // flattenNode 的变化将导致弹出层面板中的选项数目变化
91178
+ // 在弹层完全收起之后,再通过 clearInput 重新计算 state 中的 expandedKey, flattenNode
91179
+ // 防止在弹出层未收起时弹层面板中选项数目变化导致视觉上出现弹层闪动问题
91180
+ // Changes to flattenNode will cause the number of options in the popup panel to change
91181
+ // After the pop-up layer is completely closed, recalculate the expandedKey and flattenNode in the state through clearInput.
91182
+ // Prevent the pop-up layer from flickering visually due to changes in the number of options in the pop-up panel when the pop-up layer is not collapsed.
91183
+ const {
91184
+ filterTreeNode
91185
+ } = this.props;
91186
+ filterTreeNode && this.foundation.clearInput();
91187
+ };
91166
91188
  this.renderTreeNode = (treeNode, ind, style) => {
91167
91189
  const {
91168
91190
  data,
@@ -91199,6 +91221,7 @@ class TreeSelect extends BaseComponent {
91199
91221
  this.renderNodeList = () => {
91200
91222
  const {
91201
91223
  flattenNodes,
91224
+ cachedFlattenNodes,
91202
91225
  motionKeys,
91203
91226
  motionType,
91204
91227
  filteredKeys
@@ -91214,7 +91237,7 @@ class TreeSelect extends BaseComponent {
91214
91237
  if (!virtualize || isEmpty_default()(virtualize)) {
91215
91238
  return /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createElement(NodeList, {
91216
91239
  flattenNodes: flattenNodes,
91217
- flattenList: this._flattenNodes,
91240
+ flattenList: cachedFlattenNodes,
91218
91241
  motionKeys: motionExpand ? motionKeys : new Set([]),
91219
91242
  motionType: motionType,
91220
91243
  // When motionKeys is empty, but filteredKeys is not empty (that is, the search hits), this situation should be distinguished from ordinary motionKeys
@@ -91333,6 +91356,7 @@ class TreeSelect extends BaseComponent {
91333
91356
  keyEntities: {},
91334
91357
  treeData: [],
91335
91358
  flattenNodes: [],
91359
+ cachedFlattenNodes: undefined,
91336
91360
  selectedKeys: [],
91337
91361
  checkedKeys: new Set(),
91338
91362
  halfCheckedKeys: new Set(),
@@ -91362,6 +91386,7 @@ class TreeSelect extends BaseComponent {
91362
91386
  };
91363
91387
  }
91364
91388
  static getDerivedStateFromProps(props, prevState) {
91389
+ var _a;
91365
91390
  const {
91366
91391
  prevProps,
91367
91392
  rePosKey
@@ -91379,6 +91404,8 @@ class TreeSelect extends BaseComponent {
91379
91404
  };
91380
91405
  const needUpdateTreeData = needUpdate('treeData');
91381
91406
  const needUpdateExpandedKeys = needUpdate('expandedKeys');
91407
+ const isExpandControlled = ('expandedKeys' in props);
91408
+ const isSearching = Boolean(props.filterTreeNode && prevState.inputValue && prevState.inputValue.length);
91382
91409
  // TreeNode
91383
91410
  if (needUpdateTreeData) {
91384
91411
  treeData = props.treeData;
@@ -91397,31 +91424,97 @@ class TreeSelect extends BaseComponent {
91397
91424
  }
91398
91425
  }
91399
91426
  const expandAllWhenDataChange = needUpdateTreeData && props.expandAll;
91400
- // expandedKeys
91401
- if (needUpdateExpandedKeys || prevProps && needUpdate('autoExpandParent')) {
91402
- newState.expandedKeys = calcExpandedKeys(props.expandedKeys, keyEntities, props.autoExpandParent || !prevProps);
91403
- // only show animation when treeData does not change
91404
- if (prevProps && props.motion && !treeData) {
91405
- const {
91406
- motionKeys,
91407
- motionType
91408
- } = calcMotionKeys(prevState.expandedKeys, newState.expandedKeys, keyEntities);
91409
- newState.motionKeys = new Set(motionKeys);
91410
- newState.motionType = motionType;
91411
- }
91412
- } else if (!prevProps && (props.defaultExpandAll || props.expandAll) || expandAllWhenDataChange) {
91413
- newState.expandedKeys = new Set(Object.keys(keyEntities));
91414
- } else if (!prevProps && props.defaultExpandedKeys) {
91415
- newState.expandedKeys = calcExpandedKeys(props.defaultExpandedKeys, keyEntities);
91416
- } else if (!prevProps && props.defaultValue) {
91417
- newState.expandedKeys = calcExpandedKeysForValues(normalizeValue(props.defaultValue, withObject, keyMaps), keyEntities, props.multiple, valueEntities);
91418
- } else if (!prevProps && props.value) {
91419
- newState.expandedKeys = calcExpandedKeysForValues(normalizeValue(props.value, withObject, keyMaps), keyEntities, props.multiple, valueEntities);
91420
- }
91421
- // flattenNodes
91422
- if (treeData || needUpdateExpandedKeys) {
91423
- const flattenNodes = flattenTreeData(treeData || prevState.treeData, newState.expandedKeys || prevState.expandedKeys, keyMaps);
91424
- newState.flattenNodes = flattenNodes;
91427
+ if (!isSearching) {
91428
+ // expandedKeys
91429
+ if (needUpdateExpandedKeys || prevProps && needUpdate('autoExpandParent')) {
91430
+ newState.expandedKeys = calcExpandedKeys(props.expandedKeys, keyEntities, props.autoExpandParent || !prevProps);
91431
+ // only show animation when treeData does not change
91432
+ if (prevProps && props.motion && !treeData) {
91433
+ const {
91434
+ motionKeys,
91435
+ motionType
91436
+ } = calcMotionKeys(prevState.expandedKeys, newState.expandedKeys, keyEntities);
91437
+ newState.motionKeys = new Set(motionKeys);
91438
+ newState.motionType = motionType;
91439
+ if (motionType === 'hide') {
91440
+ // cache flatten nodes: expandedKeys changed may not be triggered by interaction
91441
+ newState.cachedFlattenNodes = treeUtil_cloneDeep(prevState.flattenNodes);
91442
+ }
91443
+ }
91444
+ } else if (!prevProps && (props.defaultExpandAll || props.expandAll) || expandAllWhenDataChange) {
91445
+ newState.expandedKeys = new Set(Object.keys(keyEntities));
91446
+ } else if (!prevProps && props.defaultExpandedKeys) {
91447
+ newState.expandedKeys = calcExpandedKeys(props.defaultExpandedKeys, keyEntities);
91448
+ } else if (!prevProps && props.defaultValue) {
91449
+ newState.expandedKeys = calcExpandedKeysForValues(normalizeValue(props.defaultValue, withObject, keyMaps), keyEntities, props.multiple, valueEntities);
91450
+ } else if (!prevProps && props.value) {
91451
+ newState.expandedKeys = calcExpandedKeysForValues(normalizeValue(props.value, withObject, keyMaps), keyEntities, props.multiple, valueEntities);
91452
+ } else if (!isExpandControlled && needUpdateTreeData && props.value) {
91453
+ // 当 treeData 已经设置具体的值,并且设置了 props.loadData ,则认为 treeData 的更新是因为 loadData 导致的
91454
+ // 如果是因为 loadData 导致 treeData改变, 此时在这里重新计算 key 会导致为未选中的展开项目被收起
91455
+ // 所以此时不需要重新计算 expandedKeys,因为在点击展开按钮时候已经把被展开的项添加到 expandedKeys 中
91456
+ // When treeData has a specific value and props.loadData is set, it is considered that the update of treeData is caused by loadData
91457
+ // If the treeData is changed because of loadData, recalculating the key here will cause the unselected expanded items to be collapsed
91458
+ // So there is no need to recalculate expandedKeys at this time, because the expanded item has been added to expandedKeys when the expand button is clicked
91459
+ if (!(prevState.treeData && ((_a = prevState.treeData) === null || _a === void 0 ? void 0 : _a.length) > 0 && props.loadData)) {
91460
+ newState.expandedKeys = calcExpandedKeysForValues(props.value, keyEntities, props.multiple, valueEntities);
91461
+ }
91462
+ }
91463
+ if (!newState.expandedKeys) {
91464
+ delete newState.expandedKeys;
91465
+ }
91466
+ if (treeData || newState.expandedKeys) {
91467
+ const flattenNodes = flattenTreeData(treeData || prevState.treeData, newState.expandedKeys || prevState.expandedKeys, keyMaps);
91468
+ newState.flattenNodes = flattenNodes;
91469
+ }
91470
+ } else {
91471
+ let filteredState;
91472
+ // treeData changed while searching
91473
+ if (treeData) {
91474
+ // Get filter data
91475
+ filteredState = filterTreeData({
91476
+ treeData,
91477
+ inputValue: prevState.inputValue,
91478
+ filterTreeNode: props.filterTreeNode,
91479
+ filterProps: props.treeNodeFilterProp,
91480
+ showFilteredOnly: props.showFilteredOnly,
91481
+ keyEntities: newState.keyEntities,
91482
+ prevExpandedKeys: [...prevState.filteredExpandedKeys],
91483
+ keyMaps: keyMaps
91484
+ });
91485
+ newState.flattenNodes = filteredState.flattenNodes;
91486
+ newState.motionKeys = new Set([]);
91487
+ newState.filteredKeys = filteredState.filteredKeys;
91488
+ newState.filteredShownKeys = filteredState.filteredShownKeys;
91489
+ newState.filteredExpandedKeys = filteredState.filteredExpandedKeys;
91490
+ }
91491
+ // expandedKeys changed while searching
91492
+ if (props.expandedKeys) {
91493
+ newState.filteredExpandedKeys = calcExpandedKeys(props.expandedKeys, keyEntities, props.autoExpandParent || !prevProps);
91494
+ if (prevProps && props.motion) {
91495
+ const prevKeys = prevState ? prevState.filteredExpandedKeys : new Set([]);
91496
+ // only show animation when treeData does not change
91497
+ if (!treeData) {
91498
+ const motionResult = calcMotionKeys(prevKeys, newState.filteredExpandedKeys, keyEntities);
91499
+ let {
91500
+ motionKeys
91501
+ } = motionResult;
91502
+ const {
91503
+ motionType
91504
+ } = motionResult;
91505
+ if (props.showFilteredOnly) {
91506
+ motionKeys = motionKeys.filter(key => prevState.filteredShownKeys.has(key));
91507
+ }
91508
+ if (motionType === 'hide') {
91509
+ // cache flatten nodes: expandedKeys changed may not be triggered by interaction
91510
+ newState.cachedFlattenNodes = treeUtil_cloneDeep(prevState.flattenNodes);
91511
+ }
91512
+ newState.motionKeys = new Set(motionKeys);
91513
+ newState.motionType = motionType;
91514
+ }
91515
+ }
91516
+ newState.flattenNodes = flattenTreeData(treeData || prevState.treeData, newState.filteredExpandedKeys || prevState.filteredExpandedKeys, keyMaps, props.showFilteredOnly && prevState.filteredShownKeys);
91517
+ }
91425
91518
  }
91426
91519
  // selectedKeys: single mode controlled
91427
91520
  const isMultiple = props.multiple;
@@ -91528,7 +91621,9 @@ class TreeSelect extends BaseComponent {
91528
91621
  this.props.onSearch && this.props.onSearch(input, filteredExpandedKeys);
91529
91622
  },
91530
91623
  cacheFlattenNodes: bool => {
91531
- this._flattenNodes = bool ? treeUtil_cloneDeep(this.state.flattenNodes) : null;
91624
+ this.setState({
91625
+ cachedFlattenNodes: bool ? treeUtil_cloneDeep(this.state.flattenNodes) : undefined
91626
+ });
91532
91627
  },
91533
91628
  notifyLoad: (newLoadedKeys, data) => {
91534
91629
  const {
@@ -91673,7 +91768,8 @@ class TreeSelect extends BaseComponent {
91673
91768
  autoAdjustOverflow: autoAdjustOverflow,
91674
91769
  mouseLeaveDelay: mouseLeaveDelay,
91675
91770
  mouseEnterDelay: mouseEnterDelay,
91676
- onVisibleChange: this.handlePopoverClose
91771
+ onVisibleChange: this.handlePopoverClose,
91772
+ afterClose: this.afterClose
91677
91773
  }, selection);
91678
91774
  }
91679
91775
  }
@@ -99029,14 +99125,14 @@ const PreviewContext = /*#__PURE__*/(0,external_root_React_commonjs2_react_commo
99029
99125
 
99030
99126
 
99031
99127
  const previewHeader_prefixCls = `${image_constants_cssClasses.PREFIX}-preview-header`;
99032
- const previewHeader_Header = _ref => {
99128
+ const previewHeader_Header = /*#__PURE__*/(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.forwardRef)((_ref, ref) => {
99033
99129
  let {
99034
99130
  onClose,
99035
99131
  titleStyle,
99036
99132
  className,
99037
99133
  renderHeader
99038
99134
  } = _ref;
99039
- return /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_.createElement(PreviewContext.Consumer, null, _ref2 => {
99135
+ return /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createElement(PreviewContext.Consumer, null, _ref2 => {
99040
99136
  let {
99041
99137
  currentIndex,
99042
99138
  titles
@@ -99045,17 +99141,18 @@ const previewHeader_Header = _ref => {
99045
99141
  if (titles && typeof currentIndex === "number") {
99046
99142
  title = titles[currentIndex];
99047
99143
  }
99048
- return /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_.createElement("section", {
99144
+ return /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createElement("section", {
99145
+ ref: ref,
99049
99146
  className: classnames_default()(previewHeader_prefixCls, className)
99050
- }, /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_.createElement("section", {
99147
+ }, /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createElement("section", {
99051
99148
  className: `${previewHeader_prefixCls}-title`,
99052
99149
  style: titleStyle
99053
- }, renderHeader ? renderHeader(title) : title), /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_.createElement("section", {
99150
+ }, renderHeader ? renderHeader(title) : title), /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createElement("section", {
99054
99151
  className: `${previewHeader_prefixCls}-close`,
99055
99152
  onMouseUp: onClose
99056
- }, /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_.createElement(IconClose, null)));
99153
+ }, /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createElement(IconClose, null)));
99057
99154
  });
99058
- };
99155
+ });
99059
99156
  /* harmony default export */ const previewHeader = (previewHeader_Header);
99060
99157
  ;// CONCATENATED MODULE: ../semi-icons/lib/es/icons/IconMinus.js
99061
99158
 
@@ -99211,7 +99308,6 @@ class PreviewFooterFoundation extends foundation {
99211
99308
  } else {
99212
99309
  onZoomOut(Number((value / 100).toFixed(2)));
99213
99310
  }
99214
- this._adapter.setStartMouseOffset(value);
99215
99311
  };
99216
99312
  this.handleRatioClick = () => {
99217
99313
  const {
@@ -99244,14 +99340,9 @@ class PreviewFooterFoundation extends foundation {
99244
99340
 
99245
99341
  const previewFooter_prefixCls = image_constants_cssClasses.PREFIX;
99246
99342
  const footerPrefixCls = `${image_constants_cssClasses.PREFIX}-preview-footer`;
99247
- let mouseActiveTime = 0;
99248
99343
  class previewFooter_Footer extends BaseComponent {
99249
99344
  get adapter() {
99250
- return Object.assign(Object.assign({}, super.adapter), {
99251
- setStartMouseOffset: time => {
99252
- mouseActiveTime = time;
99253
- }
99254
- });
99345
+ return Object.assign({}, super.adapter);
99255
99346
  }
99256
99347
  constructor(props) {
99257
99348
  super(props);
@@ -99491,13 +99582,15 @@ class previewFooter_Footer extends BaseComponent {
99491
99582
  render() {
99492
99583
  const {
99493
99584
  className,
99494
- renderPreviewMenu
99585
+ renderPreviewMenu,
99586
+ forwardRef
99495
99587
  } = this.props;
99496
99588
  const menuCls = classnames_default()(footerPrefixCls, `${footerPrefixCls}-wrapper`, className, {
99497
99589
  [`${footerPrefixCls}-content`]: !Boolean(renderPreviewMenu)
99498
99590
  });
99499
99591
  return /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createElement("section", {
99500
- className: menuCls
99592
+ className: menuCls,
99593
+ ref: forwardRef
99501
99594
  }, renderPreviewMenu ? this.customRenderViewMenu() : this.getFooterMenu());
99502
99595
  }
99503
99596
  }
@@ -99536,9 +99629,6 @@ previewFooter_Footer.defaultProps = {
99536
99629
  };
99537
99630
  ;// CONCATENATED MODULE: ../semi-foundation/image/previewImageFoundation.ts
99538
99631
 
99539
-
99540
-
99541
-
99542
99632
  const DefaultDOMRect = {
99543
99633
  bottom: 0,
99544
99634
  height: 0,
@@ -99552,7 +99642,15 @@ const DefaultDOMRect = {
99552
99642
  };
99553
99643
  class PreviewImageFoundation extends foundation {
99554
99644
  constructor(adapter) {
99645
+ var _this;
99555
99646
  super(Object.assign({}, adapter));
99647
+ _this = this;
99648
+ this.startMouseOffset = {
99649
+ x: 0,
99650
+ y: 0
99651
+ };
99652
+ this.originImageWidth = null;
99653
+ this.originImageHeight = null;
99556
99654
  this._isImageVertical = () => this.getProp("rotation") % 180 !== 0;
99557
99655
  this._getImageBounds = () => {
99558
99656
  const imageDOM = this._adapter.getImage();
@@ -99582,36 +99680,24 @@ class PreviewImageFoundation extends foundation {
99582
99680
  this._adapter.setLoading(loading);
99583
99681
  };
99584
99682
  this.handleWindowResize = () => {
99585
- const {
99586
- ratio,
99587
- setRatio
99588
- } = this.getProps();
99589
- const {
99590
- originImageWidth,
99591
- originImageHeight
99592
- } = this._adapter.getOriginImageSize();
99593
- if (originImageWidth && originImageHeight) {
99594
- if (ratio !== "adaptation") {
99595
- setRatio("adaptation");
99596
- } else {
99597
- this.handleResizeImage();
99598
- }
99683
+ if (this.originImageWidth && this.originImageHeight) {
99684
+ this.handleResizeImage();
99599
99685
  }
99600
99686
  };
99601
99687
  this.handleLoad = e => {
99602
99688
  if (e.target) {
99603
99689
  const {
99604
- width: w,
99605
- height: h
99690
+ naturalWidth: w,
99691
+ naturalHeight: h
99606
99692
  } = e.target;
99607
- this._adapter.setOriginImageSize({
99608
- originImageWidth: w,
99609
- originImageHeight: h
99610
- });
99693
+ this.originImageHeight = h;
99694
+ this.originImageWidth = w;
99611
99695
  this.setState({
99612
99696
  loading: false
99613
99697
  });
99614
- this.handleResizeImage();
99698
+ // 图片初次加载,计算 zoom,zoom 改变不需要通过回调透出
99699
+ // When the image is loaded for the first time, zoom is calculated, and zoom changes do not need to be exposed through callbacks.
99700
+ this.handleResizeImage(false);
99615
99701
  }
99616
99702
  const {
99617
99703
  src,
@@ -99629,27 +99715,65 @@ class PreviewImageFoundation extends foundation {
99629
99715
  });
99630
99716
  onError && onError(src);
99631
99717
  };
99632
- this.handleResizeImage = () => {
99633
- const horizontal = !this._isImageVertical();
99718
+ this.handleResizeImage = function () {
99719
+ let notify = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
99720
+ const horizontal = !_this._isImageVertical();
99634
99721
  const {
99635
- originImageWidth,
99636
- originImageHeight
99637
- } = this._adapter.getOriginImageSize();
99638
- const imgWidth = horizontal ? originImageWidth : originImageHeight;
99639
- const imgHeight = horizontal ? originImageHeight : originImageWidth;
99722
+ currZoom
99723
+ } = _this.getStates();
99724
+ const imgWidth = horizontal ? _this.originImageWidth : _this.originImageHeight;
99725
+ const imgHeight = horizontal ? _this.originImageHeight : _this.originImageWidth;
99640
99726
  const {
99641
- onZoom
99642
- } = this.getProps();
99643
- const containerDOM = this._adapter.getContainer();
99727
+ onZoom,
99728
+ setRatio,
99729
+ ratio
99730
+ } = _this.getProps();
99731
+ const containerDOM = _this._adapter.getContainer();
99644
99732
  if (containerDOM) {
99645
99733
  const {
99646
99734
  width: containerWidth,
99647
99735
  height: containerHeight
99648
- } = this._getContainerBounds();
99736
+ } = _this._getContainerBounds();
99649
99737
  const reservedWidth = containerWidth - 80;
99650
99738
  const reservedHeight = containerHeight - 80;
99651
- const _zoom = Number(Math.min(reservedWidth / imgWidth, reservedHeight / imgHeight).toFixed(2));
99652
- onZoom(_zoom);
99739
+ let _zoom = 1;
99740
+ if (imgWidth > reservedWidth || imgHeight > reservedHeight) {
99741
+ _zoom = Number(Math.min(reservedWidth / imgWidth, reservedHeight / imgHeight).toFixed(2));
99742
+ }
99743
+ if (currZoom === _zoom) {
99744
+ _this.calculatePreviewImage(_zoom, null);
99745
+ } else {
99746
+ onZoom(_zoom, notify);
99747
+ }
99748
+ }
99749
+ };
99750
+ this.handleRatioChange = () => {
99751
+ if (this.originImageWidth && this.originImageHeight) {
99752
+ const {
99753
+ currZoom
99754
+ } = this.getStates();
99755
+ const {
99756
+ ratio,
99757
+ onZoom
99758
+ } = this.getProps();
99759
+ let _zoom;
99760
+ if (ratio === 'adaptation') {
99761
+ const horizontal = !this._isImageVertical();
99762
+ const imgWidth = horizontal ? this.originImageWidth : this.originImageHeight;
99763
+ const imgHeight = horizontal ? this.originImageHeight : this.originImageWidth;
99764
+ const {
99765
+ width: containerWidth,
99766
+ height: containerHeight
99767
+ } = this._getContainerBounds();
99768
+ const reservedWidth = containerWidth - 80;
99769
+ const reservedHeight = containerHeight - 80;
99770
+ _zoom = Number(Math.min(reservedWidth / imgWidth, reservedHeight / imgHeight).toFixed(2));
99771
+ } else {
99772
+ _zoom = 1;
99773
+ }
99774
+ if (currZoom !== _zoom) {
99775
+ onZoom(_zoom);
99776
+ }
99653
99777
  }
99654
99778
  };
99655
99779
  this.handleRightClickImage = e => {
@@ -99664,38 +99788,6 @@ class PreviewImageFoundation extends foundation {
99664
99788
  return true;
99665
99789
  }
99666
99790
  };
99667
- // e: WheelEvent<HTMLImageElement>
99668
- this.handleWheel = e => {
99669
- this.onWheel(e);
99670
- handlePrevent(e);
99671
- };
99672
- // e: WheelEvent<HTMLImageElement>
99673
- this.onWheel = throttle_default()(e => {
99674
- const {
99675
- onZoom,
99676
- zoomStep,
99677
- maxZoom,
99678
- minZoom
99679
- } = this.getProps();
99680
- const {
99681
- currZoom
99682
- } = this.getStates();
99683
- let _zoom;
99684
- if (e.deltaY < 0) {
99685
- /* zoom in */
99686
- if (currZoom + zoomStep <= maxZoom) {
99687
- _zoom = Number((currZoom + zoomStep).toFixed(2));
99688
- }
99689
- } else if (e.deltaY > 0) {
99690
- /* zoom out */
99691
- if (currZoom - zoomStep >= minZoom) {
99692
- _zoom = Number((currZoom - zoomStep).toFixed(2));
99693
- }
99694
- }
99695
- if (!isUndefined_default()(_zoom)) {
99696
- onZoom(_zoom);
99697
- }
99698
- }, 50);
99699
99791
  this.calcCanDragDirection = () => {
99700
99792
  const {
99701
99793
  width,
@@ -99719,12 +99811,8 @@ class PreviewImageFoundation extends foundation {
99719
99811
  canDragHorizontal
99720
99812
  };
99721
99813
  };
99722
- this.handleZoomChange = (newZoom, e) => {
99814
+ this.calculatePreviewImage = (newZoom, e) => {
99723
99815
  const imageDOM = this._adapter.getImage();
99724
- const {
99725
- originImageWidth,
99726
- originImageHeight
99727
- } = this._adapter.getOriginImageSize();
99728
99816
  const {
99729
99817
  canDragVertical,
99730
99818
  canDragHorizontal
@@ -99734,8 +99822,8 @@ class PreviewImageFoundation extends foundation {
99734
99822
  width: containerWidth,
99735
99823
  height: containerHeight
99736
99824
  } = this._getContainerBounds();
99737
- const newWidth = Math.floor(originImageWidth * newZoom);
99738
- const newHeight = Math.floor(originImageHeight * newZoom);
99825
+ const newWidth = Math.floor(this.originImageWidth * newZoom);
99826
+ const newHeight = Math.floor(this.originImageHeight * newZoom);
99739
99827
  // debugger;
99740
99828
  let _offset;
99741
99829
  const horizontal = !this._isImageVertical();
@@ -99794,13 +99882,13 @@ class PreviewImageFoundation extends foundation {
99794
99882
  width,
99795
99883
  height
99796
99884
  } = this.getStates();
99797
- const startMouseMove = this._adapter.getMouseMove();
99798
- const startMouseOffset = this._adapter.getMouseOffset();
99799
99885
  const {
99800
99886
  canDragVertical,
99801
99887
  canDragHorizontal
99802
99888
  } = this.calcCanDragDirection();
99803
- if (startMouseMove && (canDragVertical || canDragHorizontal)) {
99889
+ // https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/buttons
99890
+ const mouseLeftPress = e.buttons === 1;
99891
+ if (mouseLeftPress && (canDragVertical || canDragHorizontal)) {
99804
99892
  const {
99805
99893
  clientX,
99806
99894
  clientY
@@ -99813,8 +99901,8 @@ class PreviewImageFoundation extends foundation {
99813
99901
  left: extremeLeft,
99814
99902
  top: extremeTop
99815
99903
  } = this.calcExtremeBounds();
99816
- let newX = canDragHorizontal ? clientX - containerLeft - startMouseOffset.x : offset.x;
99817
- let newY = canDragVertical ? clientY - containerTop - startMouseOffset.y : offset.y;
99904
+ let newX = canDragHorizontal ? clientX - containerLeft - this.startMouseOffset.x : offset.x;
99905
+ let newY = canDragVertical ? clientY - containerTop - this.startMouseOffset.y : offset.y;
99818
99906
  if (canDragHorizontal) {
99819
99907
  newX = newX > 0 ? 0 : newX < extremeLeft ? extremeLeft : newX;
99820
99908
  }
@@ -99833,11 +99921,7 @@ class PreviewImageFoundation extends foundation {
99833
99921
  }
99834
99922
  };
99835
99923
  this.handleImageMouseDown = e => {
99836
- this._adapter.setStartMouseOffset(this._getOffset(e));
99837
- this._adapter.setStartMouseMove(true);
99838
- };
99839
- this.handleImageMouseUp = () => {
99840
- this._adapter.setStartMouseMove(false);
99924
+ this.startMouseOffset = this._getOffset(e);
99841
99925
  };
99842
99926
  }
99843
99927
  }
@@ -99850,38 +99934,14 @@ class PreviewImageFoundation extends foundation {
99850
99934
 
99851
99935
  const previewImage_prefixCls = image_constants_cssClasses.PREFIX;
99852
99936
  const preViewImgPrefixCls = `${previewImage_prefixCls}-preview-image`;
99853
- let originImageWidth = null;
99854
- let originImageHeight = null;
99855
- let startMouseMove = false;
99856
- // startMouseOffset:The offset of the mouse relative to the left and top of the picture
99857
- let startMouseOffset = {
99858
- x: 0,
99859
- y: 0
99860
- };
99861
99937
  class PreviewImage extends BaseComponent {
99862
99938
  get adapter() {
99863
99939
  return Object.assign(Object.assign({}, super.adapter), {
99864
- getOriginImageSize: () => ({
99865
- originImageWidth,
99866
- originImageHeight
99867
- }),
99868
- setOriginImageSize: size => {
99869
- originImageWidth = size.originImageWidth;
99870
- originImageHeight = size.originImageHeight;
99871
- },
99872
99940
  getContainer: () => {
99873
99941
  return this.containerRef.current;
99874
99942
  },
99875
99943
  getImage: () => {
99876
- return this.imageRef;
99877
- },
99878
- getMouseMove: () => startMouseMove,
99879
- setStartMouseMove: move => {
99880
- startMouseMove = move;
99881
- },
99882
- getMouseOffset: () => startMouseOffset,
99883
- setStartMouseOffset: offset => {
99884
- startMouseOffset = offset;
99944
+ return this.imageRef.current;
99885
99945
  },
99886
99946
  setLoading: loading => {
99887
99947
  this.setState({
@@ -99889,7 +99949,7 @@ class PreviewImage extends BaseComponent {
99889
99949
  });
99890
99950
  },
99891
99951
  setImageCursor: canDrag => {
99892
- this.imageRef.style.cursor = canDrag ? "grab" : "default";
99952
+ this.imageRef.current.style.cursor = canDrag ? "grab" : "default";
99893
99953
  }
99894
99954
  });
99895
99955
  }
@@ -99898,52 +99958,22 @@ class PreviewImage extends BaseComponent {
99898
99958
  this.onWindowResize = () => {
99899
99959
  this.foundation.handleWindowResize();
99900
99960
  };
99901
- this.handleZoomChange = (newZoom, e) => {
99902
- this.foundation.handleZoomChange(newZoom, e);
99903
- };
99904
99961
  // Determine the response method of right click according to the disableDownload parameter in props
99905
99962
  this.handleRightClickImage = e => {
99906
99963
  this.foundation.handleRightClickImage(e);
99907
99964
  };
99908
- this.handleWheel = e => {
99909
- this.foundation.handleWheel(e);
99910
- };
99911
99965
  this.handleLoad = e => {
99912
99966
  this.foundation.handleLoad(e);
99913
99967
  };
99914
99968
  this.handleError = e => {
99915
99969
  this.foundation.handleError(e);
99916
99970
  };
99917
- this.resizeImage = () => {
99918
- this.foundation.handleResizeImage();
99919
- };
99920
99971
  this.handleMoveImage = e => {
99921
99972
  this.foundation.handleMoveImage(e);
99922
99973
  };
99923
- // 为什么通过ref注册wheel而不是使用onWheel事件?
99924
- // 因为对于wheel事件,浏览器将 addEventListener 的 passive 默认值更改为 true。如此,事件监听器便不能取消事件,也不会在用户滚动页面时阻止页面呈现。
99925
- // 这里我们需要保持页面不动,仅放大图片,因此此处需要将 passive 更改设置为 false。
99926
- // Why register wheel via ref instead of using onWheel event?
99927
- // Because for wheel events, the browser changes the passive default of addEventListener to true. This way, the event listener cannot cancel the event, nor prevent the page from rendering when the user scrolls.
99928
- // Here we need to keep the page still and only zoom in on the image, so here we need to set the passive change to false.
99929
- // https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#improving_scrolling_performance_with_passive_listeners。
99930
- this.registryImageRef = ref => {
99931
- if (this.imageRef) {
99932
- this.imageRef.removeEventListener("wheel", this.handleWheel);
99933
- }
99934
- if (ref) {
99935
- ref.addEventListener("wheel", this.handleWheel, {
99936
- passive: false
99937
- });
99938
- }
99939
- this.imageRef = ref;
99940
- };
99941
99974
  this.onImageMouseDown = e => {
99942
99975
  this.foundation.handleImageMouseDown(e);
99943
99976
  };
99944
- this.onImageMouseUp = () => {
99945
- this.foundation.handleImageMouseUp();
99946
- };
99947
99977
  this.state = {
99948
99978
  width: 0,
99949
99979
  height: 0,
@@ -99957,7 +99987,7 @@ class PreviewImage extends BaseComponent {
99957
99987
  left: 0
99958
99988
  };
99959
99989
  this.containerRef = /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createRef();
99960
- this.imageRef = null;
99990
+ this.imageRef = /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createRef();
99961
99991
  this.foundation = new PreviewImageFoundation(this.adapter);
99962
99992
  }
99963
99993
  componentDidMount() {
@@ -99968,27 +99998,22 @@ class PreviewImage extends BaseComponent {
99968
99998
  }
99969
99999
  componentDidUpdate(prevProps, prevStates) {
99970
100000
  // If src changes, start a new loading
99971
- if (this.props.src && this.props.src !== prevProps.src) {
100001
+ const zoomChange = "zoom" in this.props && this.props.zoom !== this.state.currZoom;
100002
+ const srcChange = this.props.src && this.props.src !== prevProps.src;
100003
+ if (srcChange) {
99972
100004
  this.foundation.setLoading(true);
99973
100005
  }
99974
100006
  // If the incoming zoom changes, other content changes are determined based on the new zoom value
99975
- if ("zoom" in this.props && this.props.zoom !== prevStates.currZoom) {
99976
- this.handleZoomChange(this.props.zoom, null);
99977
- }
99978
- // When the incoming ratio is changed, if it"s adaptation, then resizeImage is triggered to make the image adapt to the page
99979
- // else if it"s adaptation is realSize, then onZoom(1) is called to make the image size the original size;
99980
- if ("ratio" in this.props && this.props.ratio !== prevProps.ratio) {
99981
- if (originImageWidth && originImageHeight) {
99982
- if (this.props.ratio === "adaptation") {
99983
- this.resizeImage();
99984
- } else {
99985
- this.props.onZoom(1);
99986
- }
99987
- }
100007
+ if (zoomChange) {
100008
+ this.foundation.calculatePreviewImage(this.props.zoom, null);
99988
100009
  }
99989
- // When the incoming rotation angle of the image changes, it needs to be resized to make the image fit on the page
99990
- if ("rotation" in this.props && this.props.rotation !== prevProps.rotation) {
99991
- this.onWindowResize();
100010
+ if (!zoomChange && !srcChange && prevProps) {
100011
+ if ("ratio" in this.props && this.props.ratio !== prevProps.ratio) {
100012
+ this.foundation.handleRatioChange();
100013
+ }
100014
+ if ("rotation" in this.props && this.props.rotation !== prevProps.rotation) {
100015
+ this.onWindowResize();
100016
+ }
99992
100017
  }
99993
100018
  }
99994
100019
  render() {
@@ -100010,21 +100035,20 @@ class PreviewImage extends BaseComponent {
100010
100035
  transform: `rotate(${-rotation}deg)`,
100011
100036
  top,
100012
100037
  left,
100013
- width: loading ? "auto" : `${width}px`,
100014
- height: loading ? "auto" : `${height}px`
100038
+ width,
100039
+ height
100015
100040
  };
100016
100041
  return /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createElement("div", {
100017
100042
  className: `${preViewImgPrefixCls}`,
100018
100043
  ref: this.containerRef
100019
100044
  }, /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createElement("img", {
100020
- ref: this.registryImageRef,
100045
+ ref: this.imageRef,
100021
100046
  src: src,
100022
100047
  alt: "previewImag",
100023
100048
  className: `${preViewImgPrefixCls}-img`,
100024
100049
  key: src,
100025
100050
  onMouseMove: this.handleMoveImage,
100026
100051
  onMouseDown: this.onImageMouseDown,
100027
- onMouseUp: this.onImageMouseUp,
100028
100052
  onContextMenu: this.handleRightClickImage,
100029
100053
  onDragStart: e => e.preventDefault(),
100030
100054
  onLoad: this.handleLoad,
@@ -100041,9 +100065,9 @@ PreviewImage.propTypes = {
100041
100065
  src: (prop_types_default()).string,
100042
100066
  rotation: (prop_types_default()).number,
100043
100067
  style: (prop_types_default()).object,
100044
- maxZoom: (prop_types_default()).number,
100045
- minZoom: (prop_types_default()).number,
100046
- zoomStep: (prop_types_default()).number,
100068
+ // maxZoom: PropTypes.number,
100069
+ // minZoom: PropTypes.number,
100070
+ // zoomStep: PropTypes.number,
100047
100071
  zoom: (prop_types_default()).number,
100048
100072
  ratio: (prop_types_default()).string,
100049
100073
  disableDownload: (prop_types_default()).bool,
@@ -100054,9 +100078,9 @@ PreviewImage.propTypes = {
100054
100078
  onError: (prop_types_default()).func
100055
100079
  };
100056
100080
  PreviewImage.defaultProps = {
100057
- maxZoom: 5,
100058
- minZoom: 0.1,
100059
- zoomStep: 0.1,
100081
+ // maxZoom: 5,
100082
+ // minZoom: 0.1,
100083
+ // zoomStep: 0.1,
100060
100084
  zoom: undefined
100061
100085
  };
100062
100086
  ;// CONCATENATED MODULE: ../semi-foundation/image/utils.ts
@@ -100151,40 +100175,93 @@ const getPreloadImagArr = (imgSrc, currentIndex, preLoadGap, infinite) => {
100151
100175
 
100152
100176
 
100153
100177
 
100178
+
100179
+
100180
+
100154
100181
  const NOT_CLOSE_TARGETS = ["icon", "footer"];
100155
- const STOP_CLOSE_TARGET = ["icon", "footer", "header"];
100182
+ const STOP_CLOSE_TARGET = (/* unused pure expression or super */ null && (["icon", "footer", "header"]));
100156
100183
  class PreviewInnerFoundation extends foundation {
100157
100184
  constructor(adapter) {
100185
+ var _this;
100158
100186
  super(Object.assign({}, adapter));
100187
+ _this = this;
100188
+ this._timer = null;
100189
+ this._startMouseDown = {
100190
+ x: 0,
100191
+ y: 0
100192
+ };
100159
100193
  this.handleViewVisibleChange = () => {
100160
- const nowTime = new Date().getTime();
100161
- const mouseActiveTime = this._adapter.getMouseActiveTime();
100162
- const stopTiming = this._adapter.getStopTiming();
100163
- const {
100164
- viewerVisibleDelay
100165
- } = this.getProps();
100166
100194
  const {
100167
100195
  viewerVisible
100168
100196
  } = this.getStates();
100169
- if (nowTime - mouseActiveTime > viewerVisibleDelay && !stopTiming) {
100170
- viewerVisible && this.setState({
100197
+ if (viewerVisible) {
100198
+ this.setState({
100171
100199
  viewerVisible: false
100172
100200
  });
100201
+ this.clearTimer();
100173
100202
  }
100174
100203
  };
100175
- this.handleMouseMoveEvent = (e, event) => {
100176
- const isTarget = isTargetEmit(e, STOP_CLOSE_TARGET);
100177
- if (isTarget && event === "over") {
100178
- this._adapter.setStopTiming(true);
100179
- } else if (isTarget && event === "out") {
100180
- this._adapter.setStopTiming(false);
100204
+ this.handleMouseMove = e => {
100205
+ this._persistEvent(e);
100206
+ this.mouseMoveHandler(e);
100207
+ };
100208
+ this.mouseMoveHandler = throttle_default()(e => {
100209
+ const {
100210
+ viewerVisible
100211
+ } = this.getStates();
100212
+ const isValidTarget = this._adapter.isValidTarget(e);
100213
+ if (isValidTarget) {
100214
+ if (!viewerVisible) {
100215
+ this.setState({
100216
+ viewerVisible: true
100217
+ });
100218
+ }
100219
+ this.updateTimer();
100220
+ } else {
100221
+ this.clearTimer();
100181
100222
  }
100223
+ }, 50);
100224
+ this.updateTimer = () => {
100225
+ const {
100226
+ viewerVisibleDelay
100227
+ } = this.getProps();
100228
+ this.clearTimer();
100229
+ this._timer = setTimeout(this.handleViewVisibleChange, viewerVisibleDelay);
100182
100230
  };
100183
- this.handleMouseMove = e => {
100184
- this._adapter.setMouseActiveTime(new Date().getTime());
100185
- this.setState({
100186
- viewerVisible: true
100187
- });
100231
+ this.clearTimer = () => {
100232
+ if (this._timer) {
100233
+ clearTimeout(this._timer);
100234
+ this._timer = null;
100235
+ }
100236
+ };
100237
+ this.handleWheel = e => {
100238
+ this.onWheel(e);
100239
+ handlePrevent(e);
100240
+ };
100241
+ this.onWheel = e => {
100242
+ const {
100243
+ zoomStep,
100244
+ maxZoom,
100245
+ minZoom
100246
+ } = this.getProps();
100247
+ const {
100248
+ zoom: currZoom
100249
+ } = this.getStates();
100250
+ let _zoom;
100251
+ if (e.deltaY < 0) {
100252
+ /* zoom in */
100253
+ if (currZoom + zoomStep <= maxZoom) {
100254
+ _zoom = Number((currZoom + zoomStep).toFixed(2));
100255
+ }
100256
+ } else if (e.deltaY > 0) {
100257
+ /* zoom out */
100258
+ if (currZoom - zoomStep >= minZoom) {
100259
+ _zoom = Number((currZoom - zoomStep).toFixed(2));
100260
+ }
100261
+ }
100262
+ if (!isUndefined_default()(_zoom)) {
100263
+ this.handleZoomImage(_zoom);
100264
+ }
100188
100265
  };
100189
100266
  this.handleMouseUp = e => {
100190
100267
  const {
@@ -100198,7 +100275,7 @@ class PreviewInnerFoundation extends foundation {
100198
100275
  const {
100199
100276
  x,
100200
100277
  y
100201
- } = this._adapter.getStartMouseDown();
100278
+ } = this._startMouseDown;
100202
100279
  // 对鼠标移动做容错处理,当 x 和 y 方向在 mouseUp 的时候移动距离都小于等于 5px 时候就可以关闭预览
100203
100280
  // Error-tolerant processing of mouse movement, when the movement distance in the x and y directions is less than or equal to 5px in mouseUp, the preview can be closed
100204
100281
  // 不做容错处理的话,直接用 clientX !== x || y !== clientY 做判断,鼠标在用户点击时候无意识的轻微移动无法关闭预览,不符合用户预期
@@ -100215,7 +100292,10 @@ class PreviewInnerFoundation extends foundation {
100215
100292
  clientX,
100216
100293
  clientY
100217
100294
  } = e;
100218
- this._adapter.setStartMouseDown(clientX, clientY);
100295
+ this._startMouseDown = {
100296
+ x: clientX,
100297
+ y: clientY
100298
+ };
100219
100299
  };
100220
100300
  this.handleKeyDown = e => {
100221
100301
  const {
@@ -100251,7 +100331,6 @@ class PreviewInnerFoundation extends foundation {
100251
100331
  direction,
100252
100332
  rotation: 0
100253
100333
  });
100254
- this._adapter.notifyRotateChange(0);
100255
100334
  };
100256
100335
  this.handleDownload = () => {
100257
100336
  const {
@@ -100284,14 +100363,17 @@ class PreviewInnerFoundation extends foundation {
100284
100363
  });
100285
100364
  this._adapter.notifyRotateChange(newRotation);
100286
100365
  };
100287
- this.handleZoomImage = newZoom => {
100366
+ this.handleZoomImage = function (newZoom) {
100367
+ let notify = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
100288
100368
  const {
100289
100369
  zoom
100290
- } = this.getStates();
100291
- this._adapter.notifyZoom(newZoom, newZoom > zoom);
100292
- this.setState({
100293
- zoom: newZoom
100294
- });
100370
+ } = _this.getStates();
100371
+ if (zoom !== newZoom) {
100372
+ notify && _this._adapter.notifyZoom(newZoom, newZoom > zoom);
100373
+ _this.setState({
100374
+ zoom: newZoom
100375
+ });
100376
+ }
100295
100377
  };
100296
100378
  // 当 visible 改变之后,预览组件完成首张图片加载后,启动预加载
100297
100379
  // 如: 1,2,3,4,5,6,7,8张图片, 点击第 4 张图片,preLoadGap 为 2
@@ -100409,10 +100491,12 @@ class PreviewInnerFoundation extends foundation {
100409
100491
  beforeShow() {
100410
100492
  this._adapter.registerKeyDownListener();
100411
100493
  this._adapter.disabledBodyScroll();
100494
+ this.updateTimer();
100412
100495
  }
100413
100496
  afterHide() {
100414
100497
  this._adapter.unregisterKeyDownListener();
100415
100498
  this._adapter.enabledBodyScroll();
100499
+ this.clearTimer();
100416
100500
  }
100417
100501
  }
100418
100502
  ;// CONCATENATED MODULE: ./image/previewInner.tsx
@@ -100432,14 +100516,6 @@ class PreviewInnerFoundation extends foundation {
100432
100516
 
100433
100517
 
100434
100518
  const previewInner_prefixCls = image_constants_cssClasses.PREFIX;
100435
- let startMouseDown = {
100436
- x: 0,
100437
- y: 0
100438
- };
100439
- let previewInner_mouseActiveTime = null;
100440
- let stopTiming = false;
100441
- let timer = null;
100442
- // let bodyOverflowValue = document.body.style.overflow;
100443
100519
  class PreviewInner extends BaseComponent {
100444
100520
  get adapter() {
100445
100521
  return Object.assign(Object.assign({}, super.adapter), {
@@ -100523,35 +100599,29 @@ class PreviewInner extends BaseComponent {
100523
100599
  unregisterKeyDownListener: () => {
100524
100600
  window && window.removeEventListener("keydown", this.handleKeyDown);
100525
100601
  },
100526
- getMouseActiveTime: () => {
100527
- return previewInner_mouseActiveTime;
100528
- },
100529
- getStopTiming: () => {
100530
- return stopTiming;
100531
- },
100532
- setStopTiming: value => {
100533
- stopTiming = value;
100534
- },
100535
- getStartMouseDown: () => {
100536
- return startMouseDown;
100537
- },
100538
- setStartMouseDown: (x, y) => {
100539
- startMouseDown = {
100540
- x,
100541
- y
100542
- };
100543
- },
100544
- setMouseActiveTime: time => {
100545
- previewInner_mouseActiveTime = time;
100546
- },
100547
100602
  getSetDownloadFunc: () => {
100548
100603
  var _a, _b;
100549
100604
  return (_b = (_a = this.context) === null || _a === void 0 ? void 0 : _a.setDownloadName) !== null && _b !== void 0 ? _b : this.props.setDownloadName;
100605
+ },
100606
+ isValidTarget: e => {
100607
+ const headerDom = this.headerRef && this.headerRef.current;
100608
+ const footerDom = this.footerRef && this.footerRef.current;
100609
+ const leftIconDom = this.leftIconRef && this.leftIconRef.current;
100610
+ const rightIconDom = this.rightIconRef && this.rightIconRef.current;
100611
+ const target = e.target;
100612
+ if (headerDom && headerDom.contains(target) || footerDom && footerDom.contains(target) || leftIconDom && leftIconDom.contains(target) || rightIconDom && rightIconDom.contains(target)) {
100613
+ // Move in the operation area, return false
100614
+ return false;
100615
+ }
100616
+ // Move in the preview area except the operation area, return true
100617
+ return true;
100550
100618
  }
100551
100619
  });
100552
100620
  }
100553
100621
  constructor(props) {
100622
+ var _this;
100554
100623
  super(props);
100624
+ _this = this;
100555
100625
  this.viewVisibleChange = () => {
100556
100626
  this.foundation.handleViewVisibleChange();
100557
100627
  };
@@ -100570,8 +100640,9 @@ class PreviewInner extends BaseComponent {
100570
100640
  this.handleRotateImage = direction => {
100571
100641
  this.foundation.handleRotateImage(direction);
100572
100642
  };
100573
- this.handleZoomImage = newZoom => {
100574
- this.foundation.handleZoomImage(newZoom);
100643
+ this.handleZoomImage = function (newZoom) {
100644
+ let notify = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
100645
+ _this.foundation.handleZoomImage(newZoom, notify);
100575
100646
  };
100576
100647
  this.handleMouseUp = e => {
100577
100648
  this.foundation.handleMouseUp(e.nativeEvent);
@@ -100579,9 +100650,6 @@ class PreviewInner extends BaseComponent {
100579
100650
  this.handleMouseMove = e => {
100580
100651
  this.foundation.handleMouseMove(e);
100581
100652
  };
100582
- this.handleMouseEvent = (e, event) => {
100583
- this.foundation.handleMouseMoveEvent(e, event);
100584
- };
100585
100653
  this.handleKeyDown = e => {
100586
100654
  this.foundation.handleKeyDown(e);
100587
100655
  };
@@ -100594,6 +100662,31 @@ class PreviewInner extends BaseComponent {
100594
100662
  this.handleMouseDown = e => {
100595
100663
  this.foundation.handleMouseDown(e);
100596
100664
  };
100665
+ this.handleWheel = e => {
100666
+ this.foundation.handleWheel(e);
100667
+ };
100668
+ // 为什么通过 addEventListener 注册 wheel 事件而不是使用 onWheel 事件?
100669
+ // 因为 Passive Event Listeners(https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#improving_scrolling_performance_with_passive_listeners)
100670
+ // Passive Event Listeners 是一种优化技术,用于提高滚动性能。在默认情况下,浏览器会假设事件的监听器不会调用
100671
+ // preventDefault() 方法来阻止事件的默认行为,从而允许进行一些优化操作,例如滚动平滑。
100672
+ // 对于 Image 而言,如果使用触控板,双指朝不同方向分开放大图片,则需要 preventDefault 防止页面整体放大。
100673
+ // Why register wheel event through addEventListener instead of using onWheel event?
100674
+ // Because of Passive Event Listeners(an optimization technique used to improve scrolling performance. By default,
100675
+ // the browser will assume that event listeners will not call preventDefault() method to prevent the default behavior of the event,
100676
+ // allowing some optimization operations such as scroll smoothing.)
100677
+ // For Image, if we use the trackpad and spread your fingers in different directions to enlarge the image, we need to preventDefault
100678
+ // to prevent the page from being enlarged as a whole.
100679
+ this.registryImageWrapRef = ref => {
100680
+ if (this.imageWrapRef) {
100681
+ this.imageWrapRef.removeEventListener("wheel", this.handleWheel);
100682
+ }
100683
+ if (ref) {
100684
+ ref.addEventListener("wheel", this.handleWheel, {
100685
+ passive: false
100686
+ });
100687
+ }
100688
+ this.imageWrapRef = ref;
100689
+ };
100597
100690
  this.state = {
100598
100691
  imgSrc: [],
100599
100692
  imgLoadStatus: new Map(),
@@ -100610,6 +100703,11 @@ class PreviewInner extends BaseComponent {
100610
100703
  this.bodyOverflow = '';
100611
100704
  this.originBodyWidth = '100%';
100612
100705
  this.scrollBarWidth = 0;
100706
+ this.imageWrapRef = null;
100707
+ this.headerRef = /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createRef();
100708
+ this.footerRef = /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createRef();
100709
+ this.leftIconRef = /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createRef();
100710
+ this.rightIconRef = /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createRef();
100613
100711
  }
100614
100712
  static getDerivedStateFromProps(props, state) {
100615
100713
  const willUpdateStates = {};
@@ -100625,6 +100723,9 @@ class PreviewInner extends BaseComponent {
100625
100723
  willUpdateStates.visible = props.visible;
100626
100724
  if (props.visible) {
100627
100725
  willUpdateStates.preloadAfterVisibleChange = true;
100726
+ willUpdateStates.viewerVisible = true;
100727
+ willUpdateStates.rotation = 0;
100728
+ willUpdateStates.ratio = 'adaptation';
100628
100729
  }
100629
100730
  }
100630
100731
  if ("currentIndex" in props && props.currentIndex !== state.currentIndex) {
@@ -100643,10 +100744,8 @@ class PreviewInner extends BaseComponent {
100643
100744
  }
100644
100745
  }
100645
100746
  componentDidUpdate(prevProps, prevState) {
100646
- if (prevState.visible !== this.props.visible && this.props.visible) {
100647
- previewInner_mouseActiveTime = new Date().getTime();
100648
- timer && clearInterval(timer);
100649
- timer = setInterval(this.viewVisibleChange, 1000);
100747
+ if (prevProps.src !== this.props.src) {
100748
+ this.foundation.updateTimer();
100650
100749
  }
100651
100750
  // hide => show
100652
100751
  if (!prevProps.visible && this.props.visible) {
@@ -100658,7 +100757,7 @@ class PreviewInner extends BaseComponent {
100658
100757
  }
100659
100758
  }
100660
100759
  componentWillUnmount() {
100661
- timer && clearInterval(timer);
100760
+ this.foundation.clearTimer();
100662
100761
  }
100663
100762
  isInGroup() {
100664
100763
  return Boolean(this.context && this.context.isGroup);
@@ -100723,10 +100822,10 @@ class PreviewInner extends BaseComponent {
100723
100822
  style: style,
100724
100823
  onMouseDown: this.handleMouseDown,
100725
100824
  onMouseUp: this.handleMouseUp,
100726
- onMouseMove: this.handleMouseMove,
100727
- onMouseOver: e => this.handleMouseEvent(e.nativeEvent, "over"),
100728
- onMouseOut: e => this.handleMouseEvent(e.nativeEvent, "out")
100825
+ ref: this.registryImageWrapRef,
100826
+ onMouseMove: this.handleMouseMove
100729
100827
  }, /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createElement(previewHeader, {
100828
+ ref: this.headerRef,
100730
100829
  className: classnames_default()(hideViewerCls),
100731
100830
  onClose: this.handlePreviewClose,
100732
100831
  renderHeader: renderHeader
@@ -100737,7 +100836,6 @@ class PreviewInner extends BaseComponent {
100737
100836
  setRatio: this.handleAdjustRatio,
100738
100837
  zoom: zoom,
100739
100838
  ratio: ratio,
100740
- zoomStep: zoomStep,
100741
100839
  rotation: rotation,
100742
100840
  crossOrigin: crossOrigin,
100743
100841
  onError: this.onImageError,
@@ -100746,6 +100844,7 @@ class PreviewInner extends BaseComponent {
100746
100844
  /*#__PURE__*/
100747
100845
  // eslint-disable-next-line jsx-a11y/click-events-have-key-events,jsx-a11y/no-static-element-interactions
100748
100846
  external_root_React_commonjs2_react_commonjs_react_amd_react_default().createElement("div", {
100847
+ ref: this.leftIconRef,
100749
100848
  className: classnames_default()(`${previewPrefixCls}-icon`, `${previewPrefixCls}-prev`, hideViewerCls),
100750
100849
  onClick: () => this.handleSwitchImage("prev")
100751
100850
  }, /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createElement(IconArrowLeft, {
@@ -100754,11 +100853,13 @@ class PreviewInner extends BaseComponent {
100754
100853
  /*#__PURE__*/
100755
100854
  // eslint-disable-next-line jsx-a11y/click-events-have-key-events,jsx-a11y/no-static-element-interactions
100756
100855
  external_root_React_commonjs2_react_commonjs_react_amd_react_default().createElement("div", {
100856
+ ref: this.rightIconRef,
100757
100857
  className: classnames_default()(`${previewPrefixCls}-icon`, `${previewPrefixCls}-next`, hideViewerCls),
100758
100858
  onClick: () => this.handleSwitchImage("next")
100759
100859
  }, /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createElement(IconArrowRight, {
100760
100860
  size: "large"
100761
100861
  })), /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createElement(previewFooter_Footer, {
100862
+ forwardRef: this.footerRef,
100762
100863
  className: hideViewerCls,
100763
100864
  totalNum: total,
100764
100865
  curPage: currentIndex + 1,
@@ -100816,6 +100917,8 @@ PreviewInner.propTypes = {
100816
100917
  disableDownload: (prop_types_default()).bool,
100817
100918
  viewerVisibleDelay: (prop_types_default()).number,
100818
100919
  zIndex: (prop_types_default()).number,
100920
+ maxZoom: (prop_types_default()).number,
100921
+ minZoom: (prop_types_default()).number,
100819
100922
  renderHeader: (prop_types_default()).func,
100820
100923
  renderPreviewMenu: (prop_types_default()).func,
100821
100924
  getPopupContainer: (prop_types_default()).func,
@@ -100840,7 +100943,9 @@ PreviewInner.defaultProps = {
100840
100943
  preLoadGap: 2,
100841
100944
  zIndex: 1000,
100842
100945
  maskClosable: true,
100843
- viewerVisibleDelay: 10000
100946
+ viewerVisibleDelay: 10000,
100947
+ maxZoom: 5,
100948
+ minZoom: 0.1
100844
100949
  };
100845
100950
  ;// CONCATENATED MODULE: ../semi-foundation/image/imageFoundation.ts
100846
100951
 
@@ -101484,6 +101589,8 @@ Preview.defaultProps = {
101484
101589
 
101485
101590
 
101486
101591
 
101592
+
101593
+
101487
101594
 
101488
101595
 
101489
101596