mirror of
https://github.com/xibyte/jsketcher
synced 2026-01-02 13:56:13 +01:00
35 lines
No EOL
762 B
JavaScript
35 lines
No EOL
762 B
JavaScript
import constraintActions from "./constraintActions";
|
|
import {sortSelectionByType} from "./matchUtils";
|
|
|
|
const ALL_CONTEXTUAL_ACTIONS = [
|
|
...constraintActions,
|
|
//keep going here
|
|
];
|
|
|
|
export function matchAvailableActions(selection) {
|
|
|
|
let sortedByType = sortSelectionByType(selection);
|
|
let matched = [];
|
|
|
|
|
|
if (selection.length) {
|
|
for (let action of ALL_CONTEXTUAL_ACTIONS) {
|
|
|
|
if (Array.isArray(action.selectionMatcher)) {
|
|
action.selectionMatcher.forEach(matcher => {
|
|
if (matcher(selection, sortedByType)) {
|
|
matched.push(action);
|
|
}
|
|
})
|
|
} else {
|
|
if (action.selectionMatcher(selection, sortedByType)) {
|
|
matched.push(action);
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
return matched;
|
|
|
|
} |