UNPKG

@atlaskit/editor-plugin-floating-toolbar

Version:

Floating toolbar plugin for @atlaskit/editor-core

35 lines (34 loc) 1.41 kB
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray"; // if there are more than 1 item with type `overflow-dropdown`, we should only show one and combine the options export var consolidateOverflowDropdownItems = function consolidateOverflowDropdownItems(overflowDropdowns) { if (overflowDropdowns.length <= 1) { return overflowDropdowns[0]; } var combinedItems = overflowDropdowns.reduce(function (acc, item) { if (item.options) { acc.push.apply(acc, _toConsumableArray(item.options)); } return acc; }, []); // To filter out items that have a rank property, sort them by rank in descending order (highest rank first) var rankedItems = combinedItems.filter(function (item) { return 'rank' in item && typeof item.rank === 'number'; }).sort(function (a, b) { return (b.rank || 0) - (a.rank || 0); }); var unrankedItems = combinedItems.filter(function (item) { return !('rank' in item && typeof item.rank === 'number'); }); var sortedItems = [].concat(_toConsumableArray(rankedItems), _toConsumableArray(unrankedItems)); var largestDropdownWidth = overflowDropdowns.reduce(function (acc, item) { if (item.dropdownWidth && item.dropdownWidth > acc) { return item.dropdownWidth; } return acc; }, 0); return { type: 'overflow-dropdown', dropdownWidth: largestDropdownWidth, options: sortedItems }; };