mirror of
https://github.com/idrawjs/idraw
synced 2026-05-24 10:08:34 +00:00
feat: improve parser for component toelement
This commit is contained in:
parent
6061cffa34
commit
58d9953eb1
3 changed files with 25 additions and 4 deletions
|
|
@ -83,6 +83,7 @@ export function createButton(name: string) {
|
|||
w: 800,
|
||||
h: 400,
|
||||
desc: {
|
||||
bgColor: '#aaaaaa54',
|
||||
default: createButtonItem('default'),
|
||||
variants: [createButtonItem('primary'), createButtonItem('secondary')]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -83,6 +83,7 @@ export function createCheckbox(name: string) {
|
|||
w: 800,
|
||||
h: 400,
|
||||
desc: {
|
||||
bgColor: '#aaaaaa54',
|
||||
default: createCheckboxItem('default'),
|
||||
variants: [createCheckboxItem('primary'), createCheckboxItem('secondary')]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,21 @@
|
|||
import { deepClone } from '@idraw/util';
|
||||
import type { Data, Element } from '@idraw/types';
|
||||
import type { Data, Element, ElementType, ElementBaseDesc } from '@idraw/types';
|
||||
import type { DesignComponent, DesignComponentItem } from '../types';
|
||||
|
||||
const baseDescKeys = ['borderWidth', 'borderColor', 'borderRadius', 'shadowColor', 'shadowOffsetX', 'shadowOffsetY', 'shadowBlur', 'color', 'bgColor'];
|
||||
|
||||
function parseElementBaseDesc(elem: DesignComponent | DesignComponentItem | Element<ElementType>): ElementBaseDesc {
|
||||
const baseDesc: ElementBaseDesc = {};
|
||||
if (elem?.desc) {
|
||||
Object.keys(elem.desc).forEach((name: string) => {
|
||||
if (baseDescKeys.includes(name)) {
|
||||
baseDesc[name as keyof ElementBaseDesc] = (elem.desc as any)?.[name];
|
||||
}
|
||||
});
|
||||
}
|
||||
return baseDesc;
|
||||
}
|
||||
|
||||
function parseComponentItemToElement(item: DesignComponentItem): Element<'group'> {
|
||||
const elem: Element<'group'> = {
|
||||
uuid: item.uuid,
|
||||
|
|
@ -12,8 +26,10 @@ function parseComponentItemToElement(item: DesignComponentItem): Element<'group'
|
|||
w: item.w,
|
||||
h: item.h,
|
||||
desc: {
|
||||
...item.desc,
|
||||
children: []
|
||||
...parseElementBaseDesc(item),
|
||||
...{
|
||||
children: []
|
||||
}
|
||||
}
|
||||
};
|
||||
item.desc?.children?.forEach?.((child) => {
|
||||
|
|
@ -38,7 +54,10 @@ function parseComponentToElement(comp: DesignComponent): Element<'group'> {
|
|||
w: comp.w,
|
||||
h: comp.h,
|
||||
desc: {
|
||||
children: []
|
||||
...parseElementBaseDesc(comp),
|
||||
...{
|
||||
children: []
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue