@douyinfe/semi-foundation 2.70.0-alpha.2 → 2.70.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.
- package/chat/foundation.ts +17 -2
- package/datePicker/yearAndMonthFoundation.ts +29 -9
- package/lib/cjs/chat/foundation.d.ts +4 -0
- package/lib/cjs/chat/foundation.js +12 -1
- package/lib/cjs/datePicker/yearAndMonthFoundation.js +39 -8
- package/lib/cjs/markdownRender/foundation.d.ts +1 -0
- package/lib/cjs/markdownRender/foundation.js +9 -4
- package/lib/cjs/overflowList/constants.d.ts +1 -1
- package/lib/cjs/resizable/foundation.d.ts +2 -4
- package/lib/cjs/resizable/group/index.d.ts +6 -3
- package/lib/cjs/resizable/group/index.js +90 -23
- package/lib/cjs/resizable/resizable.css +86 -0
- package/lib/cjs/resizable/resizable.scss +100 -3
- package/lib/cjs/resizable/single/index.d.ts +1 -1
- package/lib/cjs/resizable/single/index.js +2 -2
- package/lib/cjs/resizable/types.d.ts +41 -0
- package/lib/cjs/resizable/types.js +12 -0
- package/lib/cjs/resizable/utils.js +5 -5
- package/lib/cjs/resizable/variables.scss +8 -0
- package/lib/cjs/table/table.css +2 -1
- package/lib/cjs/table/table.scss +2 -1
- package/lib/cjs/transfer/transfer.css +1 -0
- package/lib/cjs/transfer/transfer.scss +1 -0
- package/lib/cjs/tree/treeUtil.d.ts +1 -1
- package/lib/cjs/treeSelect/treeSelect.css +3 -1
- package/lib/cjs/treeSelect/treeSelect.scss +4 -1
- package/lib/es/chat/foundation.d.ts +4 -0
- package/lib/es/chat/foundation.js +12 -1
- package/lib/es/datePicker/yearAndMonthFoundation.js +39 -8
- package/lib/es/markdownRender/foundation.d.ts +1 -0
- package/lib/es/markdownRender/foundation.js +9 -4
- package/lib/es/overflowList/constants.d.ts +1 -1
- package/lib/es/resizable/foundation.d.ts +2 -4
- package/lib/es/resizable/foundation.js +2 -4
- package/lib/es/resizable/group/index.d.ts +6 -3
- package/lib/es/resizable/group/index.js +90 -23
- package/lib/es/resizable/resizable.css +86 -0
- package/lib/es/resizable/resizable.scss +100 -3
- package/lib/es/resizable/single/index.d.ts +1 -1
- package/lib/es/resizable/single/index.js +1 -1
- package/lib/es/resizable/types.d.ts +41 -0
- package/lib/es/resizable/types.js +6 -0
- package/lib/es/resizable/utils.js +5 -5
- package/lib/es/resizable/variables.scss +8 -0
- package/lib/es/table/table.css +2 -1
- package/lib/es/table/table.scss +2 -1
- package/lib/es/transfer/transfer.css +1 -0
- package/lib/es/transfer/transfer.scss +1 -0
- package/lib/es/tree/treeUtil.d.ts +1 -1
- package/lib/es/treeSelect/treeSelect.css +3 -1
- package/lib/es/treeSelect/treeSelect.scss +4 -1
- package/markdownRender/foundation.ts +13 -7
- package/package.json +3 -5
- package/resizable/foundation.ts +3 -19
- package/resizable/group/index.ts +92 -29
- package/resizable/resizable.scss +100 -3
- package/resizable/single/index.ts +1 -1
- package/resizable/{singleConstants.ts → types.ts} +0 -65
- package/resizable/utils.ts +7 -6
- package/resizable/variables.scss +8 -0
- package/table/table.scss +2 -1
- package/transfer/transfer.scss +1 -0
- package/treeSelect/treeSelect.scss +4 -1
- package/tsconfig.json +1 -1
- package/jsonViewer/constants.ts +0 -7
- package/jsonViewer/foundation.ts +0 -67
- package/jsonViewer/jsonViewer.scss +0 -152
- package/jsonViewer/script/build.js +0 -51
- package/jsonViewer/variables.scss +0 -27
- package/lib/cjs/jsonViewer/constants.d.ts +0 -4
- package/lib/cjs/jsonViewer/constants.js +0 -10
- package/lib/cjs/jsonViewer/foundation.d.ts +0 -21
- package/lib/cjs/jsonViewer/foundation.js +0 -78
- package/lib/cjs/jsonViewer/jsonViewer.css +0 -136
- package/lib/cjs/jsonViewer/jsonViewer.scss +0 -152
- package/lib/cjs/jsonViewer/variables.scss +0 -27
- package/lib/cjs/resizable/groupConstants.d.ts +0 -16
- package/lib/cjs/resizable/groupConstants.js +0 -25
- package/lib/cjs/resizable/singleConstants.d.ts +0 -105
- package/lib/cjs/resizable/singleConstants.js +0 -67
- package/lib/es/jsonViewer/constants.d.ts +0 -4
- package/lib/es/jsonViewer/constants.js +0 -5
- package/lib/es/jsonViewer/foundation.d.ts +0 -21
- package/lib/es/jsonViewer/foundation.js +0 -60
- package/lib/es/jsonViewer/jsonViewer.css +0 -136
- package/lib/es/jsonViewer/jsonViewer.scss +0 -152
- package/lib/es/jsonViewer/variables.scss +0 -27
- package/lib/es/resizable/groupConstants.d.ts +0 -16
- package/lib/es/resizable/groupConstants.js +0 -19
- package/lib/es/resizable/singleConstants.d.ts +0 -105
- package/lib/es/resizable/singleConstants.js +0 -61
- package/resizable/groupConstants.ts +0 -25
package/chat/foundation.ts
CHANGED
|
@@ -53,7 +53,9 @@ export interface ChatAdapter<P = Record<string, any>, S = Record<string, any>> e
|
|
|
53
53
|
notifyHintClick: (hint: string) => void;
|
|
54
54
|
setUploadAreaVisible: (visible: boolean) => void;
|
|
55
55
|
manualUpload: (e: any) => void;
|
|
56
|
-
getDropAreaElement: () => HTMLDivElement
|
|
56
|
+
getDropAreaElement: () => HTMLDivElement;
|
|
57
|
+
getDragStatus: () => boolean;
|
|
58
|
+
setDragStatus: (status: boolean) => void
|
|
57
59
|
}
|
|
58
60
|
|
|
59
61
|
|
|
@@ -265,7 +267,19 @@ export default class ChatFoundation <P = Record<string, any>, S = Record<string,
|
|
|
265
267
|
}
|
|
266
268
|
|
|
267
269
|
handleDragOver = (e: any) => {
|
|
270
|
+
const dragStatus = this._adapter.getDragStatus();
|
|
271
|
+
if (dragStatus) {
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
268
274
|
this._adapter.setUploadAreaVisible(true);
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
handleDragStart = (e: any) => {
|
|
278
|
+
this._adapter.setDragStatus(true);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
handleDragEnd = (e: any) => {
|
|
282
|
+
this._adapter.setDragStatus(false);
|
|
269
283
|
}
|
|
270
284
|
|
|
271
285
|
handleContainerDragOver = (e: any) => {
|
|
@@ -285,7 +299,8 @@ export default class ChatFoundation <P = Record<string, any>, S = Record<string,
|
|
|
285
299
|
// 鼠标移动至 container 的子元素,则不做任何操作
|
|
286
300
|
// If the mouse moves to the child element of container, no operation will be performed.
|
|
287
301
|
const dropAreaElement = this._adapter.getDropAreaElement();
|
|
288
|
-
|
|
302
|
+
const enterTarget = e.relatedTarget;
|
|
303
|
+
if (dropAreaElement.contains(enterTarget)) {
|
|
289
304
|
return;
|
|
290
305
|
}
|
|
291
306
|
/**
|
|
@@ -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
|
-
//
|
|
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
|
|
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
|
-
|
|
136
|
-
month
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
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() {
|
|
@@ -46,6 +46,8 @@ export interface ChatAdapter<P = Record<string, any>, S = Record<string, any>> e
|
|
|
46
46
|
setUploadAreaVisible: (visible: boolean) => void;
|
|
47
47
|
manualUpload: (e: any) => void;
|
|
48
48
|
getDropAreaElement: () => HTMLDivElement;
|
|
49
|
+
getDragStatus: () => boolean;
|
|
50
|
+
setDragStatus: (status: boolean) => void;
|
|
49
51
|
}
|
|
50
52
|
export default class ChatFoundation<P = Record<string, any>, S = Record<string, any>> extends BaseFoundation<ChatAdapter<P, S>, P, S> {
|
|
51
53
|
animation: any;
|
|
@@ -69,6 +71,8 @@ export default class ChatFoundation<P = Record<string, any>, S = Record<string,
|
|
|
69
71
|
dislikeMessage: (message: Message) => void;
|
|
70
72
|
resetMessage: (message: Message) => void;
|
|
71
73
|
handleDragOver: (e: any) => void;
|
|
74
|
+
handleDragStart: (e: any) => void;
|
|
75
|
+
handleDragEnd: (e: any) => void;
|
|
72
76
|
handleContainerDragOver: (e: any) => void;
|
|
73
77
|
handleContainerDrop: (e: any) => void;
|
|
74
78
|
handleContainerDragLeave: (e: any) => void;
|
|
@@ -235,8 +235,18 @@ class ChatFoundation extends _foundation.default {
|
|
|
235
235
|
onMessageReset === null || onMessageReset === void 0 ? void 0 : onMessageReset(message);
|
|
236
236
|
};
|
|
237
237
|
this.handleDragOver = e => {
|
|
238
|
+
const dragStatus = this._adapter.getDragStatus();
|
|
239
|
+
if (dragStatus) {
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
238
242
|
this._adapter.setUploadAreaVisible(true);
|
|
239
243
|
};
|
|
244
|
+
this.handleDragStart = e => {
|
|
245
|
+
this._adapter.setDragStatus(true);
|
|
246
|
+
};
|
|
247
|
+
this.handleDragEnd = e => {
|
|
248
|
+
this._adapter.setDragStatus(false);
|
|
249
|
+
};
|
|
240
250
|
this.handleContainerDragOver = e => {
|
|
241
251
|
(0, _a11y.handlePrevent)(e);
|
|
242
252
|
};
|
|
@@ -253,7 +263,8 @@ class ChatFoundation extends _foundation.default {
|
|
|
253
263
|
// 鼠标移动至 container 的子元素,则不做任何操作
|
|
254
264
|
// If the mouse moves to the child element of container, no operation will be performed.
|
|
255
265
|
const dropAreaElement = this._adapter.getDropAreaElement();
|
|
256
|
-
|
|
266
|
+
const enterTarget = e.relatedTarget;
|
|
267
|
+
if (dropAreaElement.contains(enterTarget)) {
|
|
257
268
|
return;
|
|
258
269
|
}
|
|
259
270
|
/**
|
|
@@ -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
|
-
//
|
|
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
|
|
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
|
-
|
|
104
|
-
month
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
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();
|
|
@@ -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
|
|
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:
|
|
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:
|
|
52
|
-
rehypePlugins: (
|
|
56
|
+
remarkPlugins: remarkPlugins,
|
|
57
|
+
rehypePlugins: (_c = this.getProp("rehypePlugins")) !== null && _c !== void 0 ? _c : []
|
|
53
58
|
},
|
|
54
59
|
runOptions: {}
|
|
55
60
|
};
|
|
@@ -1,4 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
export {
|
|
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 "../
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
59
|
-
nextItemSize
|
|
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.
|
|
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),
|
|
113
|
-
nextFlag = (0, _utils.judgeConstraint)(nextNewSize, this._adapter.getItemMin(curHandler + 1), this._adapter.getItemMax(curHandler + 1),
|
|
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),
|
|
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),
|
|
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 =
|
|
124
|
-
nextItem.style.width =
|
|
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 =
|
|
127
|
-
nextItem.style.height =
|
|
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.
|
|
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
|
|
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,
|
|
202
|
-
maxSizePercent = maxSize ? (0, _utils.getPixelSize)(maxSize,
|
|
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)) /
|
|
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(${
|
|
262
|
+
child.style.width = `calc(${percent}% - ${this.itemMinusMap.get(key)}px)`;
|
|
251
263
|
} else {
|
|
252
|
-
child.style.height = `calc(${
|
|
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.
|
|
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
|
}
|