From b35b7b0d1a1ac714ed75461ade7082ad98088e8e Mon Sep 17 00:00:00 2001 From: chenshenhai Date: Fri, 6 Aug 2021 11:31:06 +0800 Subject: [PATCH] fix: select index and element-type --- docs/todo/core.md | 5 +++-- packages/core/src/lib/element.ts | 2 +- packages/types/src/lib/element.ts | 18 +++++++++++++++--- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/docs/todo/core.md b/docs/todo/core.md index 8e4d79b..a19a96d 100644 --- a/docs/todo/core.md +++ b/docs/todo/core.md @@ -1,7 +1,8 @@ # @idraw/core -* [] BUG: Type error about keyof TypeElemDesc -* [] BUG: Type error about TypeElement'uuid +* [] add type of TypeElemDesc-key +* [x] BUG: Type error about keyof TypeElemDesc +* [x] BUG: Type error about TypeElement'uuid * [] Element default data * [] Support gradient color * [] Listen keyboard action diff --git a/packages/core/src/lib/element.ts b/packages/core/src/lib/element.ts index 421e97c..95ae914 100644 --- a/packages/core/src/lib/element.ts +++ b/packages/core/src/lib/element.ts @@ -33,7 +33,7 @@ export class Element { const ctx = this._ctx; let idx = -1; let uuid = null; - for (let i = 0; i < data.elements.length; i++) { + for (let i = data.elements.length - 1; i >= 0; i--) { const ele = data.elements[i]; let bw = 0; // @ts-ignore diff --git a/packages/types/src/lib/element.ts b/packages/types/src/lib/element.ts index 8ed76d9..b2bb4e3 100644 --- a/packages/types/src/lib/element.ts +++ b/packages/types/src/lib/element.ts @@ -8,15 +8,15 @@ type TypeElementAttrs = { angle: number; } -type TypeElementBase = TypeElementAttrs & { +type TypeElementBase = TypeElementAttrs & { name?: string; uuid?: string; - type: T; + type: T | TypeElemType; lock?: boolean; desc: TypeElemDesc[T]; } -type TypeElement = TypeElementBase & { +type TypeElement = TypeElementBase & { uuid: string; } @@ -36,6 +36,17 @@ type TypeElemDesc = { // paint: TypeElemDescPaint, } +// enum TypeElemType { +// text = 'text', +// rect = 'rect', +// circle = 'circle', +// image = 'image', +// svg = 'svg', +// html = 'html', +// } + +type TypeElemType = 'text' | 'rect' | 'circle' | 'image' | 'svg' | 'html'; + type TypeElemDescRect = { color?: string; } & TypeElemBoxDesc @@ -77,6 +88,7 @@ export { TypeElemDescImage, TypeElemDescSVG, TypeElemDesc, + TypeElemType, TypeElement, TypeElementBase, }; \ No newline at end of file