@douyinfe/semi-foundation 2.67.3-alpha.0 → 2.68.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/datePicker/foundation.ts +1 -1
- package/hotKeys/foundation.ts +4 -5
- package/lib/cjs/datePicker/foundation.d.ts +1 -1
- package/lib/cjs/hotKeys/foundation.d.ts +2 -1
- package/lib/cjs/hotKeys/foundation.js +2 -4
- package/lib/cjs/overflowList/constants.d.ts +1 -1
- package/lib/cjs/resizable/constants.d.ts +5 -0
- package/lib/cjs/resizable/constants.js +11 -0
- package/lib/cjs/resizable/foundation.d.ts +4 -0
- package/lib/cjs/resizable/foundation.js +37 -0
- package/lib/cjs/resizable/group/index.d.ts +50 -0
- package/lib/cjs/resizable/group/index.js +271 -0
- package/lib/cjs/resizable/groupConstants.d.ts +16 -0
- package/lib/cjs/resizable/groupConstants.js +25 -0
- package/lib/cjs/resizable/resizable.css +34 -0
- package/lib/cjs/resizable/resizable.scss +39 -0
- package/lib/cjs/resizable/single/index.d.ts +70 -0
- package/lib/cjs/resizable/single/index.js +574 -0
- package/lib/cjs/resizable/singleConstants.d.ts +105 -0
- package/lib/cjs/resizable/singleConstants.js +67 -0
- package/lib/cjs/resizable/utils.d.ts +20 -0
- package/lib/cjs/resizable/utils.js +142 -0
- package/lib/cjs/tree/treeUtil.d.ts +1 -1
- package/lib/es/datePicker/foundation.d.ts +1 -1
- package/lib/es/hotKeys/foundation.d.ts +2 -1
- package/lib/es/hotKeys/foundation.js +2 -4
- package/lib/es/overflowList/constants.d.ts +1 -1
- package/lib/es/resizable/constants.d.ts +5 -0
- package/lib/es/resizable/constants.js +6 -0
- package/lib/es/resizable/foundation.d.ts +4 -0
- package/lib/es/resizable/foundation.js +4 -0
- package/lib/es/resizable/group/index.d.ts +50 -0
- package/lib/es/resizable/group/index.js +262 -0
- package/lib/es/resizable/groupConstants.d.ts +16 -0
- package/lib/es/resizable/groupConstants.js +19 -0
- package/lib/es/resizable/resizable.css +34 -0
- package/lib/es/resizable/resizable.scss +39 -0
- package/lib/es/resizable/single/index.d.ts +70 -0
- package/lib/es/resizable/single/index.js +565 -0
- package/lib/es/resizable/singleConstants.d.ts +105 -0
- package/lib/es/resizable/singleConstants.js +61 -0
- package/lib/es/resizable/utils.d.ts +20 -0
- package/lib/es/resizable/utils.js +124 -0
- package/lib/es/tree/treeUtil.d.ts +1 -1
- package/package.json +3 -3
- package/resizable/constants.ts +13 -0
- package/resizable/foundation.ts +31 -0
- package/resizable/group/index.ts +293 -0
- package/resizable/groupConstants.ts +25 -0
- package/resizable/resizable.scss +39 -0
- package/resizable/single/index.ts +629 -0
- package/resizable/singleConstants.ts +127 -0
- package/resizable/utils.ts +145 -0
package/datePicker/foundation.ts
CHANGED
|
@@ -114,7 +114,7 @@ export interface EventHandlerProps {
|
|
|
114
114
|
onClear?: (e: any) => void;
|
|
115
115
|
onFocus?: (e: any, rangType: RangeType) => void;
|
|
116
116
|
onPresetClick?: OnPresetClickType;
|
|
117
|
-
onClickOutSide?: () => void
|
|
117
|
+
onClickOutSide?: (e: any) => void
|
|
118
118
|
}
|
|
119
119
|
|
|
120
120
|
export interface DatePickerFoundationProps extends ElementProps, RenderProps, EventHandlerProps, Pick<MonthsGridFoundationProps, 'startYear' | 'endYear'> {
|
package/hotKeys/foundation.ts
CHANGED
|
@@ -3,7 +3,8 @@ import { keyToCode, Keys } from './constants';
|
|
|
3
3
|
|
|
4
4
|
export interface HotKeysAdapter<P = Record<string, any>, S = Record<string, any>> extends DefaultAdapter<P, S> {
|
|
5
5
|
notifyHotKey: (e: KeyboardEvent) => void;
|
|
6
|
-
|
|
6
|
+
registerEvent: () => void;
|
|
7
|
+
unregisterEvent: () => void
|
|
7
8
|
}
|
|
8
9
|
|
|
9
10
|
export default class HotKeysFoundation<P = Record<string, any>, S = Record<string, any>> extends BaseFoundation<HotKeysAdapter<P, S>, P, S> {
|
|
@@ -13,8 +14,7 @@ export default class HotKeysFoundation<P = Record<string, any>, S = Record<strin
|
|
|
13
14
|
|
|
14
15
|
init(): void {
|
|
15
16
|
// init Listener
|
|
16
|
-
|
|
17
|
-
target?.addEventListener('keydown', this.handleKeyDown);
|
|
17
|
+
this._adapter.registerEvent();
|
|
18
18
|
const hotKeys = this.getProps().hotKeys;
|
|
19
19
|
if (!this.isValidHotKeys(hotKeys)) {
|
|
20
20
|
throw new Error('HotKeys must have one common key and 0/some modifier key');
|
|
@@ -75,7 +75,6 @@ export default class HotKeysFoundation<P = Record<string, any>, S = Record<strin
|
|
|
75
75
|
|
|
76
76
|
destroy(): void {
|
|
77
77
|
// remove Listener
|
|
78
|
-
|
|
79
|
-
target?.removeEventListener('keydown', this.handleKeyDown);
|
|
78
|
+
this._adapter.unregisterEvent();
|
|
80
79
|
}
|
|
81
80
|
}
|
|
@@ -85,7 +85,7 @@ export interface EventHandlerProps {
|
|
|
85
85
|
onClear?: (e: any) => void;
|
|
86
86
|
onFocus?: (e: any, rangType: RangeType) => void;
|
|
87
87
|
onPresetClick?: OnPresetClickType;
|
|
88
|
-
onClickOutSide?: () => void;
|
|
88
|
+
onClickOutSide?: (e: any) => void;
|
|
89
89
|
}
|
|
90
90
|
export interface DatePickerFoundationProps extends ElementProps, RenderProps, EventHandlerProps, Pick<MonthsGridFoundationProps, 'startYear' | 'endYear'> {
|
|
91
91
|
autoAdjustOverflow?: boolean;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import BaseFoundation, { DefaultAdapter } from '../base/foundation';
|
|
2
2
|
export interface HotKeysAdapter<P = Record<string, any>, S = Record<string, any>> extends DefaultAdapter<P, S> {
|
|
3
3
|
notifyHotKey: (e: KeyboardEvent) => void;
|
|
4
|
-
|
|
4
|
+
registerEvent: () => void;
|
|
5
|
+
unregisterEvent: () => void;
|
|
5
6
|
}
|
|
6
7
|
export default class HotKeysFoundation<P = Record<string, any>, S = Record<string, any>> extends BaseFoundation<HotKeysAdapter<P, S>, P, S> {
|
|
7
8
|
constructor(adapter: HotKeysAdapter<P, S>);
|
|
@@ -63,8 +63,7 @@ class HotKeysFoundation extends _foundation.default {
|
|
|
63
63
|
}
|
|
64
64
|
init() {
|
|
65
65
|
// init Listener
|
|
66
|
-
|
|
67
|
-
target === null || target === void 0 ? void 0 : target.addEventListener('keydown', this.handleKeyDown);
|
|
66
|
+
this._adapter.registerEvent();
|
|
68
67
|
const hotKeys = this.getProps().hotKeys;
|
|
69
68
|
if (!this.isValidHotKeys(hotKeys)) {
|
|
70
69
|
throw new Error('HotKeys must have one common key and 0/some modifier key');
|
|
@@ -72,8 +71,7 @@ class HotKeysFoundation extends _foundation.default {
|
|
|
72
71
|
}
|
|
73
72
|
destroy() {
|
|
74
73
|
// remove Listener
|
|
75
|
-
|
|
76
|
-
target === null || target === void 0 ? void 0 : target.removeEventListener('keydown', this.handleKeyDown);
|
|
74
|
+
this._adapter.unregisterEvent();
|
|
77
75
|
}
|
|
78
76
|
}
|
|
79
77
|
exports.default = HotKeysFoundation;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.strings = exports.cssClasses = void 0;
|
|
7
|
+
var _constants = require("../base/constants");
|
|
8
|
+
const cssClasses = exports.cssClasses = {
|
|
9
|
+
PREFIX: `${_constants.BASE_CLASS_PREFIX}-resizable`
|
|
10
|
+
};
|
|
11
|
+
const strings = exports.strings = {};
|
|
@@ -0,0 +1,4 @@
|
|
|
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 };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "ResizableFoundation", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _single.ResizableFoundation;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "ResizableHandlerFoundation", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _single.ResizableHandlerFoundation;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "ResizeGroupFoundation", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _group.ResizeGroupFoundation;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(exports, "ResizeHandlerFoundation", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () {
|
|
27
|
+
return _group.ResizeHandlerFoundation;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
Object.defineProperty(exports, "ResizeItemFoundation", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function () {
|
|
33
|
+
return _group.ResizeItemFoundation;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
var _single = require("./single");
|
|
37
|
+
var _group = require("./group");
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import BaseFoundation, { DefaultAdapter } from '../../base/foundation';
|
|
2
|
+
import { ResizeStartCallback, ResizeCallback } from "../singleConstants";
|
|
3
|
+
export interface ResizeHandlerAdapter<P = Record<string, any>, S = Record<string, any>> extends DefaultAdapter<P, S> {
|
|
4
|
+
registerEvents: () => void;
|
|
5
|
+
unregisterEvents: () => void;
|
|
6
|
+
}
|
|
7
|
+
export declare class ResizeHandlerFoundation<P = Record<string, any>, S = Record<string, any>> extends BaseFoundation<ResizeHandlerAdapter<P, S>, P, S> {
|
|
8
|
+
constructor(adapter: ResizeHandlerAdapter<P, S>);
|
|
9
|
+
init(): void;
|
|
10
|
+
destroy(): void;
|
|
11
|
+
}
|
|
12
|
+
export interface ResizeItemAdapter<P = Record<string, any>, S = Record<string, any>> extends DefaultAdapter<P, S> {
|
|
13
|
+
}
|
|
14
|
+
export declare class ResizeItemFoundation<P = Record<string, any>, S = Record<string, any>> extends BaseFoundation<ResizeItemAdapter<P, S>, P, S> {
|
|
15
|
+
constructor(adapter: ResizeItemAdapter<P, S>);
|
|
16
|
+
init(): void;
|
|
17
|
+
destroy(): void;
|
|
18
|
+
}
|
|
19
|
+
export interface ResizeGroupAdapter<P = Record<string, any>, S = Record<string, any>> extends DefaultAdapter<P, S> {
|
|
20
|
+
getGroupRef: () => HTMLDivElement | null;
|
|
21
|
+
getItem: (index: number) => HTMLDivElement;
|
|
22
|
+
getItemCount: () => number;
|
|
23
|
+
getHandler: (index: number) => HTMLDivElement;
|
|
24
|
+
getHandlerCount: () => number;
|
|
25
|
+
getItemMin: (index: number) => string;
|
|
26
|
+
getItemMax: (index: number) => string;
|
|
27
|
+
getItemStart: (index: number) => ResizeStartCallback;
|
|
28
|
+
getItemChange: (index: number) => ResizeCallback;
|
|
29
|
+
getItemEnd: (index: number) => ResizeCallback;
|
|
30
|
+
getItemDefaultSize: (index: number) => string | number;
|
|
31
|
+
registerEvents: () => void;
|
|
32
|
+
unregisterEvents: () => void;
|
|
33
|
+
}
|
|
34
|
+
export declare class ResizeGroupFoundation<P = Record<string, any>, S = Record<string, any>> extends BaseFoundation<ResizeGroupAdapter<P, S>, P, S> {
|
|
35
|
+
constructor(adapter: ResizeGroupAdapter<P, S>);
|
|
36
|
+
get groupRef(): HTMLDivElement | null;
|
|
37
|
+
direction: 'horizontal' | 'vertical';
|
|
38
|
+
itemMinusMap: Map<number, number>;
|
|
39
|
+
totalMinus: number;
|
|
40
|
+
avaliableSize: number;
|
|
41
|
+
init(): void;
|
|
42
|
+
get window(): Window | null;
|
|
43
|
+
registerEvents: () => void;
|
|
44
|
+
unregisterEvents: () => void;
|
|
45
|
+
onResizeStart: (handlerIndex: number, e: MouseEvent) => void;
|
|
46
|
+
onResizing: (e: MouseEvent) => void;
|
|
47
|
+
onResizeEnd: (e: MouseEvent) => void;
|
|
48
|
+
calculateSpace: () => void;
|
|
49
|
+
destroy(): void;
|
|
50
|
+
}
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.ResizeItemFoundation = exports.ResizeHandlerFoundation = exports.ResizeGroupFoundation = void 0;
|
|
7
|
+
var _utils = require("../utils");
|
|
8
|
+
var _foundation = _interopRequireDefault(require("../../base/foundation"));
|
|
9
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
|
+
class ResizeHandlerFoundation extends _foundation.default {
|
|
11
|
+
constructor(adapter) {
|
|
12
|
+
super(Object.assign({}, adapter));
|
|
13
|
+
}
|
|
14
|
+
init() {
|
|
15
|
+
this._adapter.registerEvents();
|
|
16
|
+
}
|
|
17
|
+
destroy() {
|
|
18
|
+
this._adapter.unregisterEvents();
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.ResizeHandlerFoundation = ResizeHandlerFoundation;
|
|
22
|
+
class ResizeItemFoundation extends _foundation.default {
|
|
23
|
+
constructor(adapter) {
|
|
24
|
+
super(Object.assign({}, adapter));
|
|
25
|
+
}
|
|
26
|
+
init() {}
|
|
27
|
+
destroy() {}
|
|
28
|
+
}
|
|
29
|
+
exports.ResizeItemFoundation = ResizeItemFoundation;
|
|
30
|
+
class ResizeGroupFoundation extends _foundation.default {
|
|
31
|
+
constructor(adapter) {
|
|
32
|
+
super(Object.assign({}, adapter));
|
|
33
|
+
this.registerEvents = () => {
|
|
34
|
+
this._adapter.registerEvents();
|
|
35
|
+
};
|
|
36
|
+
this.unregisterEvents = () => {
|
|
37
|
+
this._adapter.unregisterEvents();
|
|
38
|
+
};
|
|
39
|
+
this.onResizeStart = (handlerIndex, e) => {
|
|
40
|
+
let {
|
|
41
|
+
clientX,
|
|
42
|
+
clientY
|
|
43
|
+
} = e;
|
|
44
|
+
let lastItem = this._adapter.getItem(handlerIndex),
|
|
45
|
+
nextItem = this._adapter.getItem(handlerIndex + 1);
|
|
46
|
+
let lastOffset, nextOffset;
|
|
47
|
+
// offset caused by padding and border
|
|
48
|
+
const lastStyle = this.window.getComputedStyle(lastItem);
|
|
49
|
+
const nextStyle = this.window.getComputedStyle(nextItem);
|
|
50
|
+
lastOffset = (0, _utils.getOffset)(lastStyle, this.direction);
|
|
51
|
+
nextOffset = (0, _utils.getOffset)(nextStyle, this.direction);
|
|
52
|
+
const states = this.getStates();
|
|
53
|
+
this.setState({
|
|
54
|
+
isResizing: true,
|
|
55
|
+
originalPosition: {
|
|
56
|
+
x: clientX,
|
|
57
|
+
y: clientY,
|
|
58
|
+
lastItemSize: this.direction === 'horizontal' ? lastItem.offsetWidth : lastItem.offsetHeight,
|
|
59
|
+
nextItemSize: this.direction === 'horizontal' ? nextItem.offsetWidth : nextItem.offsetHeight,
|
|
60
|
+
lastOffset,
|
|
61
|
+
nextOffset
|
|
62
|
+
},
|
|
63
|
+
backgroundStyle: Object.assign(Object.assign({}, states.backgroundStyle), {
|
|
64
|
+
cursor: this.window.getComputedStyle(e.target).cursor || 'auto'
|
|
65
|
+
}),
|
|
66
|
+
curHandler: handlerIndex
|
|
67
|
+
});
|
|
68
|
+
this.registerEvents();
|
|
69
|
+
let lastStart = this._adapter.getItemStart(handlerIndex),
|
|
70
|
+
nextStart = this._adapter.getItemStart(handlerIndex + 1);
|
|
71
|
+
let [lastDir, nextDir] = (0, _utils.getItemDirection)(this.direction);
|
|
72
|
+
if (lastStart) {
|
|
73
|
+
lastStart(e, lastDir);
|
|
74
|
+
}
|
|
75
|
+
if (nextStart) {
|
|
76
|
+
nextStart(e, nextDir);
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
this.onResizing = e => {
|
|
80
|
+
const state = this.getStates();
|
|
81
|
+
if (!state.isResizing) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
const {
|
|
85
|
+
curHandler,
|
|
86
|
+
originalPosition
|
|
87
|
+
} = state;
|
|
88
|
+
let {
|
|
89
|
+
x: initX,
|
|
90
|
+
y: initY,
|
|
91
|
+
lastItemSize,
|
|
92
|
+
nextItemSize,
|
|
93
|
+
lastOffset,
|
|
94
|
+
nextOffset
|
|
95
|
+
} = originalPosition;
|
|
96
|
+
let {
|
|
97
|
+
clientX,
|
|
98
|
+
clientY
|
|
99
|
+
} = e;
|
|
100
|
+
const props = this.getProps();
|
|
101
|
+
const {
|
|
102
|
+
direction
|
|
103
|
+
} = props;
|
|
104
|
+
let lastItem = this._adapter.getItem(curHandler),
|
|
105
|
+
nextItem = this._adapter.getItem(curHandler + 1);
|
|
106
|
+
let parentSize = this.direction === 'horizontal' ? this.groupRef.offsetWidth : this.groupRef.offsetHeight;
|
|
107
|
+
let availableSize = parentSize - this.totalMinus;
|
|
108
|
+
let delta = direction === 'horizontal' ? clientX - initX : clientY - initY;
|
|
109
|
+
let lastNewSize = lastItemSize + delta;
|
|
110
|
+
let nextNewSize = nextItemSize - delta;
|
|
111
|
+
// 判断是否超出限制
|
|
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
|
+
if (lastFlag) {
|
|
115
|
+
lastNewSize = (0, _utils.adjustNewSize)(lastNewSize, this._adapter.getItemMin(curHandler), this._adapter.getItemMax(curHandler), availableSize, lastOffset);
|
|
116
|
+
nextNewSize = lastItemSize + nextItemSize - lastNewSize;
|
|
117
|
+
}
|
|
118
|
+
if (nextFlag) {
|
|
119
|
+
nextNewSize = (0, _utils.adjustNewSize)(nextNewSize, this._adapter.getItemMin(curHandler + 1), this._adapter.getItemMax(curHandler + 1), availableSize, nextOffset);
|
|
120
|
+
lastNewSize = lastItemSize + nextItemSize - nextNewSize;
|
|
121
|
+
}
|
|
122
|
+
if (direction === 'horizontal') {
|
|
123
|
+
lastItem.style.width = lastNewSize / parentSize * 100 + '%';
|
|
124
|
+
nextItem.style.width = nextNewSize / parentSize * 100 + '%';
|
|
125
|
+
} else if (direction === 'vertical') {
|
|
126
|
+
lastItem.style.height = lastNewSize / parentSize * 100 + '%';
|
|
127
|
+
nextItem.style.height = nextNewSize / parentSize * 100 + '%';
|
|
128
|
+
}
|
|
129
|
+
let lastFunc = this._adapter.getItemChange(curHandler),
|
|
130
|
+
nextFunc = this._adapter.getItemChange(curHandler + 1);
|
|
131
|
+
let [lastDir, nextDir] = (0, _utils.getItemDirection)(this.direction);
|
|
132
|
+
if (lastFunc) {
|
|
133
|
+
lastFunc({
|
|
134
|
+
width: lastItem.offsetWidth,
|
|
135
|
+
height: lastItem.offsetHeight
|
|
136
|
+
}, e, lastDir);
|
|
137
|
+
}
|
|
138
|
+
if (nextFunc) {
|
|
139
|
+
nextFunc({
|
|
140
|
+
width: nextItem.offsetWidth,
|
|
141
|
+
height: nextItem.offsetHeight
|
|
142
|
+
}, e, nextDir);
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
this.onResizeEnd = e => {
|
|
146
|
+
const {
|
|
147
|
+
curHandler
|
|
148
|
+
} = this.getStates();
|
|
149
|
+
let lastItem = this._adapter.getItem(curHandler),
|
|
150
|
+
nextItem = this._adapter.getItem(curHandler + 1);
|
|
151
|
+
let lastFunc = this._adapter.getItemEnd(curHandler),
|
|
152
|
+
nextFunc = this._adapter.getItemEnd(curHandler + 1);
|
|
153
|
+
let [lastDir, nextDir] = (0, _utils.getItemDirection)(this.direction);
|
|
154
|
+
if (lastFunc) {
|
|
155
|
+
lastFunc({
|
|
156
|
+
width: lastItem.offsetWidth,
|
|
157
|
+
height: lastItem.offsetHeight
|
|
158
|
+
}, e, lastDir);
|
|
159
|
+
}
|
|
160
|
+
if (nextFunc) {
|
|
161
|
+
nextFunc({
|
|
162
|
+
width: nextItem.offsetWidth,
|
|
163
|
+
height: nextItem.offsetHeight
|
|
164
|
+
}, e, nextDir);
|
|
165
|
+
}
|
|
166
|
+
this.setState({
|
|
167
|
+
isResizing: false,
|
|
168
|
+
curHandler: null
|
|
169
|
+
});
|
|
170
|
+
this.unregisterEvents();
|
|
171
|
+
};
|
|
172
|
+
this.calculateSpace = () => {
|
|
173
|
+
const props = this.getProps();
|
|
174
|
+
const {
|
|
175
|
+
direction
|
|
176
|
+
} = props;
|
|
177
|
+
// calculate accurate space for group item
|
|
178
|
+
let handlerSizes = new Array(this._adapter.getHandlerCount()).fill(0);
|
|
179
|
+
let groupSize = direction === 'horizontal' ? this.groupRef.offsetWidth : this.groupRef.offsetHeight;
|
|
180
|
+
this.totalMinus = 0;
|
|
181
|
+
for (let i = 0; i < this._adapter.getHandlerCount(); i++) {
|
|
182
|
+
let handlerSize = direction === 'horizontal' ? this._adapter.getHandler(i).offsetWidth : this._adapter.getHandler(i).offsetHeight;
|
|
183
|
+
handlerSizes[i] = handlerSize;
|
|
184
|
+
this.totalMinus += handlerSize;
|
|
185
|
+
}
|
|
186
|
+
// allocate size for items which don't have default size
|
|
187
|
+
let totalSizePercent = 0;
|
|
188
|
+
let undefineLoc = new Map(),
|
|
189
|
+
undefinedTotal = 0; // proportion
|
|
190
|
+
for (let i = 0; i < this._adapter.getItemCount(); i++) {
|
|
191
|
+
if (i === 0) {
|
|
192
|
+
this.itemMinusMap.set(i, handlerSizes[i] / 2);
|
|
193
|
+
} else if (i === this._adapter.getItemCount() - 1) {
|
|
194
|
+
this.itemMinusMap.set(i, handlerSizes[i - 1] / 2);
|
|
195
|
+
} else {
|
|
196
|
+
this.itemMinusMap.set(i, handlerSizes[i - 1] / 2 + handlerSizes[i] / 2);
|
|
197
|
+
}
|
|
198
|
+
const child = this._adapter.getItem(i);
|
|
199
|
+
let minSize = this._adapter.getItemMin(i),
|
|
200
|
+
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;
|
|
203
|
+
if (minSizePercent > maxSizePercent) {
|
|
204
|
+
console.warn('[Semi ResizableItem]: min size bigger than max size');
|
|
205
|
+
}
|
|
206
|
+
let defaultSize = this._adapter.getItemDefaultSize(i);
|
|
207
|
+
if (defaultSize) {
|
|
208
|
+
let itemSizePercent;
|
|
209
|
+
if (typeof defaultSize === 'string') {
|
|
210
|
+
if (defaultSize.endsWith('%')) {
|
|
211
|
+
itemSizePercent = parseFloat(defaultSize.slice(0, -1));
|
|
212
|
+
} else if (defaultSize.endsWith('px')) {
|
|
213
|
+
itemSizePercent = parseFloat(defaultSize.slice(0, -2)) / groupSize * 100;
|
|
214
|
+
} else if (/^-?\d+(\.\d+)?$/.test(defaultSize)) {
|
|
215
|
+
// 仅由数字组成,表示按比例分配剩下空间
|
|
216
|
+
undefineLoc.set(i, parseFloat(defaultSize));
|
|
217
|
+
undefinedTotal += parseFloat(defaultSize);
|
|
218
|
+
continue;
|
|
219
|
+
}
|
|
220
|
+
} else {
|
|
221
|
+
undefineLoc.set(i, defaultSize);
|
|
222
|
+
undefinedTotal += defaultSize;
|
|
223
|
+
continue;
|
|
224
|
+
}
|
|
225
|
+
totalSizePercent += itemSizePercent;
|
|
226
|
+
if (direction === 'horizontal') {
|
|
227
|
+
child.style.width = `calc(${itemSizePercent}% - ${this.itemMinusMap.get(i)}px)`;
|
|
228
|
+
} else {
|
|
229
|
+
child.style.height = `calc(${itemSizePercent}% - ${this.itemMinusMap.get(i)}px)`;
|
|
230
|
+
}
|
|
231
|
+
if (itemSizePercent < minSizePercent) {
|
|
232
|
+
console.warn('[Semi ResizableGroup]: item size smaller than min size');
|
|
233
|
+
}
|
|
234
|
+
if (itemSizePercent > maxSizePercent) {
|
|
235
|
+
console.warn('[Semi ResizableGroup]: item size bigger than max size');
|
|
236
|
+
}
|
|
237
|
+
} else {
|
|
238
|
+
undefineLoc.set(i, 1);
|
|
239
|
+
undefinedTotal += 1;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
let undefineSizePercent = 100 - totalSizePercent;
|
|
243
|
+
if (totalSizePercent > 100) {
|
|
244
|
+
console.warn('[Semi ResizableGroup]: total Size bigger than 100%');
|
|
245
|
+
undefineSizePercent = 10; // 如果总和超过100%,则保留10%的空间均分给未定义的item
|
|
246
|
+
}
|
|
247
|
+
undefineLoc.forEach((value, key) => {
|
|
248
|
+
const child = this._adapter.getItem(key);
|
|
249
|
+
if (direction === 'horizontal') {
|
|
250
|
+
child.style.width = `calc(${undefineSizePercent / undefinedTotal * value}% - ${this.itemMinusMap.get(key)}px)`;
|
|
251
|
+
} else {
|
|
252
|
+
child.style.height = `calc(${undefineSizePercent / undefinedTotal * value}% - ${this.itemMinusMap.get(key)}px)`;
|
|
253
|
+
}
|
|
254
|
+
});
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
get groupRef() {
|
|
258
|
+
return this._adapter.getGroupRef();
|
|
259
|
+
}
|
|
260
|
+
init() {
|
|
261
|
+
this.direction = this.getProp('direction');
|
|
262
|
+
this.itemMinusMap = new Map();
|
|
263
|
+
this.calculateSpace();
|
|
264
|
+
}
|
|
265
|
+
get window() {
|
|
266
|
+
var _a;
|
|
267
|
+
return (_a = this.groupRef.ownerDocument.defaultView) !== null && _a !== void 0 ? _a : null;
|
|
268
|
+
}
|
|
269
|
+
destroy() {}
|
|
270
|
+
}
|
|
271
|
+
exports.ResizeGroupFoundation = ResizeGroupFoundation;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare const directionStyles: {
|
|
2
|
+
readonly horizontal: {
|
|
3
|
+
readonly width: "8px";
|
|
4
|
+
readonly flexShrink: 0;
|
|
5
|
+
readonly height: "100%";
|
|
6
|
+
readonly margin: "0";
|
|
7
|
+
readonly cursor: "col-resize";
|
|
8
|
+
};
|
|
9
|
+
readonly vertical: {
|
|
10
|
+
readonly width: "100%";
|
|
11
|
+
readonly height: "8px";
|
|
12
|
+
readonly flexShrink: 0;
|
|
13
|
+
readonly margin: "0";
|
|
14
|
+
readonly cursor: "row-resize";
|
|
15
|
+
};
|
|
16
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.directionStyles = void 0;
|
|
7
|
+
// group
|
|
8
|
+
const rowStyleBase = {
|
|
9
|
+
width: '100%',
|
|
10
|
+
height: '8px',
|
|
11
|
+
flexShrink: 0,
|
|
12
|
+
margin: '0',
|
|
13
|
+
cursor: 'row-resize'
|
|
14
|
+
};
|
|
15
|
+
const colStyleBase = {
|
|
16
|
+
width: '8px',
|
|
17
|
+
flexShrink: 0,
|
|
18
|
+
height: '100%',
|
|
19
|
+
margin: '0',
|
|
20
|
+
cursor: 'col-resize'
|
|
21
|
+
};
|
|
22
|
+
const directionStyles = exports.directionStyles = {
|
|
23
|
+
horizontal: Object.assign({}, colStyleBase),
|
|
24
|
+
vertical: Object.assign({}, rowStyleBase)
|
|
25
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/* shadow */
|
|
2
|
+
/* sizing */
|
|
3
|
+
/* spacing */
|
|
4
|
+
.semi-resizable-resizable {
|
|
5
|
+
position: relative;
|
|
6
|
+
box-sizing: border-box;
|
|
7
|
+
flex-shrink: 0;
|
|
8
|
+
}
|
|
9
|
+
.semi-resizable-resizableHandler {
|
|
10
|
+
position: absolute;
|
|
11
|
+
user-select: none;
|
|
12
|
+
z-index: 2000;
|
|
13
|
+
}
|
|
14
|
+
.semi-resizable-group {
|
|
15
|
+
display: flex;
|
|
16
|
+
position: relative;
|
|
17
|
+
box-sizing: border-box;
|
|
18
|
+
height: 100%;
|
|
19
|
+
width: 100%;
|
|
20
|
+
}
|
|
21
|
+
.semi-resizable-item {
|
|
22
|
+
position: relative;
|
|
23
|
+
box-sizing: border-box;
|
|
24
|
+
flex-shrink: 0;
|
|
25
|
+
}
|
|
26
|
+
.semi-resizable-handler {
|
|
27
|
+
user-select: none;
|
|
28
|
+
z-index: 2000;
|
|
29
|
+
display: flex;
|
|
30
|
+
align-items: center;
|
|
31
|
+
justify-content: center;
|
|
32
|
+
background-color: var(--semi-color-fill-0);
|
|
33
|
+
opacity: 1;
|
|
34
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
$module: #{$prefix}-resizable;
|
|
2
|
+
|
|
3
|
+
.#{$module} {
|
|
4
|
+
&-resizable {
|
|
5
|
+
position: relative;
|
|
6
|
+
box-sizing: border-box;
|
|
7
|
+
flex-shrink: 0;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
&-resizableHandler {
|
|
11
|
+
position: absolute;
|
|
12
|
+
user-select: none;
|
|
13
|
+
z-index: $z-resizable_handler;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
&-group {
|
|
17
|
+
display: flex;
|
|
18
|
+
position: relative;
|
|
19
|
+
box-sizing: border-box;
|
|
20
|
+
height: 100%;
|
|
21
|
+
width: 100%;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
&-item {
|
|
25
|
+
position: relative;
|
|
26
|
+
box-sizing: border-box;
|
|
27
|
+
flex-shrink: 0;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
&-handler {
|
|
31
|
+
user-select: none;
|
|
32
|
+
z-index: $z-resizable_handler;
|
|
33
|
+
display: flex;
|
|
34
|
+
align-items: center;
|
|
35
|
+
justify-content: center;
|
|
36
|
+
background-color: var(--semi-color-fill-0);
|
|
37
|
+
opacity: 1;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import BaseFoundation, { DefaultAdapter } from '../../base/foundation';
|
|
2
|
+
import { Size, NumberSize, Direction } from "../singleConstants";
|
|
3
|
+
export interface ResizableHandlerAdapter<P = Record<string, any>, S = Record<string, any>> extends DefaultAdapter<P, S> {
|
|
4
|
+
registerEvent: () => void;
|
|
5
|
+
unregisterEvent: () => void;
|
|
6
|
+
}
|
|
7
|
+
export declare class ResizableHandlerFoundation<P = Record<string, any>, S = Record<string, any>> extends BaseFoundation<ResizableHandlerAdapter<P, S>, P, S> {
|
|
8
|
+
constructor(adapter: ResizableHandlerAdapter<P, S>);
|
|
9
|
+
init(): void;
|
|
10
|
+
onMouseDown: (e: MouseEvent) => void;
|
|
11
|
+
destroy(): void;
|
|
12
|
+
}
|
|
13
|
+
export interface ResizableAdapter<P = Record<string, any>, S = Record<string, any>> extends DefaultAdapter<P, S> {
|
|
14
|
+
getResizable: () => HTMLDivElement | null;
|
|
15
|
+
registerEvent: () => void;
|
|
16
|
+
unregisterEvent: () => void;
|
|
17
|
+
}
|
|
18
|
+
export declare class ResizableFoundation<P = Record<string, any>, S = Record<string, any>> extends BaseFoundation<ResizableAdapter<P, S>, P, S> {
|
|
19
|
+
constructor(adapter: ResizableAdapter<P, S>);
|
|
20
|
+
init(): void;
|
|
21
|
+
flexDirection?: 'row' | 'column';
|
|
22
|
+
lockAspectRatio: number;
|
|
23
|
+
resizable: HTMLElement | null;
|
|
24
|
+
parentLeft: number;
|
|
25
|
+
parentTop: number;
|
|
26
|
+
boundaryLeft: number;
|
|
27
|
+
boundaryRight: number;
|
|
28
|
+
boundaryTop: number;
|
|
29
|
+
boundaryBottom: number;
|
|
30
|
+
targetLeft: number;
|
|
31
|
+
targetTop: number;
|
|
32
|
+
get parent(): HTMLElement | null;
|
|
33
|
+
get window(): Window | null;
|
|
34
|
+
get propSize(): Size;
|
|
35
|
+
get size(): NumberSize;
|
|
36
|
+
get sizeStyle(): {
|
|
37
|
+
width: string;
|
|
38
|
+
height: string;
|
|
39
|
+
};
|
|
40
|
+
getParentSize(): {
|
|
41
|
+
width: number;
|
|
42
|
+
height: number;
|
|
43
|
+
};
|
|
44
|
+
registerEvents(): void;
|
|
45
|
+
unregisterEvents(): void;
|
|
46
|
+
getCssPropertySize(newSize: number | string, property: 'width' | 'height'): number | string;
|
|
47
|
+
calBoundaryMax(maxWidth?: number, maxHeight?: number): {
|
|
48
|
+
maxWidth: number;
|
|
49
|
+
maxHeight: number;
|
|
50
|
+
};
|
|
51
|
+
calDirectionSize(clientX: number, clientY: number): {
|
|
52
|
+
newWidth: any;
|
|
53
|
+
newHeight: any;
|
|
54
|
+
};
|
|
55
|
+
calAspectRatioSize(newWidth: number, newHeight: number, max: {
|
|
56
|
+
width?: number;
|
|
57
|
+
height?: number;
|
|
58
|
+
}, min: {
|
|
59
|
+
width?: number;
|
|
60
|
+
height?: number;
|
|
61
|
+
}): {
|
|
62
|
+
newWidth: number;
|
|
63
|
+
newHeight: number;
|
|
64
|
+
};
|
|
65
|
+
setBoundary(): void;
|
|
66
|
+
onResizeStart: (e: MouseEvent, direction: Direction) => void;
|
|
67
|
+
onMouseMove: (event: MouseEvent) => void;
|
|
68
|
+
onMouseUp: (event: MouseEvent) => void;
|
|
69
|
+
destroy(): void;
|
|
70
|
+
}
|