@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.
Files changed (53) hide show
  1. package/datePicker/foundation.ts +1 -1
  2. package/hotKeys/foundation.ts +4 -5
  3. package/lib/cjs/datePicker/foundation.d.ts +1 -1
  4. package/lib/cjs/hotKeys/foundation.d.ts +2 -1
  5. package/lib/cjs/hotKeys/foundation.js +2 -4
  6. package/lib/cjs/overflowList/constants.d.ts +1 -1
  7. package/lib/cjs/resizable/constants.d.ts +5 -0
  8. package/lib/cjs/resizable/constants.js +11 -0
  9. package/lib/cjs/resizable/foundation.d.ts +4 -0
  10. package/lib/cjs/resizable/foundation.js +37 -0
  11. package/lib/cjs/resizable/group/index.d.ts +50 -0
  12. package/lib/cjs/resizable/group/index.js +271 -0
  13. package/lib/cjs/resizable/groupConstants.d.ts +16 -0
  14. package/lib/cjs/resizable/groupConstants.js +25 -0
  15. package/lib/cjs/resizable/resizable.css +34 -0
  16. package/lib/cjs/resizable/resizable.scss +39 -0
  17. package/lib/cjs/resizable/single/index.d.ts +70 -0
  18. package/lib/cjs/resizable/single/index.js +574 -0
  19. package/lib/cjs/resizable/singleConstants.d.ts +105 -0
  20. package/lib/cjs/resizable/singleConstants.js +67 -0
  21. package/lib/cjs/resizable/utils.d.ts +20 -0
  22. package/lib/cjs/resizable/utils.js +142 -0
  23. package/lib/cjs/tree/treeUtil.d.ts +1 -1
  24. package/lib/es/datePicker/foundation.d.ts +1 -1
  25. package/lib/es/hotKeys/foundation.d.ts +2 -1
  26. package/lib/es/hotKeys/foundation.js +2 -4
  27. package/lib/es/overflowList/constants.d.ts +1 -1
  28. package/lib/es/resizable/constants.d.ts +5 -0
  29. package/lib/es/resizable/constants.js +6 -0
  30. package/lib/es/resizable/foundation.d.ts +4 -0
  31. package/lib/es/resizable/foundation.js +4 -0
  32. package/lib/es/resizable/group/index.d.ts +50 -0
  33. package/lib/es/resizable/group/index.js +262 -0
  34. package/lib/es/resizable/groupConstants.d.ts +16 -0
  35. package/lib/es/resizable/groupConstants.js +19 -0
  36. package/lib/es/resizable/resizable.css +34 -0
  37. package/lib/es/resizable/resizable.scss +39 -0
  38. package/lib/es/resizable/single/index.d.ts +70 -0
  39. package/lib/es/resizable/single/index.js +565 -0
  40. package/lib/es/resizable/singleConstants.d.ts +105 -0
  41. package/lib/es/resizable/singleConstants.js +61 -0
  42. package/lib/es/resizable/utils.d.ts +20 -0
  43. package/lib/es/resizable/utils.js +124 -0
  44. package/lib/es/tree/treeUtil.d.ts +1 -1
  45. package/package.json +3 -3
  46. package/resizable/constants.ts +13 -0
  47. package/resizable/foundation.ts +31 -0
  48. package/resizable/group/index.ts +293 -0
  49. package/resizable/groupConstants.ts +25 -0
  50. package/resizable/resizable.scss +39 -0
  51. package/resizable/single/index.ts +629 -0
  52. package/resizable/singleConstants.ts +127 -0
  53. package/resizable/utils.ts +145 -0
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.directions = exports.directionStyles = exports.DEFAULT_SIZE = void 0;
7
+ // single
8
+ const rowStyleBase = {
9
+ width: '100%',
10
+ height: '10px',
11
+ top: '0px',
12
+ left: '0px',
13
+ cursor: 'row-resize'
14
+ };
15
+ const colStyleBase = {
16
+ width: '10px',
17
+ height: '100%',
18
+ top: '0px',
19
+ left: '0px',
20
+ cursor: 'col-resize'
21
+ };
22
+ const edgeStyleBase = {
23
+ width: '20px',
24
+ height: '20px',
25
+ position: 'absolute'
26
+ };
27
+ const directions = exports.directions = ['top', 'right', 'bottom', 'left', 'topRight', 'bottomRight', 'bottomLeft', 'topLeft'];
28
+ const directionStyles = exports.directionStyles = {
29
+ top: Object.assign(Object.assign({}, rowStyleBase), {
30
+ top: '-5px'
31
+ }),
32
+ right: Object.assign(Object.assign({}, colStyleBase), {
33
+ left: undefined,
34
+ right: '-5px'
35
+ }),
36
+ bottom: Object.assign(Object.assign({}, rowStyleBase), {
37
+ top: undefined,
38
+ bottom: '-5px'
39
+ }),
40
+ left: Object.assign(Object.assign({}, colStyleBase), {
41
+ left: '-5px'
42
+ }),
43
+ topRight: Object.assign(Object.assign({}, edgeStyleBase), {
44
+ right: '-10px',
45
+ top: '-10px',
46
+ cursor: 'ne-resize'
47
+ }),
48
+ bottomRight: Object.assign(Object.assign({}, edgeStyleBase), {
49
+ right: '-10px',
50
+ bottom: '-10px',
51
+ cursor: 'se-resize'
52
+ }),
53
+ bottomLeft: Object.assign(Object.assign({}, edgeStyleBase), {
54
+ left: '-10px',
55
+ bottom: '-10px',
56
+ cursor: 'sw-resize'
57
+ }),
58
+ topLeft: Object.assign(Object.assign({}, edgeStyleBase), {
59
+ left: '-10px',
60
+ top: '-10px',
61
+ cursor: 'nw-resize'
62
+ })
63
+ };
64
+ const DEFAULT_SIZE = exports.DEFAULT_SIZE = {
65
+ width: 'auto',
66
+ height: 'auto'
67
+ };
@@ -0,0 +1,20 @@
1
+ export declare const clamp: (n: number, min: number, max: number) => number;
2
+ export declare const snap: (n: number, size: number) => number;
3
+ export declare const has: (dir: 'top' | 'right' | 'bottom' | 'left', target: string) => boolean;
4
+ export declare const findNextSnap: (n: number, snapArray: number[], snapGap?: number) => number;
5
+ export declare const getStringSize: (n: number | string) => string;
6
+ export declare const getNumberSize: (size: undefined | string | number, parentSize: number, innerWidth: number, innerHeight: number) => number;
7
+ export declare const calculateNewMax: (parentSize: {
8
+ width: number;
9
+ height: number;
10
+ }, innerWidth: number, innerHeight: number, maxWidth?: string | number, maxHeight?: string | number, minWidth?: string | number, minHeight?: string | number) => {
11
+ maxWidth: number;
12
+ maxHeight: number;
13
+ minWidth: number;
14
+ minHeight: number;
15
+ };
16
+ export declare const getItemDirection: (dir: 'vertical' | 'horizontal') => string[];
17
+ export declare const getPixelSize: (size: string, parentSize: number) => number;
18
+ export declare const judgeConstraint: (newSize: number, min: string, max: string, parentSize: number, offset?: number) => boolean;
19
+ export declare const adjustNewSize: (newSize: number, min: string, max: string, parentSize: number, offset: number) => number;
20
+ export declare const getOffset: (style: CSSStyleDeclaration, direction: 'horizontal' | 'vertical') => number;
@@ -0,0 +1,142 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.snap = exports.judgeConstraint = exports.has = exports.getStringSize = exports.getPixelSize = exports.getOffset = exports.getNumberSize = exports.getItemDirection = exports.findNextSnap = exports.clamp = exports.calculateNewMax = exports.adjustNewSize = void 0;
7
+ const clamp = (n, min, max) => Math.max(Math.min(n, max), min);
8
+ exports.clamp = clamp;
9
+ const snap = (n, size) => Math.round(n / size) * size;
10
+ exports.snap = snap;
11
+ const has = (dir, target) => new RegExp(dir, 'i').test(target);
12
+ exports.has = has;
13
+ const findNextSnap = function (n, snapArray) {
14
+ let snapGap = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
15
+ const closestGapIndex = snapArray.reduce((prev, curr, index) => Math.abs(curr - n) < Math.abs(snapArray[prev] - n) ? index : prev, 0);
16
+ const gap = Math.abs(snapArray[closestGapIndex] - n);
17
+ return snapGap === 0 || gap < snapGap ? snapArray[closestGapIndex] : n;
18
+ };
19
+ exports.findNextSnap = findNextSnap;
20
+ const getStringSize = n => {
21
+ n = n.toString();
22
+ if (n === 'auto') {
23
+ return n;
24
+ }
25
+ if (n.endsWith('px')) {
26
+ return n;
27
+ }
28
+ if (n.endsWith('%')) {
29
+ return n;
30
+ }
31
+ if (n.endsWith('vh')) {
32
+ return n;
33
+ }
34
+ if (n.endsWith('vw')) {
35
+ return n;
36
+ }
37
+ if (n.endsWith('vmax')) {
38
+ return n;
39
+ }
40
+ if (n.endsWith('vmin')) {
41
+ return n;
42
+ }
43
+ return `${n}px`;
44
+ };
45
+ exports.getStringSize = getStringSize;
46
+ const getNumberSize = (size, parentSize, innerWidth, innerHeight) => {
47
+ if (size && typeof size === 'string') {
48
+ if (size.endsWith('px')) {
49
+ return Number(size.replace('px', ''));
50
+ }
51
+ if (size.endsWith('%')) {
52
+ const ratio = Number(size.replace('%', '')) / 100;
53
+ return parentSize * ratio;
54
+ }
55
+ if (size.endsWith('vw')) {
56
+ const ratio = Number(size.replace('vw', '')) / 100;
57
+ return innerWidth * ratio;
58
+ }
59
+ if (size.endsWith('vh')) {
60
+ const ratio = Number(size.replace('vh', '')) / 100;
61
+ return innerHeight * ratio;
62
+ }
63
+ }
64
+ return typeof size === 'undefined' ? size : Number(size);
65
+ };
66
+ exports.getNumberSize = getNumberSize;
67
+ const calculateNewMax = (parentSize, innerWidth, innerHeight, maxWidth, maxHeight, minWidth, minHeight) => {
68
+ maxWidth = getNumberSize(maxWidth, parentSize.width, innerWidth, innerHeight);
69
+ maxHeight = getNumberSize(maxHeight, parentSize.height, innerWidth, innerHeight);
70
+ minWidth = getNumberSize(minWidth, parentSize.width, innerWidth, innerHeight);
71
+ minHeight = getNumberSize(minHeight, parentSize.height, innerWidth, innerHeight);
72
+ return {
73
+ maxWidth,
74
+ maxHeight,
75
+ minWidth,
76
+ minHeight
77
+ };
78
+ };
79
+ exports.calculateNewMax = calculateNewMax;
80
+ const getItemDirection = dir => {
81
+ if (dir === 'vertical') {
82
+ return ['bottom', 'top'];
83
+ } else {
84
+ return ['right', 'left'];
85
+ }
86
+ };
87
+ exports.getItemDirection = getItemDirection;
88
+ const getPixelSize = (size, parentSize) => {
89
+ if (size.endsWith('px')) {
90
+ return Number(size.replace('px', ''));
91
+ }
92
+ if (size.endsWith('%')) {
93
+ return Number(size.replace('%', '')) / 100 * parentSize;
94
+ }
95
+ return typeof size === 'undefined' ? size : Number(size);
96
+ };
97
+ exports.getPixelSize = getPixelSize;
98
+ const judgeConstraint = function (newSize, min, max, parentSize) {
99
+ let offset = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0;
100
+ min = min !== null && min !== void 0 ? min : "0%";
101
+ max = max !== null && max !== void 0 ? max : "100%";
102
+ const minSize = getPixelSize(min, parentSize);
103
+ const maxSize = getPixelSize(max, parentSize);
104
+ if (newSize <= minSize + offset) {
105
+ return true;
106
+ }
107
+ if (newSize >= maxSize - offset) {
108
+ return true;
109
+ }
110
+ return false;
111
+ };
112
+ exports.judgeConstraint = judgeConstraint;
113
+ const adjustNewSize = (newSize, min, max, parentSize, offset) => {
114
+ min = min !== null && min !== void 0 ? min : "0%";
115
+ max = max !== null && max !== void 0 ? max : "100%";
116
+ const minSize = getPixelSize(min, parentSize);
117
+ const maxSize = getPixelSize(max, parentSize);
118
+ if (newSize <= minSize + offset) {
119
+ return minSize + offset;
120
+ }
121
+ if (newSize >= maxSize - offset) {
122
+ return maxSize - offset;
123
+ }
124
+ return newSize;
125
+ };
126
+ exports.adjustNewSize = adjustNewSize;
127
+ const getOffset = (style, direction) => {
128
+ if (direction === 'horizontal') {
129
+ const paddingLeft = parseFloat(style.paddingLeft);
130
+ const paddingRight = parseFloat(style.paddingRight);
131
+ const borderLeftWidth = parseFloat(style.borderLeftWidth);
132
+ const borderRightWidth = parseFloat(style.borderRightWidth);
133
+ return paddingLeft + paddingRight + borderLeftWidth + borderRightWidth;
134
+ } else {
135
+ const paddingTop = parseFloat(style.paddingTop);
136
+ const paddingBottom = parseFloat(style.paddingBottom);
137
+ const borderTopWidth = parseFloat(style.borderTopWidth);
138
+ const borderBottomWidth = parseFloat(style.borderBottomWidth);
139
+ return paddingTop + paddingBottom + borderTopWidth + borderBottomWidth;
140
+ }
141
+ };
142
+ exports.getOffset = getOffset;
@@ -83,6 +83,6 @@ export declare function getValueOrKey(data: any, keyMaps?: KeyMapProps): any;
83
83
  export declare function normalizeValue(value: any, withObject: boolean, keyMaps?: KeyMapProps): any;
84
84
  export declare function updateKeys(keySet: Set<string> | string[], keyEntities: KeyEntities): string[];
85
85
  export declare function calcDisabledKeys(keyEntities: KeyEntities, keyMaps?: KeyMapProps): Set<string>;
86
- export declare function calcDropRelativePosition(event: any, treeNode: any): 0 | 1 | -1;
86
+ export declare function calcDropRelativePosition(event: any, treeNode: any): 1 | -1 | 0;
87
87
  export declare function getDragNodesKeys(key: string, keyEntities: KeyEntities): string[];
88
88
  export declare function calcDropActualPosition(pos: string, relativeDropPos: any): any;
@@ -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
- getListenerTarget: () => HTMLElement;
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>);
@@ -56,8 +56,7 @@ export default class HotKeysFoundation extends BaseFoundation {
56
56
  }
57
57
  init() {
58
58
  // init Listener
59
- const target = this._adapter.getListenerTarget();
60
- target === null || target === void 0 ? void 0 : target.addEventListener('keydown', this.handleKeyDown);
59
+ this._adapter.registerEvent();
61
60
  const hotKeys = this.getProps().hotKeys;
62
61
  if (!this.isValidHotKeys(hotKeys)) {
63
62
  throw new Error('HotKeys must have one common key and 0/some modifier key');
@@ -65,7 +64,6 @@ export default class HotKeysFoundation extends BaseFoundation {
65
64
  }
66
65
  destroy() {
67
66
  // remove Listener
68
- const target = this._adapter.getListenerTarget();
69
- target === null || target === void 0 ? void 0 : target.removeEventListener('keydown', this.handleKeyDown);
67
+ this._adapter.unregisterEvent();
70
68
  }
71
69
  }
@@ -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: {
@@ -0,0 +1,5 @@
1
+ declare const cssClasses: {
2
+ readonly PREFIX: "semi-resizable";
3
+ };
4
+ declare const strings: {};
5
+ export { cssClasses, strings };
@@ -0,0 +1,6 @@
1
+ import { BASE_CLASS_PREFIX } from "../base/constants";
2
+ const cssClasses = {
3
+ PREFIX: `${BASE_CLASS_PREFIX}-resizable`
4
+ };
5
+ const strings = {};
6
+ export { cssClasses, 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,4 @@
1
+ import { ResizableHandlerFoundation, ResizableFoundation } from './single';
2
+ export { ResizableHandlerFoundation, ResizableFoundation };
3
+ import { ResizeGroupFoundation, ResizeItemFoundation, ResizeHandlerFoundation } from './group';
4
+ export { ResizeGroupFoundation, ResizeItemFoundation, ResizeHandlerFoundation };
@@ -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,262 @@
1
+ import { getItemDirection, getPixelSize } from "../utils";
2
+ import BaseFoundation from '../../base/foundation';
3
+ import { adjustNewSize, judgeConstraint, getOffset } from "../utils";
4
+ export class ResizeHandlerFoundation extends BaseFoundation {
5
+ constructor(adapter) {
6
+ super(Object.assign({}, adapter));
7
+ }
8
+ init() {
9
+ this._adapter.registerEvents();
10
+ }
11
+ destroy() {
12
+ this._adapter.unregisterEvents();
13
+ }
14
+ }
15
+ export class ResizeItemFoundation extends BaseFoundation {
16
+ constructor(adapter) {
17
+ super(Object.assign({}, adapter));
18
+ }
19
+ init() {}
20
+ destroy() {}
21
+ }
22
+ export class ResizeGroupFoundation extends BaseFoundation {
23
+ constructor(adapter) {
24
+ super(Object.assign({}, adapter));
25
+ this.registerEvents = () => {
26
+ this._adapter.registerEvents();
27
+ };
28
+ this.unregisterEvents = () => {
29
+ this._adapter.unregisterEvents();
30
+ };
31
+ this.onResizeStart = (handlerIndex, e) => {
32
+ let {
33
+ clientX,
34
+ clientY
35
+ } = e;
36
+ let lastItem = this._adapter.getItem(handlerIndex),
37
+ nextItem = this._adapter.getItem(handlerIndex + 1);
38
+ let lastOffset, nextOffset;
39
+ // offset caused by padding and border
40
+ const lastStyle = this.window.getComputedStyle(lastItem);
41
+ const nextStyle = this.window.getComputedStyle(nextItem);
42
+ lastOffset = getOffset(lastStyle, this.direction);
43
+ nextOffset = getOffset(nextStyle, this.direction);
44
+ const states = this.getStates();
45
+ this.setState({
46
+ isResizing: true,
47
+ originalPosition: {
48
+ x: clientX,
49
+ y: clientY,
50
+ lastItemSize: this.direction === 'horizontal' ? lastItem.offsetWidth : lastItem.offsetHeight,
51
+ nextItemSize: this.direction === 'horizontal' ? nextItem.offsetWidth : nextItem.offsetHeight,
52
+ lastOffset,
53
+ nextOffset
54
+ },
55
+ backgroundStyle: Object.assign(Object.assign({}, states.backgroundStyle), {
56
+ cursor: this.window.getComputedStyle(e.target).cursor || 'auto'
57
+ }),
58
+ curHandler: handlerIndex
59
+ });
60
+ this.registerEvents();
61
+ let lastStart = this._adapter.getItemStart(handlerIndex),
62
+ nextStart = this._adapter.getItemStart(handlerIndex + 1);
63
+ let [lastDir, nextDir] = getItemDirection(this.direction);
64
+ if (lastStart) {
65
+ lastStart(e, lastDir);
66
+ }
67
+ if (nextStart) {
68
+ nextStart(e, nextDir);
69
+ }
70
+ };
71
+ this.onResizing = e => {
72
+ const state = this.getStates();
73
+ if (!state.isResizing) {
74
+ return;
75
+ }
76
+ const {
77
+ curHandler,
78
+ originalPosition
79
+ } = state;
80
+ let {
81
+ x: initX,
82
+ y: initY,
83
+ lastItemSize,
84
+ nextItemSize,
85
+ lastOffset,
86
+ nextOffset
87
+ } = originalPosition;
88
+ let {
89
+ clientX,
90
+ clientY
91
+ } = e;
92
+ const props = this.getProps();
93
+ const {
94
+ direction
95
+ } = props;
96
+ let lastItem = this._adapter.getItem(curHandler),
97
+ nextItem = this._adapter.getItem(curHandler + 1);
98
+ let parentSize = this.direction === 'horizontal' ? this.groupRef.offsetWidth : this.groupRef.offsetHeight;
99
+ let availableSize = parentSize - this.totalMinus;
100
+ let delta = direction === 'horizontal' ? clientX - initX : clientY - initY;
101
+ let lastNewSize = lastItemSize + delta;
102
+ let nextNewSize = nextItemSize - delta;
103
+ // 判断是否超出限制
104
+ let lastFlag = judgeConstraint(lastNewSize, this._adapter.getItemMin(curHandler), this._adapter.getItemMax(curHandler), availableSize, lastOffset),
105
+ nextFlag = judgeConstraint(nextNewSize, this._adapter.getItemMin(curHandler + 1), this._adapter.getItemMax(curHandler + 1), availableSize, nextOffset);
106
+ if (lastFlag) {
107
+ lastNewSize = adjustNewSize(lastNewSize, this._adapter.getItemMin(curHandler), this._adapter.getItemMax(curHandler), availableSize, lastOffset);
108
+ nextNewSize = lastItemSize + nextItemSize - lastNewSize;
109
+ }
110
+ if (nextFlag) {
111
+ nextNewSize = adjustNewSize(nextNewSize, this._adapter.getItemMin(curHandler + 1), this._adapter.getItemMax(curHandler + 1), availableSize, nextOffset);
112
+ lastNewSize = lastItemSize + nextItemSize - nextNewSize;
113
+ }
114
+ if (direction === 'horizontal') {
115
+ lastItem.style.width = lastNewSize / parentSize * 100 + '%';
116
+ nextItem.style.width = nextNewSize / parentSize * 100 + '%';
117
+ } else if (direction === 'vertical') {
118
+ lastItem.style.height = lastNewSize / parentSize * 100 + '%';
119
+ nextItem.style.height = nextNewSize / parentSize * 100 + '%';
120
+ }
121
+ let lastFunc = this._adapter.getItemChange(curHandler),
122
+ nextFunc = this._adapter.getItemChange(curHandler + 1);
123
+ let [lastDir, nextDir] = getItemDirection(this.direction);
124
+ if (lastFunc) {
125
+ lastFunc({
126
+ width: lastItem.offsetWidth,
127
+ height: lastItem.offsetHeight
128
+ }, e, lastDir);
129
+ }
130
+ if (nextFunc) {
131
+ nextFunc({
132
+ width: nextItem.offsetWidth,
133
+ height: nextItem.offsetHeight
134
+ }, e, nextDir);
135
+ }
136
+ };
137
+ this.onResizeEnd = e => {
138
+ const {
139
+ curHandler
140
+ } = this.getStates();
141
+ let lastItem = this._adapter.getItem(curHandler),
142
+ nextItem = this._adapter.getItem(curHandler + 1);
143
+ let lastFunc = this._adapter.getItemEnd(curHandler),
144
+ nextFunc = this._adapter.getItemEnd(curHandler + 1);
145
+ let [lastDir, nextDir] = getItemDirection(this.direction);
146
+ if (lastFunc) {
147
+ lastFunc({
148
+ width: lastItem.offsetWidth,
149
+ height: lastItem.offsetHeight
150
+ }, e, lastDir);
151
+ }
152
+ if (nextFunc) {
153
+ nextFunc({
154
+ width: nextItem.offsetWidth,
155
+ height: nextItem.offsetHeight
156
+ }, e, nextDir);
157
+ }
158
+ this.setState({
159
+ isResizing: false,
160
+ curHandler: null
161
+ });
162
+ this.unregisterEvents();
163
+ };
164
+ this.calculateSpace = () => {
165
+ const props = this.getProps();
166
+ const {
167
+ direction
168
+ } = props;
169
+ // calculate accurate space for group item
170
+ let handlerSizes = new Array(this._adapter.getHandlerCount()).fill(0);
171
+ let groupSize = direction === 'horizontal' ? this.groupRef.offsetWidth : this.groupRef.offsetHeight;
172
+ this.totalMinus = 0;
173
+ for (let i = 0; i < this._adapter.getHandlerCount(); i++) {
174
+ let handlerSize = direction === 'horizontal' ? this._adapter.getHandler(i).offsetWidth : this._adapter.getHandler(i).offsetHeight;
175
+ handlerSizes[i] = handlerSize;
176
+ this.totalMinus += handlerSize;
177
+ }
178
+ // allocate size for items which don't have default size
179
+ let totalSizePercent = 0;
180
+ let undefineLoc = new Map(),
181
+ undefinedTotal = 0; // proportion
182
+ for (let i = 0; i < this._adapter.getItemCount(); i++) {
183
+ if (i === 0) {
184
+ this.itemMinusMap.set(i, handlerSizes[i] / 2);
185
+ } else if (i === this._adapter.getItemCount() - 1) {
186
+ this.itemMinusMap.set(i, handlerSizes[i - 1] / 2);
187
+ } else {
188
+ this.itemMinusMap.set(i, handlerSizes[i - 1] / 2 + handlerSizes[i] / 2);
189
+ }
190
+ const child = this._adapter.getItem(i);
191
+ let minSize = this._adapter.getItemMin(i),
192
+ maxSize = this._adapter.getItemMax(i);
193
+ let minSizePercent = minSize ? getPixelSize(minSize, groupSize) / groupSize * 100 : 0,
194
+ maxSizePercent = maxSize ? getPixelSize(maxSize, groupSize) / groupSize * 100 : 100;
195
+ if (minSizePercent > maxSizePercent) {
196
+ console.warn('[Semi ResizableItem]: min size bigger than max size');
197
+ }
198
+ let defaultSize = this._adapter.getItemDefaultSize(i);
199
+ if (defaultSize) {
200
+ let itemSizePercent;
201
+ if (typeof defaultSize === 'string') {
202
+ if (defaultSize.endsWith('%')) {
203
+ itemSizePercent = parseFloat(defaultSize.slice(0, -1));
204
+ } else if (defaultSize.endsWith('px')) {
205
+ itemSizePercent = parseFloat(defaultSize.slice(0, -2)) / groupSize * 100;
206
+ } else if (/^-?\d+(\.\d+)?$/.test(defaultSize)) {
207
+ // 仅由数字组成,表示按比例分配剩下空间
208
+ undefineLoc.set(i, parseFloat(defaultSize));
209
+ undefinedTotal += parseFloat(defaultSize);
210
+ continue;
211
+ }
212
+ } else {
213
+ undefineLoc.set(i, defaultSize);
214
+ undefinedTotal += defaultSize;
215
+ continue;
216
+ }
217
+ totalSizePercent += itemSizePercent;
218
+ if (direction === 'horizontal') {
219
+ child.style.width = `calc(${itemSizePercent}% - ${this.itemMinusMap.get(i)}px)`;
220
+ } else {
221
+ child.style.height = `calc(${itemSizePercent}% - ${this.itemMinusMap.get(i)}px)`;
222
+ }
223
+ if (itemSizePercent < minSizePercent) {
224
+ console.warn('[Semi ResizableGroup]: item size smaller than min size');
225
+ }
226
+ if (itemSizePercent > maxSizePercent) {
227
+ console.warn('[Semi ResizableGroup]: item size bigger than max size');
228
+ }
229
+ } else {
230
+ undefineLoc.set(i, 1);
231
+ undefinedTotal += 1;
232
+ }
233
+ }
234
+ let undefineSizePercent = 100 - totalSizePercent;
235
+ if (totalSizePercent > 100) {
236
+ console.warn('[Semi ResizableGroup]: total Size bigger than 100%');
237
+ undefineSizePercent = 10; // 如果总和超过100%,则保留10%的空间均分给未定义的item
238
+ }
239
+ undefineLoc.forEach((value, key) => {
240
+ const child = this._adapter.getItem(key);
241
+ if (direction === 'horizontal') {
242
+ child.style.width = `calc(${undefineSizePercent / undefinedTotal * value}% - ${this.itemMinusMap.get(key)}px)`;
243
+ } else {
244
+ child.style.height = `calc(${undefineSizePercent / undefinedTotal * value}% - ${this.itemMinusMap.get(key)}px)`;
245
+ }
246
+ });
247
+ };
248
+ }
249
+ get groupRef() {
250
+ return this._adapter.getGroupRef();
251
+ }
252
+ init() {
253
+ this.direction = this.getProp('direction');
254
+ this.itemMinusMap = new Map();
255
+ this.calculateSpace();
256
+ }
257
+ get window() {
258
+ var _a;
259
+ return (_a = this.groupRef.ownerDocument.defaultView) !== null && _a !== void 0 ? _a : null;
260
+ }
261
+ destroy() {}
262
+ }
@@ -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,19 @@
1
+ // group
2
+ const rowStyleBase = {
3
+ width: '100%',
4
+ height: '8px',
5
+ flexShrink: 0,
6
+ margin: '0',
7
+ cursor: 'row-resize'
8
+ };
9
+ const colStyleBase = {
10
+ width: '8px',
11
+ flexShrink: 0,
12
+ height: '100%',
13
+ margin: '0',
14
+ cursor: 'col-resize'
15
+ };
16
+ export const directionStyles = {
17
+ horizontal: Object.assign({}, colStyleBase),
18
+ vertical: Object.assign({}, rowStyleBase)
19
+ };