|
| 1 | +/** |
| 2 | + * This file contains highlight-related functions |
| 3 | + * Highlights appear when a box is selected |
| 4 | + */ |
| 5 | + |
| 6 | +import { BOX_HIGHLIGHTERS } from "../../constants/constants"; |
| 7 | +import Paper from "../../classes/Paper"; |
| 8 | + |
| 9 | +const HighlightPlugin = store => { |
| 10 | + store.subscribe(({ type }, { Interface }) => { |
| 11 | + // @TODO optimize with only changed values |
| 12 | + switch (type) { |
| 13 | + case "Interface/ADD_ELEMENT_TO_SELECTION": |
| 14 | + case "Interface/UNSELECT_ALL_ELEMENTS": |
| 15 | + case "Interface/ADD_UNIQUE_ELEMENT_TO_SELECTION": |
| 16 | + case "Interface/ADD_ELEMENTS_TO_SELECTION": { |
| 17 | + console.log(type, Interface); |
| 18 | + for (const element of Interface.elements) { |
| 19 | + const cellView = Paper.getViewFromBoxId(element.boxId); |
| 20 | + if (element.selected) { |
| 21 | + highlightSelection(cellView); |
| 22 | + } else { |
| 23 | + unHighlight(cellView); |
| 24 | + } |
| 25 | + } |
| 26 | + break; |
| 27 | + } |
| 28 | + default: |
| 29 | + break; |
| 30 | + } |
| 31 | + }); |
| 32 | +}; |
| 33 | + |
| 34 | +export default HighlightPlugin; |
| 35 | + |
| 36 | +function highlightSelection(cellView) { |
| 37 | + if (cellView) { |
| 38 | + for (const highlight of BOX_HIGHLIGHTERS) { |
| 39 | + cellView.highlight(null, highlight); |
| 40 | + } |
| 41 | + |
| 42 | + // if(!cellView.el.querySelector(`.${HIGHLIGHT_TOOLSBAR}`)) { |
| 43 | + |
| 44 | + // appendHighlightToolsbar(cellView) |
| 45 | + |
| 46 | + // } |
| 47 | + } |
| 48 | +} |
| 49 | + |
| 50 | +/** |
| 51 | + * remove highlight on given cellView |
| 52 | + * |
| 53 | + * @param {cellView} cellView |
| 54 | + */ |
| 55 | +function unHighlight(cellView) { |
| 56 | + for (const highlight of BOX_HIGHLIGHTERS) { |
| 57 | + cellView.unhighlight(null, highlight); |
| 58 | + } |
| 59 | + |
| 60 | + // removeHighlightToolsbar(cellView) |
| 61 | +} |
| 62 | + |
| 63 | +/** |
| 64 | + * remove highlight for all given elements |
| 65 | + * |
| 66 | + * @param {array} elements |
| 67 | + */ |
| 68 | +// function unHighlightAllElements(elements) { |
| 69 | +// for (const el of elements) { |
| 70 | +// unHighlight(el); |
| 71 | +// } |
| 72 | +// } |
| 73 | + |
| 74 | +/** |
| 75 | + * reset highlight on element |
| 76 | + * |
| 77 | + * @param {element} element |
| 78 | + */ |
| 79 | +// const resetHighlight = element => { |
| 80 | +// unHighlight(element); |
| 81 | +// highlightSelection(element); |
| 82 | +// }; |
| 83 | + |
| 84 | +/** |
| 85 | + * reset highlight on all elements |
| 86 | + * |
| 87 | + * @param {araay} elements |
| 88 | + */ |
| 89 | +// function resetHighlightAllElements(elements) { |
| 90 | +// for (const el of elements) { |
| 91 | +// resetHighlight(el); |
| 92 | +// } |
| 93 | +// } |
0 commit comments