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`

59 lines 2.75 kB
import _extends from "@babel/runtime/helpers/extends"; import { Fragment } from "react"; import $i18n from "../../locales/i18n"; import React, { useEffect } from 'react'; import { AddSection } from "../cn-layout-page/components/add-section"; import { BLOCK, SECTION, TILE } from "../../common/util/const"; import { createBlockSnippet, createSectionInitialChildren, createSectionSnippet } from "../../common/manager/setter-snippet"; import { initSingletonDivider } from "../cn-layout-cell/components/divider"; import { isDesignMode } from "../../common/util/util"; function addNewSection(_leaf) { var _leaf$schema; var prevSectionSchema = [].concat((_leaf === null || _leaf === void 0 ? void 0 : (_leaf$schema = _leaf.schema) === null || _leaf$schema === void 0 ? void 0 : _leaf$schema.children) || []).reverse().find(function (n) { return n.componentName === SECTION; }) || createSectionSnippet(); var prevBlockSchema = [].concat(prevSectionSchema === null || prevSectionSchema === void 0 ? void 0 : prevSectionSchema.children).reverse().find(function (n) { return n.componentName === TILE || n.componentName === BLOCK; }) || createBlockSnippet(); var prevBlockProps = _extends({}, prevBlockSchema.props); delete prevBlockProps.operation; var newSectionSchema = _extends({}, prevSectionSchema, { props: { normalStyle: { title: $i18n.get({ id: 'LayoutContainerTitle', dm: '布局容器标题' }) } }, children: createSectionInitialChildren() }); var realLeaf = _leaf; // const contentDom = _leaf?.getChildren?.()?.children?.[0]; // const { componentName } = contentDom || {} // if(componentName === 'CnLayoutContent') { // realLeaf = contentDom; // } realLeaf === null || realLeaf === void 0 ? void 0 : realLeaf.insertAfter(newSectionSchema); } var CnLayoutContent = function CnLayoutContent(props) { var _leaf$schema$children; var _ref = props || {}, children = _ref.children, _leaf = _ref._leaf; var hasSection = Array.isArray(_leaf === null || _leaf === void 0 ? void 0 : _leaf.schema.children) && (_leaf === null || _leaf === void 0 ? void 0 : (_leaf$schema$children = _leaf.schema.children) === null || _leaf$schema$children === void 0 ? void 0 : _leaf$schema$children.length); useEffect(function () { if (isDesignMode(props)) { // 加载切割的交互能力 initSingletonDivider(); } }, []); return /*#__PURE__*/React.createElement(React.Fragment, null, children, /*#__PURE__*/React.createElement(AddSection, { onClick: function onClick() { return addNewSection(_leaf); }, alwaysShow: !hasSection })); }; CnLayoutContent.displayName = 'CnLayoutContent'; export default CnLayoutContent;