2018-10-17 12:38:25 +03:00
|
|
|
/*
|
|
|
|
Copyright 2018 New Vector Ltd
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2018-10-17 14:42:30 +03:00
|
|
|
/**
|
|
|
|
distributors translate a moving cursor into
|
|
|
|
CSS/DOM changes by calling the sizer
|
|
|
|
|
2018-11-26 18:42:58 +03:00
|
|
|
they have two methods:
|
|
|
|
`resize` receives then new item size
|
|
|
|
`resizeFromContainerOffset` receives resize handle location
|
|
|
|
within the container bounding box. For internal use.
|
|
|
|
This method usually ends up calling `resize` once the start offset is subtracted.
|
2018-10-17 14:42:30 +03:00
|
|
|
the offset from the container edge of where
|
|
|
|
the mouse cursor is.
|
|
|
|
*/
|
2018-09-24 18:07:42 +03:00
|
|
|
class FixedDistributor {
|
2018-12-20 01:51:19 +03:00
|
|
|
constructor(item) {
|
2018-10-16 17:25:00 +03:00
|
|
|
this.item = item;
|
2018-12-20 01:51:19 +03:00
|
|
|
this.beforeOffset = item.offset();
|
2018-09-24 18:07:42 +03:00
|
|
|
}
|
|
|
|
|
2018-12-20 01:51:19 +03:00
|
|
|
resize(size) {
|
|
|
|
this.item.setSize(size);
|
2018-09-24 18:07:42 +03:00
|
|
|
}
|
|
|
|
|
2018-11-26 18:42:58 +03:00
|
|
|
resizeFromContainerOffset(offset) {
|
|
|
|
this.resize(offset - this.beforeOffset);
|
2018-09-24 18:07:42 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class CollapseDistributor extends FixedDistributor {
|
2018-12-20 01:51:19 +03:00
|
|
|
constructor(item, sizer, _container, config) {
|
|
|
|
super(item);
|
2018-10-16 15:56:49 +03:00
|
|
|
this.toggleSize = config && config.toggleSize;
|
|
|
|
this.onCollapsed = config && config.onCollapsed;
|
2018-10-16 19:43:13 +03:00
|
|
|
this.isCollapsed = false;
|
2018-09-24 18:07:42 +03:00
|
|
|
}
|
|
|
|
|
2018-11-26 18:42:58 +03:00
|
|
|
resize(newSize) {
|
2018-10-16 19:43:13 +03:00
|
|
|
const isCollapsedSize = newSize < this.toggleSize;
|
|
|
|
if (isCollapsedSize && !this.isCollapsed) {
|
|
|
|
this.isCollapsed = true;
|
2018-10-16 15:56:49 +03:00
|
|
|
if (this.onCollapsed) {
|
|
|
|
this.onCollapsed(true, this.item);
|
|
|
|
}
|
2018-10-17 14:36:15 +03:00
|
|
|
} else if (!isCollapsedSize && this.isCollapsed) {
|
2018-10-16 15:56:49 +03:00
|
|
|
if (this.onCollapsed) {
|
|
|
|
this.onCollapsed(false, this.item);
|
|
|
|
}
|
2018-10-16 19:43:13 +03:00
|
|
|
this.isCollapsed = false;
|
|
|
|
}
|
|
|
|
if (!isCollapsedSize) {
|
2018-11-26 18:42:58 +03:00
|
|
|
super.resize(newSize);
|
2018-09-24 18:07:42 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
FixedDistributor,
|
|
|
|
CollapseDistributor,
|
|
|
|
};
|