@composy/layout-elements
v0.0.2
Published
Light DOM custom elements for LDesign Layout
Readme
@composy/layout-elements
LDesign 布局的原生 Web Component,把 LayoutDocument 渲染到浏览器 DOM。
安装
pnpm add @composy/layout-elements @composy/layout-core @composy/layout-runtime目录结构
src/
├── index.ts
└── elements.ts # LDesignGridElement核心 API
类
| 类 | 说明 |
| -------------------- | ------------------------------------------------------- |
| LDesignGridElement | 继承 HTMLElement,observedAttributes=['breakpoint'] |
属性
| 属性 | 类型 | 说明 |
| ---------------- | ------------------------------------------ | ---------------------------- |
| layoutDocument | LayoutDocument \| undefined | 布局文档,更新后自动触发渲染 |
| materials | MaterialRegistry \| MaterialDefinition[] | 物料注册表 |
| breakpoint | string \| undefined | 当前断点 ID |
使用示例
<script type="module">
import { LDesignGridElement } from '@composy/layout-elements'
import { createLayoutDocument } from '@composy/layout-core'
customElements.define('ldesign-grid', LDesignGridElement)
</script>
<ldesign-grid breakpoint="lg"></ldesign-grid>
<script>
const el = document.querySelector('ldesign-grid')
el.layoutDocument = createLayoutDocument({
version: 1,
name: 'App',
defaultBreakpointId: 'lg',
breakpoints: [{ id: 'lg', min: 1024 }],
items: [
{ id: 'p1', type: 'panel', placement: { grid: [0, 0, 4, 3] } },
{ id: 'p2', type: 'panel', placement: { grid: [0, 3, 4, 6] } },
],
})
</script>构建脚本 & 验证命令
pnpm build
pnpm type-check产物说明
es//lib//dist/。
备注
- 仅在浏览器环境注册;Node/SSR 安全。
- 运行时读取物料的 Web Component 或 HTML descriptor 自动创建节点。
