mirror of
https://github.com/smartxworks/sunmao-ui.git
synced 2024-11-21 03:15:49 +08:00
fix code
This commit is contained in:
parent
70d4a1587f
commit
5b805b715a
@ -9,18 +9,20 @@ describe('AppModel test', () => {
|
||||
expect(appModel.allComponents.length).toBe(10);
|
||||
expect(appModel.topComponents.length).toBe(2);
|
||||
});
|
||||
|
||||
it('components order', () => {
|
||||
expect(appModel.allComponents[0].id).toBe('hstack1');
|
||||
expect(appModel.allComponents[1].id).toBe('vstack1');
|
||||
expect(appModel.allComponents[2].id).toBe('text3');
|
||||
expect(appModel.allComponents[3].id).toBe('text4');
|
||||
expect(appModel.allComponents[4].id).toBe('hstack2');
|
||||
expect(appModel.allComponents[5].id).toBe('text1');
|
||||
expect(appModel.allComponents[6].id).toBe('text2');
|
||||
expect(appModel.allComponents[7].id).toBe('button1');
|
||||
expect(appModel.allComponents[8].id).toBe('moduleContainer1');
|
||||
expect(appModel.allComponents[9].id).toBe('apiFetch');
|
||||
const order = [
|
||||
'hstack1',
|
||||
'vstack1',
|
||||
'text3',
|
||||
'text4',
|
||||
'hstack2',
|
||||
'text1',
|
||||
'text2',
|
||||
'button1',
|
||||
'moduleContainer1',
|
||||
'apiFetch',
|
||||
];
|
||||
expect(appModel.allComponents.map(c => c.id)).toEqual(order);
|
||||
});
|
||||
|
||||
it('detect duplicated dd', () => {
|
||||
|
@ -1,4 +1,8 @@
|
||||
import { ApplicationComponent, MethodSchema, RuntimeComponentSpec } from '@sunmao-ui/core';
|
||||
import {
|
||||
ApplicationComponent,
|
||||
MethodSchema,
|
||||
RuntimeComponentSpec,
|
||||
} from '@sunmao-ui/core';
|
||||
import { registry } from '../setup';
|
||||
import { genComponent, genTrait } from './utils';
|
||||
import {
|
||||
@ -219,7 +223,9 @@ export class ComponentModel implements IComponentModel {
|
||||
}
|
||||
// update model
|
||||
siblings.splice(siblings.indexOf(this), 1);
|
||||
const afterIndexInSiblings = after ? siblings.findIndex(c => c === after) + 1 : 0;
|
||||
const afterIndexInSiblings = after
|
||||
? siblings.findIndex(c => c.id === after.id) + 1
|
||||
: 0;
|
||||
siblings.splice(afterIndexInSiblings, 0, this);
|
||||
return this;
|
||||
}
|
||||
|
@ -9,14 +9,14 @@ export type RemoveComponentLeafOperationContext = {
|
||||
|
||||
export class RemoveComponentLeafOperation extends BaseLeafOperation<RemoveComponentLeafOperationContext> {
|
||||
private deletedComponent?: IComponentModel;
|
||||
private beforeComponent?: IComponentModel;
|
||||
private prevComponent?: IComponentModel;
|
||||
|
||||
do(prev: ApplicationComponent[]): ApplicationComponent[] {
|
||||
const appModel = new AppModel(prev);
|
||||
this.deletedComponent = appModel.getComponentById(
|
||||
this.context.componentId as ComponentId
|
||||
);
|
||||
this.beforeComponent = this.deletedComponent?.prevSilbling || undefined;
|
||||
this.prevComponent = this.deletedComponent?.prevSilbling || undefined;
|
||||
appModel.removeComponent(this.context.componentId as ComponentId);
|
||||
return appModel.toSchema();
|
||||
}
|
||||
@ -41,7 +41,7 @@ export class RemoveComponentLeafOperation extends BaseLeafOperation<RemoveCompon
|
||||
} else {
|
||||
appModel.appendChild(this.deletedComponent);
|
||||
}
|
||||
this.deletedComponent.moveAfter(this.beforeComponent || null);
|
||||
this.deletedComponent.moveAfter(this.prevComponent || null);
|
||||
return appModel.toSchema();
|
||||
}
|
||||
}
|
||||
|
@ -109,7 +109,6 @@ class EventHandlerValidatorRule implements TraitValidatorRule {
|
||||
|
||||
if (method.parameters && !ajv.validate(method.parameters, parameters)) {
|
||||
ajv.errors!.forEach(error => {
|
||||
JSON;
|
||||
if (error.keyword === 'type') {
|
||||
const { instancePath } = error;
|
||||
const path = instancePath.split('/')[1];
|
||||
|
Loading…
Reference in New Issue
Block a user