-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #603 from VisActor/release/0.15.0
[Auto release] release 0.15.0
- Loading branch information
Showing
27 changed files
with
423 additions
and
194 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
[{"definitionName":"lockStepVersion","policyName":"vgrammarMain","version":"0.14.18","mainProject":"@visactor/vgrammar-core","nextBump":"patch"}] | ||
[{"definitionName":"lockStepVersion","policyName":"vgrammarMain","version":"0.15.0","mainProject":"@visactor/vgrammar-core","nextBump":"minor"}] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
packages/vgrammar-core/src/interactions/element-highlight-by-graphic-name.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import type { ElementHighlightByGraphicNameOptions, IElement, IGlyphElement, IView, InteractionEvent } from '../types'; | ||
import { isNil } from '@visactor/vutils'; | ||
import { ElementHighlight } from './element-highlight'; | ||
|
||
export class ElementHighlightByGraphicName extends ElementHighlight { | ||
static type: string = 'element-highlight-by-graphic-name'; | ||
type: string = ElementHighlightByGraphicName.type; | ||
|
||
options: ElementHighlightByGraphicNameOptions; | ||
|
||
constructor(view: IView, options?: ElementHighlightByGraphicNameOptions) { | ||
super(view, options); | ||
this.options = Object.assign({}, ElementHighlightByGraphicName.defaultOptions, options); | ||
this._marks = view.getMarksBySelector(this.options.selector); | ||
} | ||
|
||
protected _filterByName(e: InteractionEvent) { | ||
const name = e?.target?.name; | ||
return !!name; | ||
} | ||
|
||
protected _parseTargetKey(e: InteractionEvent, element: IElement | IGlyphElement) { | ||
return e.target.name; | ||
} | ||
|
||
start(itemKey: IElement | IGlyphElement | string) { | ||
if (isNil(itemKey)) { | ||
return; | ||
} | ||
|
||
this._marks.forEach(mark => { | ||
mark.elements.forEach(el => { | ||
const isHighlight = el.getGraphicItem()?.name === itemKey; | ||
if (isHighlight) { | ||
el.updateStates({ | ||
[this.options.blurState]: false, | ||
[this.options.highlightState]: true | ||
}); | ||
} else { | ||
el.updateStates({ | ||
[this.options.blurState]: true, | ||
[this.options.highlightState]: false | ||
}); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
reset() { | ||
const states = [this.options.blurState, this.options.highlightState]; | ||
this._marks.forEach(mark => { | ||
mark.elements.forEach(el => { | ||
el.removeState(states); | ||
}); | ||
}); | ||
} | ||
|
||
handleStart = (e: InteractionEvent) => { | ||
if (e && e.element && this._marks.includes(e.element.mark)) { | ||
const shouldStart = this.options.shouldStart ? this.options.shouldStart(e) : this._filterByName(e); | ||
if (shouldStart) { | ||
const itemKey = this._parseTargetKey(e, e.element); | ||
this.start(itemKey); | ||
} | ||
} | ||
}; | ||
|
||
handleReset = (e: InteractionEvent) => { | ||
if (e && e.element && this._marks.includes(e.element.mark)) { | ||
this.reset(); | ||
} | ||
}; | ||
} |
20 changes: 20 additions & 0 deletions
20
packages/vgrammar-core/src/interactions/element-select-by-graphic-name.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import type { InteractionEvent } from '../types'; | ||
import { ElementSelect } from './element-select'; | ||
|
||
export class ElementSelectByGraphicName extends ElementSelect { | ||
static type: string = 'element-select-by-graphic-name'; | ||
type: string = ElementSelectByGraphicName.type; | ||
|
||
start(element: InteractionEvent['element']) { | ||
const name = element.getGraphicItem()?.name; | ||
if (name) { | ||
this._marks.forEach(mark => { | ||
mark.elements.forEach(el => { | ||
if (el.getGraphicItem()?.name === name) { | ||
super.start(el); | ||
} | ||
}); | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.