Skip to content

Commit

Permalink
refactor(stage): node-list转成数组使用array.from
Browse files Browse the repository at this point in the history
  • Loading branch information
roymondchen committed Oct 20, 2023
1 parent 921867f commit 0402568
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 7 deletions.
6 changes: 3 additions & 3 deletions packages/stage/src/MoveableOptionsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export default class MoveableOptionsManager extends EventEmitter {
* @param selectedElList 选中的元素列表,需要排除在对齐元素之外
* @param allElList 全部元素列表
*/
protected setElementGuidelines(selectedElList: HTMLElement[], allElList: HTMLElement[]): void {
protected setElementGuidelines(selectedElList: HTMLElement[], allElList: Element[]): void {
this.elementGuidelines.forEach((node) => {
node.remove();
});
Expand Down Expand Up @@ -224,7 +224,7 @@ export default class MoveableOptionsManager extends EventEmitter {
* @param allElList 全部元素列表
* @returns frame 辅助对齐元素集合的页面片
*/
private createGuidelineElements(selectedElList: HTMLElement[], allElList: HTMLElement[]): DocumentFragment {
private createGuidelineElements(selectedElList: HTMLElement[], allElList: Element[]): DocumentFragment {
const frame = globalThis.document.createDocumentFragment();

for (const node of allElList) {
Expand All @@ -246,7 +246,7 @@ export default class MoveableOptionsManager extends EventEmitter {
* @param eleList 元素列表
* @returns 是否在元素列表里面
*/
private isInElementList(ele: HTMLElement, eleList: HTMLElement[]): boolean {
private isInElementList(ele: Element, eleList: Element[]): boolean {
for (const eleItem of eleList) {
if (ele === eleItem) return true;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/stage/src/StageDragResize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export default class StageDragResize extends MoveableOptionsManager {
this.dragResizeHelper.setMode(this.mode);

// 设置选中元素的周围元素,用于选中元素跟周围元素对齐辅助
const elementGuidelines: HTMLElement[] = Array.prototype.slice.call(this.target?.parentElement?.children) || [];
const elementGuidelines: Element[] = Array.from(this.target?.parentElement?.children || []);
this.setElementGuidelines([this.target as HTMLElement], elementGuidelines);

return this.getOptions(false, {
Expand Down
3 changes: 1 addition & 2 deletions packages/stage/src/StageMultiDragResize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ export default class StageMultiDragResize extends MoveableOptionsManager {
this.dragResizeHelper.updateGroup(els);

// 设置周围元素,用于选中元素跟周围元素的对齐辅助
const elementGuidelines: HTMLElement[] =
Array.prototype.slice.call(this.targetList[0].parentElement?.children) || [];
const elementGuidelines: Element[] = Array.from(this.targetList[0].parentElement?.children || []);
this.setElementGuidelines(this.targetList, elementGuidelines);

this.moveableForMulti?.destroy();
Expand Down
2 changes: 1 addition & 1 deletion packages/stage/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const getParents = (el: Element, relative: Element) => {
return parents;
};

export const getOffset = (el: TargetElement): Offset => {
export const getOffset = (el: Element): Offset => {
const htmlEl = el as HTMLElement;
const { offsetParent } = htmlEl;

Expand Down

0 comments on commit 0402568

Please sign in to comment.