diff --git a/packages/idraw/src/idraw.ts b/packages/idraw/src/idraw.ts index 45091727f..567cc8767 100644 --- a/packages/idraw/src/idraw.ts +++ b/packages/idraw/src/idraw.ts @@ -151,7 +151,7 @@ export class iDraw { this.#core.off(name, callback); } - trigger(name: T, e: IDrawEvent[T]) { + trigger(name: T, e?: IDrawEvent[T]) { this.#core.trigger(name, e); } @@ -212,10 +212,11 @@ export class iDraw { ): Data { const core = this.#core; const data: Data = core.getData() || { elements: [] }; - if (!opts) { + if (!opts || !opts?.position?.length) { data.elements.push(element); } else if (opts?.position) { - insertElementToListByPosition(element, opts?.position, data.elements); + const position = [...opts?.position]; + insertElementToListByPosition(element, position, data.elements); } core.setData(data); core.refresh(); diff --git a/packages/util/src/lib/event.ts b/packages/util/src/lib/event.ts index 63dcca89d..316ca5c8d 100644 --- a/packages/util/src/lib/event.ts +++ b/packages/util/src/lib/event.ts @@ -32,7 +32,7 @@ export class EventEmitter> implements UtilEventEmi } } - trigger(eventKey: K, e: T[K]) { + trigger(eventKey: K, e?: T[K]) { const callbacks = this.#listeners.get(eventKey); if (Array.isArray(callbacks)) { callbacks.forEach((cb) => {