MagicBox pro version.
npm install @whalecloud/magic-box-pro
json
{
index: 0,
id: 'df019a54-e3fb-40f8-b916-d2cde8325475',
pid: -1,
childNodes: [
{
type: 'MRow',
id: '9c40cfe6-c6ff-418f-8ae6-5e1818189172',
title: 'MRow',
pid: 'df019a54-e3fb-40f8-b916-d2cde8325475',
index: 0,
childNodes: [
{
type: 'MCol',
id: '9d027c88-ad6d-43c3-850e-ab8bae6b8ab4',
title: 'MCol',
pid: '9c40cfe6-c6ff-418f-8ae6-5e1818189172',
index: 0,
childNodes: [
{
type: 'GalaryTemplate4',
id: '80c970f7-5f30-4f72-b6a9-455399ac2aea',
title: '4 Images',
pid: '9d027c88-ad6d-43c3-850e-ab8bae6b8ab4',
index: 0,
},
],
},
],
}
...
`
$3
├─assets
│ └─imgs
├─components
│ ├─assets
│ │ ├─IconBase64
│ │ └─imgs
│ ├─core
│ │ ├─core-layout-component
│ │ │ ├─MCol
│ │ │ └─MRow
│ │ ├─design-view
│ │ │ ├─DesignView
│ │ │ ├─MainArea
│ │ │ ├─PropertyPanelContainer
│ │ │ ├─SideBar
│ │ │ └─TopBar
│ │ ├─designers
│ │ │ ├─PadDesigner
│ │ │ ├─PCDesigner
│ │ │ └─PhoneDesigner
│ │ ├─PreviewView
│ │ └─renderers
│ │ ├─PadRenderer
│ │ ├─PCRenderer
│ │ └─PhoneRenderer
│ ├─MComponents
│ │ ├─basic
│ │ │ ├─MImg
│ │ │ ├─MText
│ │ │ └─MVideo
│ │ ├─charts
│ │ │ └─MLineChart
│ │ ├─mobile
│ │ │ ├─MBanner
│ │ │ ├─MFlashSale
│ │ │ ├─MFlashService
│ │ │ ├─MGroup
│ │ │ ├─MGroupGoods
│ │ │ ├─MGroupParticipants
│ │ │ ├─MIconGrid
│ │ │ ├─MPageTitle
│ │ │ ├─MRecommend
│ │ │ ├─MSearchBar
│ │ │ └─MTabs
│ │ ├─pc
│ │ │ ├─GalaryTemplate4
│ │ │ ├─MCard
│ │ │ ├─MCarousel
│ │ │ ├─MCatalogMenu
│ │ │ ├─MFlashSales
│ │ │ ├─MMultipleBanners
│ │ │ ├─MNav
│ │ │ ├─MProductList
│ │ │ └─MScroll
│ │ └─um
│ │ └─MBanner-um
│ ├─property-panels
│ │ ├─components
│ │ │ ├─AddImgLink
│ │ │ ├─BottomButton
│ │ │ ├─ColorPicker
│ │ │ ├─CommonStyle
│ │ │ ├─FilteredProductModal
│ │ │ ├─LinkModal
│ │ │ ├─ProductDetailPage
│ │ │ ├─ProductList
│ │ │ └─ProductModal
│ │ ├─GalaryTemplate4Properties
│ │ ├─MCardProperties
│ │ ├─MCarouselProperties
│ │ ├─MCatalogMenuProperties
│ │ ├─MColProperties
│ │ ├─MFlashSalesProperties
│ │ ├─MFlashServiceProperties
│ │ ├─MIconGridProperties
│ │ ├─MImgProperties
│ │ ├─MMGroupGoodsProperties
│ │ ├─MMParticipantsProperties
│ │ ├─MMShareByProperties
│ │ ├─MMTitleProperties
│ │ ├─MMultipleBannersProperties
│ │ ├─MNavProperties
│ │ ├─MPlotAreaProperties
│ │ ├─MProductListProperties
│ │ ├─MRecommendProperties
│ │ ├─MScrollProperties
│ │ ├─MSearchBarProperties
│ │ ├─MStyleProperties
│ │ └─MTextProperties
│ └─utils
├─config
├─locale
│ ├─en_US
│ └─zh_CN
└─pages
├─designer-page
└─preview-page
$3
核心组件只有2个:
- MagicBox: 是整个设计器和渲染器的核心,MagicBox 在逻辑上可以看成超级 DIV,它在 DIV 的基础上增加了拖拽布局和渲染功能。重要:因为 react-dnd 目前只能支持函数式组件,所以这里只能写成函数形式。MagicBox 在 designer 模式和 renderer 模式下具有不同的外观和功能。MagicBox 切分成2个内部组件分别实现设计器和渲染器功能 DesignerBox 和 RendererBox。在 designer 模式下,具有拖拽布局功能。在 renderer 模式下纯展现,其功能退化成一层空的容器 div,不再具有拖拽交互功能。
- DropZone: 封装放置区域逻辑,当把对象拖动到 DropZone 并放开鼠标时,会触发 drop 动作。
MagicBox 和 DropZone 基于 react-dnd 进行了再次封装,它们是内部核心机制,设计器的外部调用方不需要关心这两个类的实现细节,只要关注暴露的参数即可,下是 MagicBox 的核心参数:
` javascript
id,
pid,
index,
nodeData,
children,
onHover,
onDrop,
componentMap,
acceptTypes = ['MagicBox', 'MRow'], //盒子内部可以接受的类型只有 MagicBox 和 MRow,MagicBox 默认可以接受自己,形成无限嵌套。
isValidDest = false,
canDrag = true,
isLeaf = false,
isSelected = false,
innerDirection = 'vertical',
``