Skip to content

Commit

Permalink
Merge pull request #563 from VisActor/fix/clear-state-of-empty-mark
Browse files Browse the repository at this point in the history
Fix/clear state of empty mark
  • Loading branch information
xile611 authored Oct 15, 2024
2 parents e254a4a + a9ebc6c commit 8dde1c2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"comment": "fix: fix error when clear states\n\n",
"type": "none",
"packageName": "@visactor/vgrammar-core"
}
],
"packageName": "@visactor/vgrammar-core",
"email": "[email protected]"
}
28 changes: 15 additions & 13 deletions packages/vgrammar-core/src/interactions/toggle-state-mixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export class ToggleStateMixin implements IToggleStateMixin {
return;
}

mark.elements.forEach(el => {
mark.elements?.forEach(el => {
const isStated = statedElements && statedElements.includes(el);

if (isStated) {
Expand All @@ -114,7 +114,7 @@ export class ToggleStateMixin implements IToggleStateMixin {
return;
}

mark.elements.forEach(el => {
mark.elements?.forEach(el => {
const isStated = statedElements && statedElements.includes(el);

if (isStated) {
Expand All @@ -132,18 +132,20 @@ export class ToggleStateMixin implements IToggleStateMixin {
}

this._marks.forEach(mark => {
if (reverseState && this._stateMarks[reverseState] && this._stateMarks[reverseState].includes(mark)) {
mark.elements.forEach(el => {
el.removeState(reverseState);
});
}
if (mark && mark.elements) {
if (reverseState && this._stateMarks[reverseState] && this._stateMarks[reverseState].includes(mark)) {
mark.elements.forEach(el => {
el.removeState(reverseState);
});
}

if (state && this._stateMarks[state] && this._stateMarks[state].includes(mark)) {
mark.elements.forEach(el => {
if (this._statedElements.includes(el)) {
el.removeState(state);
}
});
if (state && this._stateMarks[state] && this._stateMarks[state].includes(mark)) {
mark.elements.forEach(el => {
if (this._statedElements.includes(el)) {
el.removeState(state);
}
});
}
}
});
}
Expand Down

0 comments on commit 8dde1c2

Please sign in to comment.