jsketcher/web/app/sketcher/actions/index.js
2020-02-05 23:24:10 -08:00

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;
}