mirror of
https://github.com/xibyte/jsketcher
synced 2025-12-09 18:02:50 +01:00
45 lines
No EOL
962 B
JavaScript
45 lines
No EOL
962 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;
|
|
|
|
}
|
|
|
|
|
|
//For backward compatibility
|
|
export function getActionIfAvailable(actionId, selection, cb) {
|
|
matchAvailableActions(selection).forEach(a => {
|
|
if (a.id === actionId) {
|
|
cb(a);
|
|
}
|
|
})
|
|
} |