/*! * All material copyright ESRI, All Rights Reserved, unless otherwise specified. * See https://github.com/Esri/calcite-components/blob/master/LICENSE.md for details. * v1.0.0-beta.82 */ 'use strict'; const index = require('./index-5c65e149.js'); const dom = require('./dom-9ac0341c.js'); const resources = require('./resources-1a214670.js'); const resources$1 = require('./resources-5da94c46.js'); const overflowActionsDebounceInMs = 150; const groupBufferHeight = 2; const getMaxActionCount = ({ height, actionHeight, groupCount }) => { return Math.floor((height - groupCount * groupBufferHeight) / actionHeight); }; const getOverflowCount = ({ actionCount, actionHeight, height, groupCount }) => { return Math.max(actionCount - getMaxActionCount({ height, actionHeight, groupCount }), 0); }; const queryActions = (el) => { return Array.from(el.querySelectorAll("calcite-action")).filter((action) => action.closest("calcite-action-menu") ? action.slot === resources.SLOTS.trigger : true); }; const overflowActions = ({ actionGroups, expanded, overflowCount }) => { let needToSlotCount = overflowCount; actionGroups.reverse().forEach((group) => { let slottedWithinGroupCount = 0; const groupActions = queryActions(group).reverse(); groupActions.forEach((groupAction) => { if (groupAction.slot === resources$1.SLOTS.menuActions) { groupAction.removeAttribute("slot"); groupAction.textEnabled = expanded; } }); if (needToSlotCount > 0) { groupActions.some((groupAction) => { const unslottedActions = groupActions.filter((action) => !action.slot); if (unslottedActions.length > 1 && groupActions.length > 2 && !groupAction.closest("calcite-action-menu")) { groupAction.textEnabled = true; groupAction.setAttribute("slot", resources$1.SLOTS.menuActions); slottedWithinGroupCount++; if (slottedWithinGroupCount > 1) { needToSlotCount--; } } return needToSlotCount < 1; }); } index.forceUpdate(group); }); }; const ICONS = { chevronsLeft: "chevrons-left", chevronsRight: "chevrons-right" }; function getCalcitePosition(position, el) { var _a; return position || ((_a = el.closest("calcite-shell-panel")) === null || _a === void 0 ? void 0 : _a.position) || "start"; } function toggleChildActionText({ parent, expanded }) { queryActions(parent) .filter((el) => el.slot !== resources$1.SLOTS.menuActions) .forEach((action) => (action.textEnabled = expanded)); parent.querySelectorAll("calcite-action-group").forEach((group) => (group.expanded = expanded)); } const setTooltipReference = ({ tooltip, referenceElement, expanded, ref }) => { if (tooltip) { tooltip.referenceElement = !expanded && referenceElement ? referenceElement : null; } if (ref) { ref(referenceElement); } return referenceElement; }; const ExpandToggle = ({ expanded, intlExpand, intlCollapse, toggle, el, position, tooltip, ref, scale }) => { const rtl = dom.getElementDir(el) === "rtl"; const expandText = expanded ? intlCollapse : intlExpand; const icons = [ICONS.chevronsLeft, ICONS.chevronsRight]; if (rtl) { icons.reverse(); } const end = getCalcitePosition(position, el) === "end"; const expandIcon = end ? icons[1] : icons[0]; const collapseIcon = end ? icons[0] : icons[1]; const actionNode = (index.h("calcite-action", { icon: expanded ? expandIcon : collapseIcon, onClick: toggle, ref: (referenceElement) => setTooltipReference({ tooltip, referenceElement, expanded, ref }), scale: scale, text: expandText, textEnabled: expanded })); return actionNode; }; exports.ExpandToggle = ExpandToggle; exports.getOverflowCount = getOverflowCount; exports.overflowActions = overflowActions; exports.overflowActionsDebounceInMs = overflowActionsDebounceInMs; exports.queryActions = queryActions; exports.toggleChildActionText = toggleChildActionText;