@douyinfe/semi-foundation 2.70.0-alpha.2 → 2.70.0-beta.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 (82) hide show
  1. package/datePicker/yearAndMonthFoundation.ts +29 -9
  2. package/lib/cjs/datePicker/yearAndMonthFoundation.js +39 -8
  3. package/lib/cjs/markdownRender/foundation.d.ts +1 -0
  4. package/lib/cjs/markdownRender/foundation.js +9 -4
  5. package/lib/cjs/overflowList/constants.d.ts +1 -1
  6. package/lib/cjs/resizable/foundation.d.ts +2 -4
  7. package/lib/cjs/resizable/group/index.d.ts +6 -3
  8. package/lib/cjs/resizable/group/index.js +90 -23
  9. package/lib/cjs/resizable/resizable.css +86 -0
  10. package/lib/cjs/resizable/resizable.scss +100 -3
  11. package/lib/cjs/resizable/single/index.d.ts +1 -1
  12. package/lib/cjs/resizable/single/index.js +2 -2
  13. package/lib/cjs/resizable/types.d.ts +41 -0
  14. package/lib/cjs/resizable/types.js +12 -0
  15. package/lib/cjs/resizable/utils.js +5 -5
  16. package/lib/cjs/resizable/variables.scss +8 -0
  17. package/lib/cjs/transfer/transfer.css +1 -0
  18. package/lib/cjs/transfer/transfer.scss +1 -0
  19. package/lib/cjs/tree/treeUtil.d.ts +1 -1
  20. package/lib/cjs/treeSelect/treeSelect.css +3 -1
  21. package/lib/cjs/treeSelect/treeSelect.scss +4 -1
  22. package/lib/es/datePicker/yearAndMonthFoundation.js +39 -8
  23. package/lib/es/markdownRender/foundation.d.ts +1 -0
  24. package/lib/es/markdownRender/foundation.js +9 -4
  25. package/lib/es/overflowList/constants.d.ts +1 -1
  26. package/lib/es/resizable/foundation.d.ts +2 -4
  27. package/lib/es/resizable/foundation.js +2 -4
  28. package/lib/es/resizable/group/index.d.ts +6 -3
  29. package/lib/es/resizable/group/index.js +90 -23
  30. package/lib/es/resizable/resizable.css +86 -0
  31. package/lib/es/resizable/resizable.scss +100 -3
  32. package/lib/es/resizable/single/index.d.ts +1 -1
  33. package/lib/es/resizable/single/index.js +1 -1
  34. package/lib/es/resizable/types.d.ts +41 -0
  35. package/lib/es/resizable/types.js +6 -0
  36. package/lib/es/resizable/utils.js +5 -5
  37. package/lib/es/resizable/variables.scss +8 -0
  38. package/lib/es/transfer/transfer.css +1 -0
  39. package/lib/es/transfer/transfer.scss +1 -0
  40. package/lib/es/tree/treeUtil.d.ts +1 -1
  41. package/lib/es/treeSelect/treeSelect.css +3 -1
  42. package/lib/es/treeSelect/treeSelect.scss +4 -1
  43. package/markdownRender/foundation.ts +13 -7
  44. package/package.json +3 -5
  45. package/resizable/foundation.ts +3 -19
  46. package/resizable/group/index.ts +92 -29
  47. package/resizable/resizable.scss +100 -3
  48. package/resizable/single/index.ts +1 -1
  49. package/resizable/{singleConstants.ts → types.ts} +0 -65
  50. package/resizable/utils.ts +7 -6
  51. package/resizable/variables.scss +8 -0
  52. package/transfer/transfer.scss +1 -0
  53. package/treeSelect/treeSelect.scss +4 -1
  54. package/tsconfig.json +1 -1
  55. package/jsonViewer/constants.ts +0 -7
  56. package/jsonViewer/foundation.ts +0 -67
  57. package/jsonViewer/jsonViewer.scss +0 -152
  58. package/jsonViewer/script/build.js +0 -51
  59. package/jsonViewer/variables.scss +0 -27
  60. package/lib/cjs/jsonViewer/constants.d.ts +0 -4
  61. package/lib/cjs/jsonViewer/constants.js +0 -10
  62. package/lib/cjs/jsonViewer/foundation.d.ts +0 -21
  63. package/lib/cjs/jsonViewer/foundation.js +0 -78
  64. package/lib/cjs/jsonViewer/jsonViewer.css +0 -136
  65. package/lib/cjs/jsonViewer/jsonViewer.scss +0 -152
  66. package/lib/cjs/jsonViewer/variables.scss +0 -27
  67. package/lib/cjs/resizable/groupConstants.d.ts +0 -16
  68. package/lib/cjs/resizable/groupConstants.js +0 -25
  69. package/lib/cjs/resizable/singleConstants.d.ts +0 -105
  70. package/lib/cjs/resizable/singleConstants.js +0 -67
  71. package/lib/es/jsonViewer/constants.d.ts +0 -4
  72. package/lib/es/jsonViewer/constants.js +0 -5
  73. package/lib/es/jsonViewer/foundation.d.ts +0 -21
  74. package/lib/es/jsonViewer/foundation.js +0 -60
  75. package/lib/es/jsonViewer/jsonViewer.css +0 -136
  76. package/lib/es/jsonViewer/jsonViewer.scss +0 -152
  77. package/lib/es/jsonViewer/variables.scss +0 -27
  78. package/lib/es/resizable/groupConstants.d.ts +0 -16
  79. package/lib/es/resizable/groupConstants.js +0 -19
  80. package/lib/es/resizable/singleConstants.d.ts +0 -105
  81. package/lib/es/resizable/singleConstants.js +0 -61
  82. package/resizable/groupConstants.ts +0 -25
@@ -105,9 +105,9 @@ export default class YearAndMonthFoundation extends BaseFoundation<YearAndMonthA
105
105
  const month = copy(currentMonth);
106
106
  month[panelType] = item.month;
107
107
 
108
- // make sure the right panel time is always less than the left panel time
108
+ // Make sure the time on the right panel is always greater than or equal to the time on the left panel
109
109
  if (type === 'monthRange' && panelType === left && currentYear[left] === currentYear[right] && item.value > month[right]) {
110
- month[right] = item.month + 1;
110
+ month[right] = item.month ;
111
111
  }
112
112
 
113
113
  this._adapter.setCurrentMonth(month);
@@ -121,8 +121,19 @@ export default class YearAndMonthFoundation extends BaseFoundation<YearAndMonthA
121
121
  const { disabledDate, locale } = this._adapter.getProps();
122
122
  const { months, currentMonth } = this._adapter.getStates();
123
123
 
124
+ const oppositeType = panelType === strings.PANEL_TYPE_LEFT ? 'right' : 'left';
125
+
124
126
  const currentDate = setYear(Date.now(), item.year);
125
127
  const isCurrentMonthDisabled = disabledDate(setMonth(currentDate, currentMonth[panelType] - 1));
128
+ // whether the date on the opposite is legal
129
+ const isOppositeMonthDisabled = disabledDate(setMonth(setYear(Date.now(), year[oppositeType]), currentMonth[oppositeType] - 1));
130
+
131
+ if (!isCurrentMonthDisabled && !isOppositeMonthDisabled) {
132
+ // all panel Date is legal
133
+ return;
134
+ }
135
+ let finalYear = year;
136
+ let finalMonth = currentMonth;
126
137
  if (isCurrentMonthDisabled) {
127
138
  const currentIndex = months.findIndex(({ month }) => month === currentMonth[panelType]);
128
139
  let validMonth: typeof months[number];
@@ -131,15 +142,24 @@ export default class YearAndMonthFoundation extends BaseFoundation<YearAndMonthA
131
142
  if (!validMonth) {
132
143
  validMonth = months.slice(0, currentIndex).find(({ month }) => !disabledDate(setMonth(currentDate, month - 1)));
133
144
  }
134
- if (validMonth) {
135
- const month = copy(currentMonth);
136
- month[panelType] = validMonth.month;
137
-
138
- // change year and month same time
139
- this._adapter.setCurrentYearAndMonth(year, month);
140
- this._adapter.notifySelectYearAndMonth(year, month);
145
+ if (validMonth && !isOppositeMonthDisabled) {
146
+ // only currentPanel Date is illegal
147
+ // just need to modify the month of the current panel
148
+ finalMonth[panelType] = validMonth.month;
149
+ } else if (validMonth && isOppositeMonthDisabled) {
150
+ // all panel Date is illegal
151
+ // change the value to the legal value calculated by the current panel
152
+ finalYear = { 'left': item.year, 'right': item.year };
153
+ finalMonth = { 'left': validMonth.month, 'right': validMonth.month };
141
154
  }
155
+ } else if (!isCurrentMonthDisabled && isOppositeMonthDisabled) {
156
+ // only opposite panel Date is illegal
157
+ // change the value to the legal value in the current panel
158
+ finalYear = { 'left': item.year, 'right': item.year };
159
+ finalMonth = { 'left': currentMonth[panelType], 'right': currentMonth[panelType] };
142
160
  }
161
+ this._adapter.setCurrentYearAndMonth(finalYear, finalMonth);
162
+ this._adapter.notifySelectYearAndMonth(finalYear, finalMonth);
143
163
  }
144
164
 
145
165
  backToMain() {
@@ -55,9 +55,9 @@ class YearAndMonthFoundation extends _foundation.default {
55
55
  const right = _constants.strings.PANEL_TYPE_RIGHT;
56
56
  const month = (0, _fastCopy.default)(currentMonth);
57
57
  month[panelType] = item.month;
58
- // make sure the right panel time is always less than the left panel time
58
+ // Make sure the time on the right panel is always greater than or equal to the time on the left panel
59
59
  if (type === 'monthRange' && panelType === left && currentYear[left] === currentYear[right] && item.value > month[right]) {
60
- month[right] = item.month + 1;
60
+ month[right] = item.month;
61
61
  }
62
62
  this._adapter.setCurrentMonth(month);
63
63
  this._adapter.notifySelectMonth(month);
@@ -74,8 +74,17 @@ class YearAndMonthFoundation extends _foundation.default {
74
74
  months,
75
75
  currentMonth
76
76
  } = this._adapter.getStates();
77
+ const oppositeType = panelType === _constants.strings.PANEL_TYPE_LEFT ? 'right' : 'left';
77
78
  const currentDate = (0, _dateFns.setYear)(Date.now(), item.year);
78
79
  const isCurrentMonthDisabled = disabledDate((0, _dateFns.setMonth)(currentDate, currentMonth[panelType] - 1));
80
+ // whether the date on the opposite is legal
81
+ const isOppositeMonthDisabled = disabledDate((0, _dateFns.setMonth)((0, _dateFns.setYear)(Date.now(), year[oppositeType]), currentMonth[oppositeType] - 1));
82
+ if (!isCurrentMonthDisabled && !isOppositeMonthDisabled) {
83
+ // all panel Date is legal
84
+ return;
85
+ }
86
+ let finalYear = year;
87
+ let finalMonth = currentMonth;
79
88
  if (isCurrentMonthDisabled) {
80
89
  const currentIndex = months.findIndex(_ref => {
81
90
  let {
@@ -99,14 +108,36 @@ class YearAndMonthFoundation extends _foundation.default {
99
108
  return !disabledDate((0, _dateFns.setMonth)(currentDate, month - 1));
100
109
  });
101
110
  }
102
- if (validMonth) {
103
- const month = (0, _fastCopy.default)(currentMonth);
104
- month[panelType] = validMonth.month;
105
- // change year and month same time
106
- this._adapter.setCurrentYearAndMonth(year, month);
107
- this._adapter.notifySelectYearAndMonth(year, month);
111
+ if (validMonth && !isOppositeMonthDisabled) {
112
+ // only currentPanel Date is illegal
113
+ // just need to modify the month of the current panel
114
+ finalMonth[panelType] = validMonth.month;
115
+ } else if (validMonth && isOppositeMonthDisabled) {
116
+ // all panel Date is illegal
117
+ // change the value to the legal value calculated by the current panel
118
+ finalYear = {
119
+ 'left': item.year,
120
+ 'right': item.year
121
+ };
122
+ finalMonth = {
123
+ 'left': validMonth.month,
124
+ 'right': validMonth.month
125
+ };
108
126
  }
127
+ } else if (!isCurrentMonthDisabled && isOppositeMonthDisabled) {
128
+ // only opposite panel Date is illegal
129
+ // change the value to the legal value in the current panel
130
+ finalYear = {
131
+ 'left': item.year,
132
+ 'right': item.year
133
+ };
134
+ finalMonth = {
135
+ 'left': currentMonth[panelType],
136
+ 'right': currentMonth[panelType]
137
+ };
109
138
  }
139
+ this._adapter.setCurrentYearAndMonth(finalYear, finalMonth);
140
+ this._adapter.notifySelectYearAndMonth(finalYear, finalMonth);
110
141
  }
111
142
  backToMain() {
112
143
  this._adapter.notifyBackToMain();
@@ -10,6 +10,7 @@ export interface MarkdownRenderBaseProps {
10
10
  format: "md" | "mdx";
11
11
  remarkPlugins?: PluggableList;
12
12
  rehypePlugins?: PluggableList;
13
+ remarkGfm?: boolean;
13
14
  }
14
15
  export interface MarkdownRenderBaseState {
15
16
  MDXContentComponent: any;
@@ -39,17 +39,22 @@ class MarkdownRenderFoundation extends _foundation.default {
39
39
  constructor() {
40
40
  super(...arguments);
41
41
  this.getOptions = () => {
42
- var _a, _b, _c, _d;
42
+ var _a, _b, _c;
43
+ const enableRemarkGfm = this._adapter.getProp("remarkGfm");
44
+ const remarkPlugins = [...((_a = this.getProp("remarkPlugins")) !== null && _a !== void 0 ? _a : [])];
45
+ if (enableRemarkGfm) {
46
+ remarkPlugins.unshift(_remarkGfm.default);
47
+ }
43
48
  return {
44
49
  evaluateOptions: {
45
- remarkPlugins: [_remarkGfm.default, ...((_a = this.getProp("remarkPlugins")) !== null && _a !== void 0 ? _a : [])],
50
+ remarkPlugins: remarkPlugins,
46
51
  rehypePlugins: (_b = this.getProp("rehypePlugins")) !== null && _b !== void 0 ? _b : [],
47
52
  format: this.getProp("format")
48
53
  },
49
54
  compileOptions: {
50
55
  format: this.getProp("format"),
51
- remarkPlugins: [_remarkGfm.default, ...((_c = this.getProp("remarkPlugins")) !== null && _c !== void 0 ? _c : [])],
52
- rehypePlugins: (_d = this.getProp("rehypePlugins")) !== null && _d !== void 0 ? _d : []
56
+ remarkPlugins: remarkPlugins,
57
+ rehypePlugins: (_c = this.getProp("rehypePlugins")) !== null && _c !== void 0 ? _c : []
53
58
  },
54
59
  runOptions: {}
55
60
  };
@@ -2,7 +2,7 @@ declare const cssClasses: {
2
2
  PREFIX: string;
3
3
  };
4
4
  declare const strings: {
5
- BOUNDARY_SET: ("start" | "end")[];
5
+ BOUNDARY_SET: ("end" | "start")[];
6
6
  POSITION_SET: string[];
7
7
  MODE_SET: string[];
8
8
  MODE_MAP: {
@@ -1,4 +1,2 @@
1
- import { ResizableHandlerAdapter, ResizableHandlerFoundation, ResizableFoundation, ResizableAdapter } from './single';
2
- export { ResizableHandlerAdapter, ResizableHandlerFoundation, ResizableFoundation, ResizableAdapter };
3
- import { ResizeGroupAdapter, ResizeItemAdapter, ResizeHandlerAdapter, ResizeGroupFoundation, ResizeItemFoundation, ResizeHandlerFoundation } from './group';
4
- export { ResizeGroupAdapter, ResizeItemAdapter, ResizeHandlerAdapter, ResizeGroupFoundation, ResizeItemFoundation, ResizeHandlerFoundation };
1
+ export { ResizableHandlerAdapter, ResizableHandlerFoundation, ResizableFoundation, ResizableAdapter } from './single';
2
+ export { ResizeGroupAdapter, ResizeItemAdapter, ResizeHandlerAdapter, ResizeGroupFoundation, ResizeItemFoundation, ResizeHandlerFoundation } from './group';
@@ -1,5 +1,6 @@
1
+ /// <reference types="lodash" />
1
2
  import BaseFoundation, { DefaultAdapter } from '../../base/foundation';
2
- import { ResizeStartCallback, ResizeCallback } from "../singleConstants";
3
+ import { ResizeStartCallback, ResizeCallback } from "../types";
3
4
  export interface ResizeHandlerAdapter<P = Record<string, any>, S = Record<string, any>> extends DefaultAdapter<P, S> {
4
5
  registerEvents: () => void;
5
6
  unregisterEvents: () => void;
@@ -34,10 +35,11 @@ export interface ResizeGroupAdapter<P = Record<string, any>, S = Record<string,
34
35
  export declare class ResizeGroupFoundation<P = Record<string, any>, S = Record<string, any>> extends BaseFoundation<ResizeGroupAdapter<P, S>, P, S> {
35
36
  constructor(adapter: ResizeGroupAdapter<P, S>);
36
37
  get groupRef(): HTMLDivElement | null;
38
+ get groupSize(): number;
37
39
  direction: 'horizontal' | 'vertical';
38
40
  itemMinusMap: Map<number, number>;
39
41
  totalMinus: number;
40
- avaliableSize: number;
42
+ itemPercentMap: Map<number, number>;
41
43
  init(): void;
42
44
  get window(): Window | null;
43
45
  registerEvents: () => void;
@@ -45,6 +47,7 @@ export declare class ResizeGroupFoundation<P = Record<string, any>, S = Record<s
45
47
  onResizeStart: (handlerIndex: number, e: MouseEvent) => void;
46
48
  onResizing: (e: MouseEvent) => void;
47
49
  onResizeEnd: (e: MouseEvent) => void;
48
- calculateSpace: () => void;
50
+ initSpace: () => void;
51
+ ensureConstraint: import("lodash").DebouncedFunc<() => void>;
49
52
  destroy(): void;
50
53
  }
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.ResizeItemFoundation = exports.ResizeHandlerFoundation = exports.ResizeGroupFoundation = void 0;
7
+ var _debounce2 = _interopRequireDefault(require("lodash/debounce"));
7
8
  var _utils = require("../utils");
8
9
  var _foundation = _interopRequireDefault(require("../../base/foundation"));
9
10
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
@@ -47,16 +48,18 @@ class ResizeGroupFoundation extends _foundation.default {
47
48
  // offset caused by padding and border
48
49
  const lastStyle = this.window.getComputedStyle(lastItem);
49
50
  const nextStyle = this.window.getComputedStyle(nextItem);
50
- lastOffset = (0, _utils.getOffset)(lastStyle, this.direction);
51
- nextOffset = (0, _utils.getOffset)(nextStyle, this.direction);
51
+ lastOffset = (0, _utils.getOffset)(lastStyle, this.direction) + this.itemMinusMap.get(handlerIndex);
52
+ nextOffset = (0, _utils.getOffset)(nextStyle, this.direction) + this.itemMinusMap.get(handlerIndex + 1);
53
+ let lastItemSize = (this.direction === 'horizontal' ? lastItem.offsetWidth : lastItem.offsetHeight) + this.itemMinusMap.get(handlerIndex),
54
+ nextItemSize = (this.direction === 'horizontal' ? nextItem.offsetWidth : nextItem.offsetHeight) + this.itemMinusMap.get(handlerIndex + 1);
52
55
  const states = this.getStates();
53
56
  this.setState({
54
57
  isResizing: true,
55
58
  originalPosition: {
56
59
  x: clientX,
57
60
  y: clientY,
58
- lastItemSize: this.direction === 'horizontal' ? lastItem.offsetWidth : lastItem.offsetHeight,
59
- nextItemSize: this.direction === 'horizontal' ? nextItem.offsetWidth : nextItem.offsetHeight,
61
+ lastItemSize,
62
+ nextItemSize,
60
63
  lastOffset,
61
64
  nextOffset
62
65
  },
@@ -103,28 +106,33 @@ class ResizeGroupFoundation extends _foundation.default {
103
106
  } = props;
104
107
  let lastItem = this._adapter.getItem(curHandler),
105
108
  nextItem = this._adapter.getItem(curHandler + 1);
106
- let parentSize = this.direction === 'horizontal' ? this.groupRef.offsetWidth : this.groupRef.offsetHeight;
107
- let availableSize = parentSize - this.totalMinus;
109
+ let parentSize = this.groupSize;
108
110
  let delta = direction === 'horizontal' ? clientX - initX : clientY - initY;
109
111
  let lastNewSize = lastItemSize + delta;
110
112
  let nextNewSize = nextItemSize - delta;
111
113
  // 判断是否超出限制
112
- let lastFlag = (0, _utils.judgeConstraint)(lastNewSize, this._adapter.getItemMin(curHandler), this._adapter.getItemMax(curHandler), availableSize, lastOffset),
113
- nextFlag = (0, _utils.judgeConstraint)(nextNewSize, this._adapter.getItemMin(curHandler + 1), this._adapter.getItemMax(curHandler + 1), availableSize, nextOffset);
114
+ let lastFlag = (0, _utils.judgeConstraint)(lastNewSize, this._adapter.getItemMin(curHandler), this._adapter.getItemMax(curHandler), parentSize, lastOffset),
115
+ nextFlag = (0, _utils.judgeConstraint)(nextNewSize, this._adapter.getItemMin(curHandler + 1), this._adapter.getItemMax(curHandler + 1), parentSize, nextOffset);
114
116
  if (lastFlag) {
115
- lastNewSize = (0, _utils.adjustNewSize)(lastNewSize, this._adapter.getItemMin(curHandler), this._adapter.getItemMax(curHandler), availableSize, lastOffset);
117
+ lastNewSize = (0, _utils.adjustNewSize)(lastNewSize, this._adapter.getItemMin(curHandler), this._adapter.getItemMax(curHandler), parentSize, lastOffset);
116
118
  nextNewSize = lastItemSize + nextItemSize - lastNewSize;
117
119
  }
118
120
  if (nextFlag) {
119
- nextNewSize = (0, _utils.adjustNewSize)(nextNewSize, this._adapter.getItemMin(curHandler + 1), this._adapter.getItemMax(curHandler + 1), availableSize, nextOffset);
121
+ nextNewSize = (0, _utils.adjustNewSize)(nextNewSize, this._adapter.getItemMin(curHandler + 1), this._adapter.getItemMax(curHandler + 1), parentSize, nextOffset);
120
122
  lastNewSize = lastItemSize + nextItemSize - nextNewSize;
121
123
  }
124
+ let lastItemPercent = this.itemPercentMap.get(curHandler),
125
+ nextItemPercent = this.itemPercentMap.get(curHandler + 1);
126
+ let lastNewPercent = lastNewSize / parentSize * 100;
127
+ let nextNewPercent = lastItemPercent + nextItemPercent - lastNewPercent; // 消除浮点误差
128
+ this.itemPercentMap.set(curHandler, lastNewPercent);
129
+ this.itemPercentMap.set(curHandler + 1, nextNewPercent);
122
130
  if (direction === 'horizontal') {
123
- lastItem.style.width = lastNewSize / parentSize * 100 + '%';
124
- nextItem.style.width = nextNewSize / parentSize * 100 + '%';
131
+ lastItem.style.width = `calc(${lastNewPercent}% - ${this.itemMinusMap.get(curHandler)}px)`;
132
+ nextItem.style.width = `calc(${nextNewPercent}% - ${this.itemMinusMap.get(curHandler + 1)}px)`;
125
133
  } else if (direction === 'vertical') {
126
- lastItem.style.height = lastNewSize / parentSize * 100 + '%';
127
- nextItem.style.height = nextNewSize / parentSize * 100 + '%';
134
+ lastItem.style.height = `calc(${lastNewPercent}% - ${this.itemMinusMap.get(curHandler)}px)`;
135
+ nextItem.style.height = `calc(${nextNewPercent}% - ${this.itemMinusMap.get(curHandler + 1)}px)`;
128
136
  }
129
137
  let lastFunc = this._adapter.getItemChange(curHandler),
130
138
  nextFunc = this._adapter.getItemChange(curHandler + 1);
@@ -169,14 +177,14 @@ class ResizeGroupFoundation extends _foundation.default {
169
177
  });
170
178
  this.unregisterEvents();
171
179
  };
172
- this.calculateSpace = () => {
180
+ this.initSpace = () => {
173
181
  const props = this.getProps();
174
182
  const {
175
183
  direction
176
184
  } = props;
177
185
  // calculate accurate space for group item
178
186
  let handlerSizes = new Array(this._adapter.getHandlerCount()).fill(0);
179
- let groupSize = direction === 'horizontal' ? this.groupRef.offsetWidth : this.groupRef.offsetHeight;
187
+ let parentSize = this.groupSize;
180
188
  this.totalMinus = 0;
181
189
  for (let i = 0; i < this._adapter.getHandlerCount(); i++) {
182
190
  let handlerSize = direction === 'horizontal' ? this._adapter.getHandler(i).offsetWidth : this._adapter.getHandler(i).offsetHeight;
@@ -198,8 +206,8 @@ class ResizeGroupFoundation extends _foundation.default {
198
206
  const child = this._adapter.getItem(i);
199
207
  let minSize = this._adapter.getItemMin(i),
200
208
  maxSize = this._adapter.getItemMax(i);
201
- let minSizePercent = minSize ? (0, _utils.getPixelSize)(minSize, groupSize) / groupSize * 100 : 0,
202
- maxSizePercent = maxSize ? (0, _utils.getPixelSize)(maxSize, groupSize) / groupSize * 100 : 100;
209
+ let minSizePercent = minSize ? (0, _utils.getPixelSize)(minSize, parentSize) / parentSize * 100 : 0,
210
+ maxSizePercent = maxSize ? (0, _utils.getPixelSize)(maxSize, parentSize) / parentSize * 100 : 100;
203
211
  if (minSizePercent > maxSizePercent) {
204
212
  console.warn('[Semi ResizableItem]: min size bigger than max size');
205
213
  }
@@ -209,15 +217,17 @@ class ResizeGroupFoundation extends _foundation.default {
209
217
  if (typeof defaultSize === 'string') {
210
218
  if (defaultSize.endsWith('%')) {
211
219
  itemSizePercent = parseFloat(defaultSize.slice(0, -1));
220
+ this.itemPercentMap.set(i, itemSizePercent);
212
221
  } else if (defaultSize.endsWith('px')) {
213
- itemSizePercent = parseFloat(defaultSize.slice(0, -2)) / groupSize * 100;
222
+ itemSizePercent = parseFloat(defaultSize.slice(0, -2)) / parentSize * 100;
223
+ this.itemPercentMap.set(i, itemSizePercent);
214
224
  } else if (/^-?\d+(\.\d+)?$/.test(defaultSize)) {
215
225
  // 仅由数字组成,表示按比例分配剩下空间
216
226
  undefineLoc.set(i, parseFloat(defaultSize));
217
227
  undefinedTotal += parseFloat(defaultSize);
218
228
  continue;
219
229
  }
220
- } else {
230
+ } else if (typeof defaultSize === 'number') {
221
231
  undefineLoc.set(i, defaultSize);
222
232
  undefinedTotal += defaultSize;
223
233
  continue;
@@ -246,21 +256,78 @@ class ResizeGroupFoundation extends _foundation.default {
246
256
  }
247
257
  undefineLoc.forEach((value, key) => {
248
258
  const child = this._adapter.getItem(key);
259
+ const percent = value / undefinedTotal * undefineSizePercent;
260
+ this.itemPercentMap.set(key, percent);
249
261
  if (direction === 'horizontal') {
250
- child.style.width = `calc(${undefineSizePercent / undefinedTotal * value}% - ${this.itemMinusMap.get(key)}px)`;
262
+ child.style.width = `calc(${percent}% - ${this.itemMinusMap.get(key)}px)`;
251
263
  } else {
252
- child.style.height = `calc(${undefineSizePercent / undefinedTotal * value}% - ${this.itemMinusMap.get(key)}px)`;
264
+ child.style.height = `calc(${percent}% - ${this.itemMinusMap.get(key)}px)`;
253
265
  }
254
266
  });
255
267
  };
268
+ this.ensureConstraint = (0, _debounce2.default)(() => {
269
+ // 浏览器拖拽时保证px值最大最小仍生效
270
+ const {
271
+ direction
272
+ } = this.getProps();
273
+ const itemCount = this._adapter.getItemCount();
274
+ let continueFlag = true;
275
+ for (let i = 0; i < itemCount; i++) {
276
+ const child = this._adapter.getItem(i);
277
+ const childSize = direction === 'horizontal' ? child.offsetWidth : child.offsetHeight;
278
+ // 判断由非鼠标拖拽导致item的size变化过程中是否有超出限制的情况
279
+ const childFlag = (0, _utils.judgeConstraint)(childSize, this._adapter.getItemMin(i), this._adapter.getItemMax(i), this.groupSize, this.itemMinusMap.get(i));
280
+ if (childFlag) {
281
+ const childNewSize = (0, _utils.adjustNewSize)(childSize, this._adapter.getItemMin(i), this._adapter.getItemMax(i), this.groupSize, this.itemMinusMap.get(i));
282
+ for (let j = i + 1; j < itemCount; j++) {
283
+ // 找到下一个没有超出限制的item
284
+ const item = this._adapter.getItem(j);
285
+ const itemSize = direction === 'horizontal' ? item.offsetWidth : item.offsetHeight;
286
+ const itemFlag = (0, _utils.judgeConstraint)(itemSize, this._adapter.getItemMin(j), this._adapter.getItemMax(j), this.groupSize, this.itemMinusMap.get(j));
287
+ if (!itemFlag) {
288
+ let childPercent = this.itemPercentMap.get(i),
289
+ itemPercent = this.itemPercentMap.get(j);
290
+ let childNewPercent = childNewSize / this.groupSize * 100;
291
+ let itemNewPercent = childPercent + itemPercent - childNewPercent;
292
+ this.itemPercentMap.set(i, childNewPercent);
293
+ this.itemPercentMap.set(j, itemNewPercent);
294
+ if (direction === 'horizontal') {
295
+ child.style.width = `calc(${childNewPercent}% - ${this.itemMinusMap.get(i)}px)`;
296
+ item.style.width = `calc(${itemNewPercent}% - ${this.itemMinusMap.get(j)}px)`;
297
+ } else {
298
+ child.style.height = `calc(${childNewPercent}% - ${this.itemMinusMap.get(i)}px)`;
299
+ item.style.height = `calc(${itemNewPercent}% - ${this.itemMinusMap.get(j)}px)`;
300
+ }
301
+ break;
302
+ } else {
303
+ if (j === itemCount - 1) {
304
+ continueFlag = false;
305
+ console.warn('[Semi ResizableGroup]: no enough space to adjust min/max size');
306
+ }
307
+ }
308
+ }
309
+ }
310
+ if (!continueFlag) {
311
+ break;
312
+ }
313
+ }
314
+ }, 200);
256
315
  }
257
316
  get groupRef() {
258
317
  return this._adapter.getGroupRef();
259
318
  }
319
+ get groupSize() {
320
+ const {
321
+ direction
322
+ } = this.getProps();
323
+ let groupSize = direction === 'horizontal' ? this.groupRef.offsetWidth : this.groupRef.offsetHeight;
324
+ return groupSize;
325
+ }
260
326
  init() {
261
327
  this.direction = this.getProp('direction');
262
328
  this.itemMinusMap = new Map();
263
- this.calculateSpace();
329
+ this.itemPercentMap = new Map();
330
+ this.initSpace();
264
331
  }
265
332
  get window() {
266
333
  var _a;
@@ -11,6 +11,72 @@
11
11
  user-select: none;
12
12
  z-index: 2000;
13
13
  }
14
+ .semi-resizable-resizableHandler-top {
15
+ width: 100%;
16
+ height: 10px;
17
+ top: 0;
18
+ left: 0;
19
+ cursor: row-resize;
20
+ top: -5px;
21
+ }
22
+ .semi-resizable-resizableHandler-right {
23
+ width: 10px;
24
+ height: 100%;
25
+ top: 0;
26
+ left: 0;
27
+ cursor: col-resize;
28
+ left: auto;
29
+ right: -5px;
30
+ }
31
+ .semi-resizable-resizableHandler-bottom {
32
+ width: 100%;
33
+ height: 10px;
34
+ top: 0;
35
+ left: 0;
36
+ cursor: row-resize;
37
+ top: auto;
38
+ bottom: -5px;
39
+ }
40
+ .semi-resizable-resizableHandler-left {
41
+ width: 10px;
42
+ height: 100%;
43
+ top: 0;
44
+ left: 0;
45
+ cursor: col-resize;
46
+ left: -5px;
47
+ }
48
+ .semi-resizable-resizableHandler-topRight {
49
+ width: 20px;
50
+ height: 20px;
51
+ position: absolute;
52
+ right: -10px;
53
+ top: -10px;
54
+ cursor: ne-resize;
55
+ }
56
+ .semi-resizable-resizableHandler-bottomRight {
57
+ width: 20px;
58
+ height: 20px;
59
+ position: absolute;
60
+ right: -10px;
61
+ bottom: -10px;
62
+ cursor: se-resize;
63
+ }
64
+ .semi-resizable-resizableHandler-bottomLeft {
65
+ width: 20px;
66
+ height: 20px;
67
+ position: absolute;
68
+ left: -10px;
69
+ bottom: -10px;
70
+ cursor: sw-resize;
71
+ }
72
+ .semi-resizable-resizableHandler-topLeft {
73
+ width: 20px;
74
+ height: 20px;
75
+ position: absolute;
76
+ left: -10px;
77
+ top: -10px;
78
+ cursor: nw-resize;
79
+ }
14
80
  .semi-resizable-group {
15
81
  display: flex;
16
82
  position: relative;
@@ -31,4 +97,24 @@
31
97
  justify-content: center;
32
98
  background-color: var(--semi-color-fill-0);
33
99
  opacity: 1;
100
+ }
101
+ .semi-resizable-handler-vertical {
102
+ width: 100%;
103
+ height: 10px;
104
+ flex-shrink: 0;
105
+ cursor: row-resize;
106
+ }
107
+ .semi-resizable-handler-horizontal {
108
+ height: 100%;
109
+ width: 10px;
110
+ flex-shrink: 0;
111
+ cursor: col-resize;
112
+ }
113
+ .semi-resizable-background {
114
+ height: 100%;
115
+ width: 100%;
116
+ inset: 0;
117
+ z-index: 2010;
118
+ opacity: 0;
119
+ position: fixed;
34
120
  }
@@ -1,5 +1,4 @@
1
- @import './variables.scss';
2
-
1
+ @import "./variables.scss";
3
2
  $module: #{$prefix}-resizable;
4
3
 
5
4
  .#{$module} {
@@ -13,8 +12,83 @@ $module: #{$prefix}-resizable;
13
12
  position: absolute;
14
13
  user-select: none;
15
14
  z-index: $z-resizable_handler;
15
+
16
+ // 基础样式
17
+ @mixin row-resize-base {
18
+ width: 100%;
19
+ height: $height-row-handler;
20
+ top: 0;
21
+ left: 0;
22
+ cursor: row-resize;
23
+ }
24
+
25
+ @mixin col-resize-base {
26
+ width: $width-col-handler;
27
+ height: 100%;
28
+ top: 0;
29
+ left: 0;
30
+ cursor: col-resize;
31
+ }
32
+
33
+ @mixin edge-resize-base {
34
+ width: $width-edge-handler;
35
+ height: $height-edge-handler;
36
+ position: absolute;
37
+ }
38
+
39
+ // 方向样式
40
+ &-top {
41
+ @include row-resize-base;
42
+ top: calc(-1 * $height-row-handler / 2);
43
+ }
44
+
45
+ &-right {
46
+ @include col-resize-base;
47
+ left: auto;
48
+ right: calc(-1 * $width-col-handler / 2);
49
+ }
50
+
51
+ &-bottom {
52
+ @include row-resize-base;
53
+ top: auto;
54
+ bottom: calc(-1 * $height-row-handler / 2);
55
+ }
56
+
57
+ &-left {
58
+ @include col-resize-base;
59
+ left: calc(-1 * $width-col-handler / 2);
60
+ }
61
+
62
+ // 边角样式
63
+ &-topRight {
64
+ @include edge-resize-base;
65
+ right: calc(-1 * $width-edge-handler / 2);
66
+ top: calc(-1 * $height-edge-handler / 2);
67
+ cursor: ne-resize;
68
+ }
69
+
70
+ &-bottomRight {
71
+ @include edge-resize-base;
72
+ right: calc(-1 * $width-edge-handler / 2);
73
+ bottom: calc(-1 * $height-edge-handler / 2);
74
+ cursor: se-resize;
75
+ }
76
+
77
+ &-bottomLeft {
78
+ @include edge-resize-base;
79
+ left: calc(-1 * $width-edge-handler / 2);
80
+ bottom: calc(-1 * $height-edge-handler / 2);
81
+ cursor: sw-resize;
82
+ }
83
+
84
+ &-topLeft {
85
+ @include edge-resize-base;
86
+ left: calc(-1 * $width-edge-handler / 2);
87
+ top: calc(-1 * $height-edge-handler / 2);
88
+ cursor: nw-resize;
89
+ }
16
90
  }
17
-
91
+
18
92
  &-group {
19
93
  display: flex;
20
94
  position: relative;
@@ -37,5 +111,28 @@ $module: #{$prefix}-resizable;
37
111
  justify-content: center;
38
112
  background-color: var(--semi-color-fill-0);
39
113
  opacity: 1;
114
+
115
+ &-vertical {
116
+ width: 100%;
117
+ height: $height-vertical-handler;
118
+ flex-shrink: 0;
119
+ cursor: row-resize;
120
+ }
121
+
122
+ &-horizontal {
123
+ height: 100%;
124
+ width: $width-horizontal-handler;
125
+ flex-shrink: 0;
126
+ cursor: col-resize;
127
+ }
128
+ }
129
+
130
+ &-background {
131
+ height: 100%;
132
+ width: 100%;
133
+ inset: 0;
134
+ z-index: $z-resizable_background;
135
+ opacity: 0;
136
+ position: fixed;
40
137
  }
41
138
  }
@@ -1,5 +1,5 @@
1
1
  import BaseFoundation, { DefaultAdapter } from '../../base/foundation';
2
- import { Size, NumberSize, Direction } from "../singleConstants";
2
+ import { Size, NumberSize, Direction } from "../types";
3
3
  export interface ResizableHandlerAdapter<P = Record<string, any>, S = Record<string, any>> extends DefaultAdapter<P, S> {
4
4
  registerEvent: () => void;
5
5
  unregisterEvent: () => void;
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.ResizableHandlerFoundation = exports.ResizableFoundation = void 0;
7
7
  var _foundation = _interopRequireDefault(require("../../base/foundation"));
8
- var _singleConstants = require("../singleConstants");
8
+ var _types = require("../types");
9
9
  var _utils = require("../utils");
10
10
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
11
11
  class ResizableHandlerFoundation extends _foundation.default {
@@ -303,7 +303,7 @@ class ResizableFoundation extends _foundation.default {
303
303
  }
304
304
  get propSize() {
305
305
  const porps = this.getProps();
306
- return porps.size || porps.defaultSize || _singleConstants.DEFAULT_SIZE;
306
+ return porps.size || porps.defaultSize || _types.DEFAULT_SIZE;
307
307
  }
308
308
  get size() {
309
309
  let width = 0;