mirror of
https://github.com/smartxworks/sunmao-ui.git
synced 2024-11-21 03:15:49 +08:00
make spec of create functions optional
This commit is contained in:
parent
451590b581
commit
2362940bb5
@ -27,10 +27,37 @@ export type RuntimeComponentSpec = Component & {
|
||||
parsedVersion: Version;
|
||||
};
|
||||
|
||||
export function createComponent(options: Omit<Component, 'kind'>): RuntimeComponentSpec {
|
||||
return {
|
||||
...options,
|
||||
kind: 'Component',
|
||||
parsedVersion: parseVersion(options.version),
|
||||
};
|
||||
// partial some fields, use as param createComponent
|
||||
export type ComponentDefinition = {
|
||||
version: string;
|
||||
metadata: Partial<ComponentMetadata> & { name: string };
|
||||
spec?: Partial<ComponentSpec>;
|
||||
};
|
||||
|
||||
export function createComponent(options: ComponentDefinition): RuntimeComponentSpec {
|
||||
return (
|
||||
{
|
||||
version: options.version,
|
||||
kind: ('Component' as any),
|
||||
parsedVersion: parseVersion(options.version),
|
||||
metadata: {
|
||||
description: '',
|
||||
isDraggable: true,
|
||||
isResizable: true,
|
||||
displayName: options.metadata.name,
|
||||
exampleProperties: {},
|
||||
exampleSize: [1, 1],
|
||||
...options.metadata,
|
||||
},
|
||||
spec: {
|
||||
properties: {},
|
||||
state: {},
|
||||
methods: [],
|
||||
styleSlots: [],
|
||||
slots: [],
|
||||
events: [],
|
||||
...options.spec,
|
||||
},
|
||||
}
|
||||
);
|
||||
}
|
||||
|
@ -23,10 +23,27 @@ export type RuntimeModuleSpec = Module & {
|
||||
parsedVersion: Version;
|
||||
};
|
||||
|
||||
export function createModule(options: Omit<Module, 'kind'>): RuntimeModuleSpec {
|
||||
// partial some fields, use as param createModule
|
||||
export type ModuleDefinition = {
|
||||
version: string;
|
||||
metadata: Metadata;
|
||||
spec?: Partial<ModuleSpec>;
|
||||
};
|
||||
|
||||
export function createModule(options: ModuleDefinition): RuntimeModuleSpec {
|
||||
return {
|
||||
...options,
|
||||
version: options.version,
|
||||
kind: 'Module',
|
||||
parsedVersion: parseVersion(options.version),
|
||||
metadata: {
|
||||
name: options.metadata.name,
|
||||
description: options.metadata.description,
|
||||
},
|
||||
spec: {
|
||||
properties: {},
|
||||
events: [],
|
||||
stateMap: {},
|
||||
...options.spec
|
||||
},
|
||||
};
|
||||
}
|
||||
|
@ -23,10 +23,29 @@ export type RuntimeTraitSpec = Trait & {
|
||||
parsedVersion: Version;
|
||||
};
|
||||
|
||||
export function createTrait(options: Omit<Trait, 'kind'>): RuntimeTraitSpec {
|
||||
return {
|
||||
...options,
|
||||
kind: 'Trait',
|
||||
parsedVersion: parseVersion(options.version),
|
||||
};
|
||||
// partial some fields, use as param createTrait
|
||||
export type TraitDefinition = {
|
||||
version: string;
|
||||
metadata: Metadata;
|
||||
spec?: Partial<TraitSpec>;
|
||||
};
|
||||
|
||||
export function createTrait(options: TraitDefinition): RuntimeTraitSpec {
|
||||
return (
|
||||
{
|
||||
version: options.version,
|
||||
kind: ('Trait' as any),
|
||||
parsedVersion: parseVersion(options.version),
|
||||
metadata: {
|
||||
name: options.metadata.name,
|
||||
description: options.metadata.description,
|
||||
},
|
||||
spec: {
|
||||
properties: {},
|
||||
state: {},
|
||||
methods: [],
|
||||
...options.spec
|
||||
},
|
||||
}
|
||||
);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user