From 52f5e9497274d99078ef2ef1a42f33c7b3ce58fd Mon Sep 17 00:00:00 2001 From: Cameron Smith Date: Tue, 20 Aug 2024 10:52:43 -0400 Subject: [PATCH] fix(position-manager): reindex, var name updates, id comparison --- amd/package.json | 2 +- esm/package.json | 2 +- src/functionality/positionManager.ts | 21 +++++++++++---------- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/amd/package.json b/amd/package.json index f2d2fe4..2d01880 100644 --- a/amd/package.json +++ b/amd/package.json @@ -1,6 +1,6 @@ { "name": "templates-common-library", - "version": "0.0.510", + "version": "0.0.529", "files": [ "/*" ], diff --git a/esm/package.json b/esm/package.json index 2e2aba4..f79c16b 100644 --- a/esm/package.json +++ b/esm/package.json @@ -1,6 +1,6 @@ { "name": "templates-common-library", - "version": "0.0.510-esm", + "version": "0.0.529-esm", "files": [ "/*" ], diff --git a/src/functionality/positionManager.ts b/src/functionality/positionManager.ts index ec007f0..b5ec203 100644 --- a/src/functionality/positionManager.ts +++ b/src/functionality/positionManager.ts @@ -40,24 +40,24 @@ export function assertWidgetOrdering( () => { view.when(() => { const watchWidgetOrdering = (quadrant: __esri.UIPosition) => { - let leftPosition = view.ui.getComponents(quadrant); + let widgets = view.ui.getComponents(quadrant); let firstAssertion = true; watch( () => config.updateCount, () => { - const leftPositionNew = view.ui.getComponents(quadrant); + const widgetsNew = view.ui.getComponents(quadrant); const positionsHaveChanged: boolean = - leftPosition.length !== leftPositionNew.length || - leftPosition.some((el, i) => { - return el !== leftPositionNew[i]; + widgets.length !== widgetsNew.length || + widgets.some((el, i) => { + return el?.id !== widgetsNew[i]?.id; }); if (positionsHaveChanged || firstAssertion) { - leftPosition = leftPositionNew; + widgets = widgetsNew; firstAssertion = false; setTimeout(() => { - const sortedPositionList = leftPosition + const sortedPositionList = widgets .map((el) => { const id = positionKeyLookup.get(el.id) != null @@ -79,9 +79,10 @@ export function assertWidgetOrdering( .sort((a, b) => { return a[1]?.index - b[1]?.index; }); - sortedPositionList.forEach((sortedPair) => { + sortedPositionList.forEach((sortedPair, index) => { const [id, positionLookup] = sortedPair; - const el = leftPosition.find((elem) => elem.id === id); + positionLookup.index = index; // override to directly match sorted list + const el = widgets.find((elem) => elem.id === id); view.ui.move({ component: el, ...positionLookup } as any); updateExpandGroup(el, positionLookup); }); @@ -153,7 +154,7 @@ function debouncePositionUpdate( components.forEach((component, index) => { const position = { index, - position: component.uiPosition.position + position: component.uiPosition.position, }; view.ui.move(component.widget, position); });