UNPKG

@cainiaofe/cn-ui-layout

Version:

- 安装 cone-cli | [Cone-CLI 使用指引](https://alidocs.dingtalk.com/i/nodes/xdqZp24KneBJzvGM6XezJvyb7RA0Nr1E) - `tnpm i -g @alife/cone-cli@latest` - 安装依赖包 - `cone install` - 启动研发 - `cone start`

119 lines (110 loc) 5.51 kB
import { CELL, ROW, COL } from "../../../common/util/const"; /** * onSubtreeModified 是从叶子节点逐级冒泡, 注意做好判断 * options.isSubDeleting 是否因为父节点删除导致被连带删除。树根节点为 false,其他分支节点、叶子节点则为 true */ export var onNodeReplaceSelfWithChildrenCell = function onNodeReplaceSelfWithChildrenCell(currentNode, options) { var _children$get; var removeNode = options.removeNode, type = options.type, isSubDeleting = options.isSubDeleting; // console.log(currentNode, currentNode.children.length, e) // 必须到了触发节点,并且触发节点是子节点 if (!removeNode || !currentNode || type !== 'remove' || isSubDeleting || removeNode.parent !== currentNode) { return; } var children = currentNode.children; var componentName = children === null || children === void 0 ? void 0 : (_children$get = children.get(0)) === null || _children$get === void 0 ? void 0 : _children$get.componentName; // 只有一个子元素 Cell/Row/Col,则让子元素替代自己 if ((children === null || children === void 0 ? void 0 : children.size) === 1 && componentName && [CELL, ROW, COL].indexOf(componentName) > -1) { var child = children.get(0); var parent = currentNode.parent; child === null || child === void 0 ? void 0 : child.setPropValue('style', currentNode.getPropValue('style')); child === null || child === void 0 ? void 0 : child.setPropValue('width', currentNode.getPropValue('width')); child && (parent === null || parent === void 0 ? void 0 : parent.insertAfter(child, currentNode, false)); currentNode.remove(); } else if (children !== null && children !== void 0 && children.size && (children === null || children === void 0 ? void 0 : children.size) > 1) { // 同名节点提升 var sameNameChild = children.find(function (n) { return n.componentName === currentNode.componentName; }); if (sameNameChild !== null && sameNameChild !== void 0 && sameNameChild.children) { sameNameChild.children.reverse().forEach(function (n) { currentNode.insertAfter(n, sameNameChild, false); }); sameNameChild.remove(); } } }; /** * 容器元素不允许空着,无子节点的时候删除自己 * @param {*} removeNode * @param {*} currentNode * @returns boolean */ export var onNodeRemoveSelfWhileNoChildren = function onNodeRemoveSelfWhileNoChildren(removeNode, currentNode) { if (!removeNode || !currentNode) { return false; } var children = currentNode.children; // 若无 children, 删除组件本身 if (children && children.size === 0) { currentNode.remove(); return true; } return false; }; export function disableDivider() { var _iframe$contentWindow; var iframe = window.AliLowCodeEngine.project.simulatorHost; iframe && ((_iframe$contentWindow = iframe.contentWindow) === null || _iframe$contentWindow === void 0 ? void 0 : _iframe$contentWindow.dispatchEvent(new Event('dividerDisable'))); } export function enableDivider() { var _iframe$contentWindow2; var iframe = window.AliLowCodeEngine.project.simulatorHost; iframe && ((_iframe$contentWindow2 = iframe.contentWindow) === null || _iframe$contentWindow2 === void 0 ? void 0 : _iframe$contentWindow2.dispatchEvent(new Event('dividerEnable'))); } export var onDrageResize = { onResizeStart: function onResizeStart(e, currentNode) { disableDivider(); currentNode.startRect = currentNode.getRect(); currentNode.siblingNode = e.trigger === 'n' || e.trigger === 'w' ? currentNode.prevSibling : currentNode.nextSibling; currentNode.siblingRect = currentNode.siblingNode ? currentNode.siblingNode.getRect() : null; }, onResize: function onResize(e, currentNode) { var deltaY = e.deltaY, deltaX = e.deltaX; var _currentNode$startRec = currentNode.startRect, startHeight = _currentNode$startRec.height, startWidth = _currentNode$startRec.width; if (e.trigger === 'e' || e.trigger === 'w') { var newWidth = e.trigger === 'w' ? startWidth - deltaX : startWidth + deltaX; // currentNode.setPropValue('style.width', `${newWidth}px`); currentNode.setPropValue('width', newWidth); currentNode.getDOMNode().style.flex = "0 0 " + Math.round(newWidth) + "px"; // 去除兄弟节点的宽度 if (currentNode.siblingRect) { currentNode.siblingNode.setPropValue('width', undefined); currentNode.siblingNode.getDOMNode().style.flex = '1 1'; // const siblingStyle = currentNode.siblingNode.getPropValue('style'); // siblingStyle && (delete siblingStyle.width); // currentNode.siblingNode.setPropValue('style', siblingStyle); } } else if (e.trigger === 's' || e.trigger === 'n') { var newHeight = e.trigger === 'n' ? startHeight - deltaY : startHeight + deltaY; currentNode.setPropValue('style.minHeight', newHeight); currentNode.getDOMNode().style.flex = '0 0 auto'; // 去除兄弟节点的高度 if (currentNode.siblingRect) { currentNode.siblingNode.setPropValue('style.minHeight', undefined); currentNode.siblingNode.getDOMNode().style.flex = '1 1'; // const siblingStyle = currentNode.siblingNode.getPropValue('style'); // siblingStyle && (delete siblingStyle.height); // currentNode.siblingNode.setPropValue('style', siblingStyle); } } }, onResizeEnd: function onResizeEnd() { enableDivider(); } };