niuma-ui 2.0.4 → 2.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +58 -0
- package/dist/components/_shared/index.d.ts +2 -2
- package/dist/components/_shared/src/overlay-utils.d.ts +44 -1
- package/dist/components/_shared/src/overlay-utils.js +87 -2
- package/dist/components/_shared/src/reka.js +2 -2
- package/dist/components/alert/index.d.ts +1 -0
- package/dist/components/alert/src/RsAlert.css +120 -65
- package/dist/components/alert/src/RsAlert.d.ts +24 -5
- package/dist/components/alert/src/RsAlert.impl.js +108 -36
- package/dist/components/alert/src/RsAlert.js +1 -1
- package/dist/components/alert/src/alert-utils.d.ts +37 -0
- package/dist/components/alert/src/alert-utils.js +71 -0
- package/dist/components/auto-complete/src/RsAutoComplete.d.ts +1 -1
- package/dist/components/button/src/RsButton.impl.js +1 -1
- package/dist/components/card/src/RsCard.d.ts +1 -1
- package/dist/components/code-block/index.d.ts +1 -0
- package/dist/components/code-block/src/RsCodeBlock.css +93 -52
- package/dist/components/code-block/src/RsCodeBlock.d.ts +36 -9
- package/dist/components/code-block/src/RsCodeBlock.impl.js +203 -84
- package/dist/components/code-block/src/RsCodeBlock.js +1 -1
- package/dist/components/code-block/src/code-block-highlight.d.ts +4 -0
- package/dist/components/code-block/src/code-block-highlight.js +34 -0
- package/dist/components/code-block/src/code-block-utils.d.ts +23 -0
- package/dist/components/code-block/src/code-block-utils.js +71 -0
- package/dist/components/code-editor/index.d.ts +1 -1
- package/dist/components/code-editor/src/RsCodeEditor.css +118 -92
- package/dist/components/code-editor/src/RsCodeEditor.d.ts +14 -3
- package/dist/components/code-editor/src/RsCodeEditor.impl.js +261 -94
- package/dist/components/code-editor/src/RsCodeEditor.js +1 -1
- package/dist/components/code-editor/src/code-editor-utils.d.ts +15 -0
- package/dist/components/code-editor/src/code-editor-utils.js +36 -1
- package/dist/components/code-editor/src/code-mirror-completion.d.ts +1 -1
- package/dist/components/code-editor/src/code-mirror-completion.js +8 -5
- package/dist/components/code-editor/src/code-mirror-diagnostics.d.ts +2 -3
- package/dist/components/code-editor/src/code-mirror-diagnostics.js +3 -4
- package/dist/components/code-editor/src/code-mirror-ghost.d.ts +1 -1
- package/dist/components/code-editor/src/code-mirror-ghost.js +12 -3
- package/dist/components/code-editor/src/code-mirror-inline-edit.js +8 -3
- package/dist/components/code-editor/src/code-mirror-intel.d.ts +2 -2
- package/dist/components/code-editor/src/code-mirror-intel.js +50 -39
- package/dist/components/code-editor/src/code-mirror-lang.js +4 -0
- package/dist/components/code-editor/src/code-mirror-session.d.ts +13 -0
- package/dist/components/code-editor/src/code-mirror-session.js +30 -0
- package/dist/components/context-menu/index.d.ts +1 -1
- package/dist/components/context-menu/src/RsContextMenu.css +115 -89
- package/dist/components/context-menu/src/RsContextMenu.d.ts +32 -11
- package/dist/components/context-menu/src/RsContextMenu.impl.js +795 -48
- package/dist/components/context-menu/src/RsContextMenuItems.d.ts +25 -1
- package/dist/components/context-menu/src/RsContextMenuItems.impl.js +110 -61
- package/dist/components/context-menu/src/context-menu-utils.d.ts +89 -3
- package/dist/components/context-menu/src/context-menu-utils.js +168 -3
- package/dist/components/date-picker/src/RsDatePicker.d.ts +2 -2
- package/dist/components/date-picker/src/RsDateTimePicker.d.ts +2 -2
- package/dist/components/descriptions/index.d.ts +1 -1
- package/dist/components/descriptions/src/RsDescriptions.css +38 -11
- package/dist/components/descriptions/src/RsDescriptions.d.ts +20 -4
- package/dist/components/descriptions/src/RsDescriptions.impl.js +89 -19
- package/dist/components/descriptions/src/RsDescriptionsItem.impl.js +13 -6
- package/dist/components/descriptions/src/descriptions-utils.d.ts +19 -0
- package/dist/components/descriptions/src/descriptions-utils.js +39 -1
- package/dist/components/dialog/index.d.ts +1 -1
- package/dist/components/dialog/src/RsConfirmDialog.css +47 -21
- package/dist/components/dialog/src/RsConfirmDialog.d.ts +19 -7
- package/dist/components/dialog/src/RsConfirmDialog.impl.js +349 -119
- package/dist/components/dialog/src/RsConfirmDialog.js +2 -1
- package/dist/components/dialog/src/RsDialog.css +102 -109
- package/dist/components/dialog/src/RsDialog.d.ts +34 -24
- package/dist/components/dialog/src/RsDialog.impl.js +410 -177
- package/dist/components/dialog/src/RsDialog.js +2 -1
- package/dist/components/dialog/src/dialog-utils.d.ts +40 -1
- package/dist/components/dialog/src/dialog-utils.js +152 -1
- package/dist/components/dialog/src/dialog-window.js +29 -8
- package/dist/components/drawer/index.d.ts +1 -1
- package/dist/components/drawer/src/RsDrawer.css +61 -29
- package/dist/components/drawer/src/RsDrawer.d.ts +37 -21
- package/dist/components/drawer/src/RsDrawer.impl.js +441 -223
- package/dist/components/drawer/src/drawer-utils.d.ts +35 -0
- package/dist/components/drawer/src/drawer-utils.js +131 -1
- package/dist/components/dropdown/index.d.ts +1 -1
- package/dist/components/dropdown/src/RsDropdown.css +140 -61
- package/dist/components/dropdown/src/RsDropdown.d.ts +39 -6
- package/dist/components/dropdown/src/RsDropdown.impl.js +693 -63
- package/dist/components/dropdown/src/RsDropdownItemView.impl.js +17 -7
- package/dist/components/dropdown/src/RsDropdownItems.d.ts +32 -3
- package/dist/components/dropdown/src/RsDropdownItems.impl.js +171 -59
- package/dist/components/dropdown/src/dropdown-utils.d.ts +50 -0
- package/dist/components/dropdown/src/dropdown-utils.js +103 -3
- package/dist/components/empty/index.d.ts +1 -0
- package/dist/components/empty/src/RsEmpty.css +105 -23
- package/dist/components/empty/src/RsEmpty.d.ts +27 -4
- package/dist/components/empty/src/RsEmpty.impl.js +154 -11
- package/dist/components/empty/src/RsEmpty.js +2 -1
- package/dist/components/empty/src/empty-utils.d.ts +28 -0
- package/dist/components/empty/src/empty-utils.js +55 -0
- package/dist/components/form/src/RsForm.d.ts +1 -1
- package/dist/components/input-number/src/RsInputNumber.d.ts +1 -1
- package/dist/components/label/src/RsLabel.d.ts +1 -1
- package/dist/components/loading/index.d.ts +1 -0
- package/dist/components/loading/src/RsLoading.css +13 -97
- package/dist/components/loading/src/RsLoading.d.ts +52 -2
- package/dist/components/loading/src/RsLoading.impl.js +216 -33
- package/dist/components/loading/src/RsLoading.js +2 -1
- package/dist/components/loading/src/loading-status.css +210 -0
- package/dist/components/loading/src/loading-status.d.ts +34 -0
- package/dist/components/loading/src/loading-status.impl.js +84 -0
- package/dist/components/loading/src/loading-status.js +8 -0
- package/dist/components/loading/src/loading-utils.d.ts +51 -4
- package/dist/components/loading/src/loading-utils.js +122 -0
- package/dist/components/loading-bar/index.d.ts +1 -0
- package/dist/components/loading-bar/src/RsLoadingBar.css +72 -8
- package/dist/components/loading-bar/src/RsLoadingBar.d.ts +55 -11
- package/dist/components/loading-bar/src/RsLoadingBar.impl.js +298 -57
- package/dist/components/loading-bar/src/RsLoadingBar.js +1 -1
- package/dist/components/loading-bar/src/loading-bar-utils.d.ts +69 -0
- package/dist/components/loading-bar/src/loading-bar-utils.js +97 -0
- package/dist/components/log/src/RsLog.css +52 -144
- package/dist/components/log/src/RsLog.d.ts +12 -11
- package/dist/components/log/src/RsLog.impl.js +181 -148
- package/dist/components/log/src/RsLog.js +1 -1
- package/dist/components/log/src/RsLogRow.css +152 -0
- package/dist/components/log/src/RsLogRow.d.ts +35 -0
- package/dist/components/log/src/RsLogRow.impl.js +91 -0
- package/dist/components/log/src/RsLogRow.js +8 -0
- package/dist/components/log/src/log-utils.d.ts +8 -0
- package/dist/components/log/src/log-utils.js +71 -10
- package/dist/components/markdown/index.d.ts +1 -1
- package/dist/components/markdown/src/RsMarkdown.css +75 -32
- package/dist/components/markdown/src/RsMarkdown.d.ts +6 -2
- package/dist/components/markdown/src/RsMarkdown.impl.js +185 -17
- package/dist/components/markdown/src/markdown-utils.d.ts +26 -0
- package/dist/components/markdown/src/markdown-utils.js +114 -12
- package/dist/components/mentions/src/RsMentions.d.ts +2 -2
- package/dist/components/menu/index.d.ts +1 -1
- package/dist/components/menu/src/RsMenu.css +70 -29
- package/dist/components/menu/src/RsMenu.d.ts +58 -4
- package/dist/components/menu/src/RsMenu.impl.js +93 -46
- package/dist/components/menu/src/RsMenuItems.d.ts +22 -5
- package/dist/components/menu/src/RsMenuItems.impl.js +506 -154
- package/dist/components/menu/src/menu-utils.d.ts +56 -0
- package/dist/components/menu/src/menu-utils.js +139 -6
- package/dist/components/monaco-editor/index.d.ts +1 -1
- package/dist/components/monaco-editor/src/RsMonacoEditor.css +28 -16
- package/dist/components/monaco-editor/src/RsMonacoEditor.d.ts +39 -41
- package/dist/components/monaco-editor/src/RsMonacoEditor.impl.js +212 -133
- package/dist/components/monaco-editor/src/RsMonacoEditor.js +1 -1
- package/dist/components/monaco-editor/src/monaco-editor-utils.d.ts +126 -0
- package/dist/components/monaco-editor/src/monaco-editor-utils.js +302 -0
- package/dist/components/pagination/index.d.ts +2 -2
- package/dist/components/pagination/src/RsPagination.css +93 -46
- package/dist/components/pagination/src/RsPagination.d.ts +68 -8
- package/dist/components/pagination/src/RsPagination.impl.js +229 -86
- package/dist/components/pagination/src/RsPagination.js +1 -1
- package/dist/components/pagination/src/pagination-utils.d.ts +59 -0
- package/dist/components/pagination/src/pagination-utils.js +105 -1
- package/dist/components/popover/index.d.ts +1 -0
- package/dist/components/popover/src/RsPopover.css +124 -14
- package/dist/components/popover/src/RsPopover.d.ts +38 -7
- package/dist/components/popover/src/RsPopover.impl.js +546 -35
- package/dist/components/popover/src/RsPopover.js +2 -1
- package/dist/components/popover/src/popover-utils.d.ts +24 -2
- package/dist/components/popover/src/popover-utils.js +55 -0
- package/dist/components/sidebar/index.d.ts +1 -0
- package/dist/components/sidebar/src/RsSidebar.css +91 -33
- package/dist/components/sidebar/src/RsSidebar.d.ts +17 -9
- package/dist/components/sidebar/src/RsSidebar.impl.js +124 -22
- package/dist/components/sidebar/src/RsSidebar.js +1 -1
- package/dist/components/sidebar/src/RsSidebarGroup.css +23 -6
- package/dist/components/sidebar/src/RsSidebarGroup.d.ts +6 -2
- package/dist/components/sidebar/src/RsSidebarGroup.impl.js +17 -4
- package/dist/components/sidebar/src/RsSidebarGroup.js +1 -1
- package/dist/components/sidebar/src/RsSidebarItem.css +50 -20
- package/dist/components/sidebar/src/RsSidebarItem.d.ts +21 -3
- package/dist/components/sidebar/src/RsSidebarItem.impl.js +71 -20
- package/dist/components/sidebar/src/RsSidebarItem.js +1 -1
- package/dist/components/sidebar/src/sidebar-utils.d.ts +47 -0
- package/dist/components/sidebar/src/sidebar-utils.js +72 -0
- package/dist/components/split-pane/index.d.ts +2 -2
- package/dist/components/split-pane/src/RsSplitPane.css +41 -30
- package/dist/components/split-pane/src/RsSplitPane.d.ts +6 -2
- package/dist/components/split-pane/src/RsSplitPane.impl.js +153 -45
- package/dist/components/split-pane/src/split-pane-utils.d.ts +23 -0
- package/dist/components/split-pane/src/split-pane-utils.js +18 -1
- package/dist/components/stat-card/index.d.ts +1 -0
- package/dist/components/stat-card/src/RsStatCard.css +129 -25
- package/dist/components/stat-card/src/RsStatCard.d.ts +40 -4
- package/dist/components/stat-card/src/RsStatCard.impl.js +106 -12
- package/dist/components/stat-card/src/RsStatCard.js +1 -1
- package/dist/components/stat-card/src/stat-card-utils.d.ts +39 -0
- package/dist/components/stat-card/src/stat-card-utils.js +113 -0
- package/dist/components/steps/index.d.ts +1 -1
- package/dist/components/steps/src/RsSteps.css +158 -37
- package/dist/components/steps/src/RsSteps.d.ts +69 -5
- package/dist/components/steps/src/RsSteps.impl.js +168 -28
- package/dist/components/steps/src/RsSteps.js +1 -1
- package/dist/components/steps/src/steps-utils.d.ts +51 -1
- package/dist/components/steps/src/steps-utils.js +67 -1
- package/dist/components/table/src/RsTable.impl.js +4 -2
- package/dist/components/table/src/composables/useRsTableContextMenu.d.ts +16 -0
- package/dist/components/table/src/composables/useRsTableContextMenu.js +1 -1
- package/dist/components/table/src/composables/useRsTableEngine.js +6 -2
- package/dist/components/table/src/composables/useRsTableScrollLayout.js +2 -0
- package/dist/components/table/src/composables/useRsTableShell.d.ts +16 -0
- package/dist/components/table/src/rs-table-props.d.ts +1 -1
- package/dist/components/table/src/rs-table-props.js +0 -1
- package/dist/components/table/src/table-body/RsTableBody.impl.js +1 -0
- package/dist/components/table/src/table-body/RsTableCellEditor.impl.js +10 -2
- package/dist/components/table/src/table-body/RsTableColGroup.impl.js +1 -0
- package/dist/components/table/src/table-footer/RsTableSummaryRow.impl.js +1 -0
- package/dist/components/table/src/table-header/RsTableHeader.impl.js +1 -0
- package/dist/components/table/src/utils/table-utils.d.ts +10 -6
- package/dist/components/table/src/utils/table-utils.js +27 -25
- package/dist/components/table/style/rs-table.css +34 -20
- package/dist/components/tabs/index.d.ts +2 -2
- package/dist/components/tabs/src/RsTabs.css +225 -101
- package/dist/components/tabs/src/RsTabs.d.ts +37 -8
- package/dist/components/tabs/src/RsTabs.impl.js +400 -270
- package/dist/components/tabs/src/tabs-utils.d.ts +41 -2
- package/dist/components/tabs/src/tabs-utils.js +55 -1
- package/dist/components/terminal/index.d.ts +1 -1
- package/dist/components/terminal/src/RsTerminal.css +60 -37
- package/dist/components/terminal/src/RsTerminal.d.ts +36 -4
- package/dist/components/terminal/src/RsTerminal.impl.js +288 -68
- package/dist/components/terminal/src/RsTerminal.js +1 -1
- package/dist/components/terminal/src/terminal-utils.d.ts +42 -4
- package/dist/components/terminal/src/terminal-utils.js +113 -10
- package/dist/components/textarea/src/RsTextarea.d.ts +1 -1
- package/dist/components/time-picker/src/RsTimePicker.d.ts +2 -2
- package/dist/components/toaster/src/RsToaster.css +156 -203
- package/dist/components/toaster/src/RsToaster.d.ts +32 -2
- package/dist/components/toaster/src/RsToaster.impl.js +309 -34
- package/dist/components/toaster/src/toast-store.d.ts +95 -0
- package/dist/components/toaster/src/toast-store.js +177 -0
- package/dist/components/toaster/src/toast-utils.d.ts +60 -0
- package/dist/components/toaster/src/toast-utils.js +86 -0
- package/dist/components/toolbar/index.d.ts +1 -1
- package/dist/components/toolbar/src/RsToolbar.css +206 -32
- package/dist/components/toolbar/src/RsToolbar.d.ts +41 -16
- package/dist/components/toolbar/src/RsToolbar.impl.js +146 -18
- package/dist/components/toolbar/src/RsToolbar.js +2 -1
- package/dist/components/toolbar/src/toolbar-utils.d.ts +20 -0
- package/dist/components/toolbar/src/toolbar-utils.js +105 -0
- package/dist/components/tooltip/index.d.ts +1 -0
- package/dist/components/tooltip/src/RsTooltip.css +104 -26
- package/dist/components/tooltip/src/RsTooltip.d.ts +38 -16
- package/dist/components/tooltip/src/RsTooltip.impl.js +420 -51
- package/dist/components/tooltip/src/RsTooltip.js +2 -1
- package/dist/components/tooltip/src/RsTooltipProvider.d.ts +4 -4
- package/dist/components/tooltip/src/RsTooltipProvider.impl.js +51 -14
- package/dist/components/tooltip/src/tooltip-utils.d.ts +30 -0
- package/dist/components/tooltip/src/tooltip-utils.js +23 -0
- package/dist/components/tree/index.d.ts +2 -2
- package/dist/components/tree/src/RsTree.css +84 -75
- package/dist/components/tree/src/RsTree.d.ts +20 -20
- package/dist/components/tree/src/RsTree.impl.js +292 -66
- package/dist/components/tree/src/RsTree.js +1 -1
- package/dist/components/tree/src/tree-utils.d.ts +22 -0
- package/dist/components/tree/src/tree-utils.js +18 -4
- package/dist/components/tree-select/src/RsTreeSelect.d.ts +1 -1
- package/dist/components/virtual-list/index.d.ts +1 -1
- package/dist/components/virtual-list/src/RsVirtualList.css +64 -9
- package/dist/components/virtual-list/src/RsVirtualList.d.ts +31 -5
- package/dist/components/virtual-list/src/RsVirtualList.impl.js +425 -76
- package/dist/components/virtual-list/src/RsVirtualList.js +1 -1
- package/dist/components/virtual-list/src/virtual-list-utils.d.ts +64 -1
- package/dist/components/virtual-list/src/virtual-list-utils.js +215 -1
- package/dist/composables/useRsLoadingBar.d.ts +2 -5
- package/dist/composables/useRsLoadingBar.js +21 -5
- package/dist/composables/useRsTabsNav.d.ts +3 -1
- package/dist/composables/useRsTabsNav.js +96 -28
- package/dist/composables/useRsToast.d.ts +11 -13
- package/dist/composables/useRsToast.js +66 -17
- package/dist/index.d.ts +30 -21
- package/dist/index.js +14 -0
- package/dist/locale/apply.js +6 -1
- package/dist/locale/messages.js +128 -2
- package/dist/styles.css +460 -797
- package/dist/theme/brand.example.css +2 -1
- package/dist/vite-plugins/niuma-ui-host.js +1 -1
- package/package.json +2 -3
|
@@ -1,13 +1,57 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { RS_COMPONENT_SIZE_ICON_PX } from "../../../theme/types.js";
|
|
2
|
+
import { useRsConfigOptional } from "../../../composables/useRsConfig.js";
|
|
3
|
+
import { resolveDirMode } from "../../../locale/apply.js";
|
|
4
|
+
import { useRsI18n } from "../../../composables/useRsI18n.js";
|
|
5
|
+
import { rsRadiusCss } from "../../_shared/src/resolve-radius.js";
|
|
6
|
+
import { claimContextMenu, escapeContextMenuSelector, findContextMenuItem, firstEnabledContextMenuKey, hasActionableContextMenuItems, hasContextMenuChildren, isContextMenuSeparator, lastEnabledContextMenuKey, listContextMenuLayerItems, matchContextMenuTypeahead, placeContextMenuPoint, placeContextMenuSubmenu, releaseContextMenu, resolveContextMenuElement, resolveContextMenuKeys, resolveContextMenuLayers, resolveContextMenuPortalTarget, shouldCloseContextMenuOnSelect, stepContextMenuKey } from "./context-menu-utils.js";
|
|
3
7
|
import RsContextMenuItems_default from "./RsContextMenuItems.js";
|
|
4
|
-
import { computed, createBlock, createCommentVNode, createVNode, defineComponent, mergeModels, openBlock, renderSlot, unref, useModel, watch, withCtx, withModifiers } from "vue";
|
|
8
|
+
import { Comment, Fragment, Teleport, Text, cloneVNode, computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createVNode, defineComponent, isVNode, mergeModels, mergeProps, nextTick, normalizeClass, normalizeStyle, onUnmounted, openBlock, ref, renderList, renderSlot, toDisplayString, unref, useId, useModel, useSlots, vShow, watch, withCtx, withDirectives, withModifiers } from "vue";
|
|
5
9
|
//#region src/components/context-menu/src/RsContextMenu.vue?vue&type=script&setup=true&lang.ts
|
|
10
|
+
var _hoisted_1 = { class: "rs-context-menu__portal" };
|
|
11
|
+
var _hoisted_2 = [
|
|
12
|
+
"id",
|
|
13
|
+
"aria-label",
|
|
14
|
+
"dir",
|
|
15
|
+
"lang",
|
|
16
|
+
"data-rs-theme",
|
|
17
|
+
"data-placed",
|
|
18
|
+
"data-origin-x",
|
|
19
|
+
"data-origin-y"
|
|
20
|
+
];
|
|
21
|
+
var _hoisted_3 = { class: "rs-context-menu__label" };
|
|
22
|
+
var _hoisted_4 = {
|
|
23
|
+
key: 0,
|
|
24
|
+
class: "rs-context-menu__hint"
|
|
25
|
+
};
|
|
26
|
+
var SUB_OPEN_MS = 80;
|
|
27
|
+
var SUB_CLOSE_MS = 160;
|
|
28
|
+
var ESTIMATE_W = 176;
|
|
29
|
+
var ESTIMATE_H = 32;
|
|
6
30
|
var RsContextMenu_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineComponent({
|
|
31
|
+
name: "RsContextMenu",
|
|
32
|
+
inheritAttrs: false,
|
|
7
33
|
__name: "RsContextMenu",
|
|
8
34
|
props: /*@__PURE__*/ mergeModels({
|
|
9
35
|
items: {},
|
|
10
|
-
disabled: {
|
|
36
|
+
disabled: {
|
|
37
|
+
type: Boolean,
|
|
38
|
+
default: false
|
|
39
|
+
},
|
|
40
|
+
size: {},
|
|
41
|
+
radius: {},
|
|
42
|
+
hideOnSelect: {
|
|
43
|
+
type: Boolean,
|
|
44
|
+
default: true
|
|
45
|
+
},
|
|
46
|
+
getPopupContainer: {},
|
|
47
|
+
popupClassName: {},
|
|
48
|
+
maxHeight: {},
|
|
49
|
+
ariaLabel: {},
|
|
50
|
+
id: {},
|
|
51
|
+
destroyOnHide: {
|
|
52
|
+
type: Boolean,
|
|
53
|
+
default: true
|
|
54
|
+
}
|
|
11
55
|
}, {
|
|
12
56
|
"open": {
|
|
13
57
|
type: Boolean,
|
|
@@ -15,65 +59,768 @@ var RsContextMenu_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ de
|
|
|
15
59
|
},
|
|
16
60
|
"openModifiers": {}
|
|
17
61
|
}),
|
|
18
|
-
emits: /*@__PURE__*/ mergeModels(["select"], ["update:open"]),
|
|
19
|
-
setup(__props, { emit: __emit }) {
|
|
20
|
-
const props = __props;
|
|
21
|
-
/**
|
|
22
|
-
* 展开状态。不绑定时组件自行维护(与原行为一致)。
|
|
23
|
-
* 绑定后可由外部主动关闭——例如菜单所依赖的数据已失效时。
|
|
24
|
-
*/
|
|
62
|
+
emits: /*@__PURE__*/ mergeModels(["select", "openChange"], ["update:open"]),
|
|
63
|
+
setup(__props, { expose: __expose, emit: __emit }) {
|
|
25
64
|
const open = useModel(__props, "open");
|
|
65
|
+
const props = __props;
|
|
26
66
|
const emit = __emit;
|
|
27
|
-
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
67
|
+
const { t, locale } = useRsI18n();
|
|
68
|
+
const config = useRsConfigOptional();
|
|
69
|
+
const slots = useSlots();
|
|
70
|
+
const autoId = useId();
|
|
71
|
+
const menuId = computed(() => props.id || autoId);
|
|
72
|
+
const configRtl = computed(() => resolveDirMode(config?.dir.value ?? "auto", config?.locale.value ?? locale.value) === "rtl");
|
|
73
|
+
const menuLabel = computed(() => props.ariaLabel || t("contextMenu.menu"));
|
|
74
|
+
const iconSize = computed(() => props.size ? RS_COMPONENT_SIZE_ICON_PX[props.size] : 16);
|
|
75
|
+
const portalTarget = computed(() => resolveContextMenuPortalTarget(props.getPopupContainer, triggerEl.value));
|
|
76
|
+
const showPanel = computed(() => open.value || !props.destroyOnHide);
|
|
77
|
+
const triggerEl = ref(null);
|
|
78
|
+
const anchor = ref({
|
|
79
|
+
x: 0,
|
|
80
|
+
y: 0
|
|
31
81
|
});
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
82
|
+
const submenuPath = ref([]);
|
|
83
|
+
const rootHighlight = ref("");
|
|
84
|
+
const subHighlights = ref({});
|
|
85
|
+
const boxes = ref({});
|
|
86
|
+
const settled = ref({});
|
|
87
|
+
const panelTheme = ref();
|
|
88
|
+
const panelDir = ref("ltr");
|
|
89
|
+
const panelLang = ref();
|
|
90
|
+
const isRtl = computed(() => open.value ? panelDir.value === "rtl" : configRtl.value);
|
|
91
|
+
const layers = computed(() => resolveContextMenuLayers(props.items, submenuPath.value).map((layer, depth) => ({
|
|
92
|
+
...layer,
|
|
93
|
+
depth,
|
|
94
|
+
openKey: submenuPath.value[depth] ?? ""
|
|
95
|
+
})));
|
|
96
|
+
const layerEls = /* @__PURE__ */ new Map();
|
|
97
|
+
const layerRefs = /* @__PURE__ */ new Map();
|
|
98
|
+
const itemRefs = /* @__PURE__ */ new Map();
|
|
99
|
+
const itemLists = /* @__PURE__ */ new Map();
|
|
100
|
+
let frame = 0;
|
|
101
|
+
let overlayBound = false;
|
|
102
|
+
let openWatchReady = false;
|
|
103
|
+
let ignoreContextClose = false;
|
|
104
|
+
let pointLocked = false;
|
|
105
|
+
let restoreOnClose = false;
|
|
106
|
+
let restoreTarget = null;
|
|
107
|
+
let subOpenTimer;
|
|
108
|
+
let subCloseTimer;
|
|
109
|
+
let typeaheadTimer;
|
|
110
|
+
let typeaheadQuery = "";
|
|
111
|
+
let resizeObserver;
|
|
112
|
+
let swallowStop;
|
|
113
|
+
function requestClose() {
|
|
114
|
+
restoreOnClose = false;
|
|
115
|
+
pointLocked = false;
|
|
116
|
+
if (open.value) open.value = false;
|
|
117
|
+
}
|
|
118
|
+
function pointFromTrigger() {
|
|
119
|
+
const el = triggerEl.value;
|
|
120
|
+
if (!el) return {
|
|
121
|
+
x: 8,
|
|
122
|
+
y: 8
|
|
123
|
+
};
|
|
124
|
+
const rect = el.getBoundingClientRect();
|
|
125
|
+
return {
|
|
126
|
+
x: rect.left + 8,
|
|
127
|
+
y: rect.top + Math.min(rect.height, 24)
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
function setOpen(next, point) {
|
|
131
|
+
if (next) {
|
|
132
|
+
if (point) {
|
|
133
|
+
anchor.value = point;
|
|
134
|
+
pointLocked = true;
|
|
135
|
+
} else if (!open.value) {
|
|
136
|
+
pointLocked = false;
|
|
137
|
+
anchor.value = pointFromTrigger();
|
|
138
|
+
}
|
|
139
|
+
if (props.disabled || !hasActionableContextMenuItems(props.items)) {
|
|
140
|
+
pointLocked = false;
|
|
141
|
+
if (open.value) open.value = false;
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
if (open.value === next) {
|
|
146
|
+
if (next) requestPlace();
|
|
35
147
|
return;
|
|
36
148
|
}
|
|
37
149
|
open.value = next;
|
|
38
150
|
}
|
|
151
|
+
function highlightOf(layerId) {
|
|
152
|
+
const live = itemLists.get(layerId)?.getHighlight();
|
|
153
|
+
if (live) return live;
|
|
154
|
+
if (layerId === "root") return rootHighlight.value;
|
|
155
|
+
return subHighlights.value[layerId] ?? "";
|
|
156
|
+
}
|
|
157
|
+
function setHighlight(layerId, key) {
|
|
158
|
+
if (!key || highlightOf(layerId) === key) return;
|
|
159
|
+
const list = itemLists.get(layerId);
|
|
160
|
+
if (list) {
|
|
161
|
+
list.setHighlight(key);
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
if (layerId === "root") rootHighlight.value = key;
|
|
165
|
+
else subHighlights.value = {
|
|
166
|
+
...subHighlights.value,
|
|
167
|
+
[layerId]: key
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
function layerHighlight(id) {
|
|
171
|
+
if (id === "root") return rootHighlight.value;
|
|
172
|
+
return subHighlights.value[id] ?? "";
|
|
173
|
+
}
|
|
174
|
+
function setPath(next) {
|
|
175
|
+
const keep = new Set(next);
|
|
176
|
+
const settledNext = {};
|
|
177
|
+
for (const id of Object.keys(settled.value)) if (id === "root" || keep.has(id)) settledNext[id] = true;
|
|
178
|
+
if (Object.keys(settledNext).length !== Object.keys(settled.value).length) settled.value = settledNext;
|
|
179
|
+
const boxesNext = {};
|
|
180
|
+
for (const id of Object.keys(boxes.value)) {
|
|
181
|
+
const box = boxes.value[id];
|
|
182
|
+
if (box && (id === "root" || keep.has(id))) boxesNext[id] = box;
|
|
183
|
+
}
|
|
184
|
+
if (Object.keys(boxesNext).length !== Object.keys(boxes.value).length) boxes.value = boxesNext;
|
|
185
|
+
submenuPath.value = next;
|
|
186
|
+
}
|
|
187
|
+
function revealSettled() {
|
|
188
|
+
const next = {};
|
|
189
|
+
for (const layer of layers.value) if (boxes.value[layer.id]) next[layer.id] = true;
|
|
190
|
+
const prev = settled.value;
|
|
191
|
+
const nextKeys = Object.keys(next);
|
|
192
|
+
if (nextKeys.length === Object.keys(prev).length && nextKeys.every((id) => prev[id])) return;
|
|
193
|
+
settled.value = next;
|
|
194
|
+
}
|
|
195
|
+
function settleLayers(after, prepare) {
|
|
196
|
+
nextTick(() => {
|
|
197
|
+
if (!open.value) return;
|
|
198
|
+
prepare?.();
|
|
199
|
+
placeAll();
|
|
200
|
+
nextTick(() => {
|
|
201
|
+
if (!open.value) return;
|
|
202
|
+
placeAll();
|
|
203
|
+
revealSettled();
|
|
204
|
+
after?.();
|
|
205
|
+
});
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
function readPanelDir(el) {
|
|
209
|
+
const dirHost = el?.closest("[dir]");
|
|
210
|
+
if (dirHost instanceof HTMLElement && (dirHost.dir === "rtl" || dirHost.dir === "ltr")) return dirHost.dir;
|
|
211
|
+
return configRtl.value ? "rtl" : "ltr";
|
|
212
|
+
}
|
|
213
|
+
function syncPanelChrome() {
|
|
214
|
+
const el = triggerEl.value;
|
|
215
|
+
const themed = el?.closest("[data-rs-theme]");
|
|
216
|
+
panelTheme.value = themed instanceof HTMLElement ? themed.dataset.rsTheme : void 0;
|
|
217
|
+
panelDir.value = readPanelDir(el);
|
|
218
|
+
const langHost = el?.closest("[lang]");
|
|
219
|
+
panelLang.value = langHost instanceof HTMLElement ? langHost.lang || void 0 : void 0;
|
|
220
|
+
}
|
|
221
|
+
function sameBoxes(prev, next) {
|
|
222
|
+
const keys = Object.keys(next);
|
|
223
|
+
if (keys.length !== Object.keys(prev).length) return false;
|
|
224
|
+
return keys.every((key) => {
|
|
225
|
+
const left = prev[key];
|
|
226
|
+
const right = next[key];
|
|
227
|
+
return left && right && left.top === right.top && left.left === right.left && left.maxHeight === right.maxHeight && left.originX === right.originX && left.originY === right.originY;
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
function placeAll() {
|
|
231
|
+
if (!open.value || typeof window === "undefined") return;
|
|
232
|
+
const viewport = {
|
|
233
|
+
width: window.innerWidth,
|
|
234
|
+
height: window.innerHeight
|
|
235
|
+
};
|
|
236
|
+
const rtl = panelDir.value === "rtl";
|
|
237
|
+
const next = {};
|
|
238
|
+
for (const layer of layers.value) {
|
|
239
|
+
const measured = layerEls.get(layer.id)?.getBoundingClientRect();
|
|
240
|
+
const popup = {
|
|
241
|
+
width: measured?.width || ESTIMATE_W,
|
|
242
|
+
height: measured?.height || ESTIMATE_H
|
|
243
|
+
};
|
|
244
|
+
if (layer.id === "root") {
|
|
245
|
+
const placed = roundBox(placeContextMenuPoint(anchor.value, popup, viewport, 8, rtl));
|
|
246
|
+
next[layer.id] = props.maxHeight != null ? {
|
|
247
|
+
...placed,
|
|
248
|
+
maxHeight: Math.min(placed.maxHeight, Math.max(0, props.maxHeight))
|
|
249
|
+
} : placed;
|
|
250
|
+
continue;
|
|
251
|
+
}
|
|
252
|
+
const parent = layers.value[layer.depth - 1];
|
|
253
|
+
const trigger = (parent ? layerEls.get(parent.id) : void 0)?.querySelector(`[data-ctx-key="${escapeContextMenuSelector(layer.parentKey ?? "")}"]`);
|
|
254
|
+
if (!trigger) continue;
|
|
255
|
+
const rect = trigger.getBoundingClientRect();
|
|
256
|
+
const placed = roundBox(placeContextMenuSubmenu({
|
|
257
|
+
top: rect.top,
|
|
258
|
+
left: rect.left,
|
|
259
|
+
width: rect.width,
|
|
260
|
+
height: rect.height
|
|
261
|
+
}, popup, viewport, rtl));
|
|
262
|
+
next[layer.id] = props.maxHeight != null ? {
|
|
263
|
+
...placed,
|
|
264
|
+
maxHeight: Math.min(placed.maxHeight, Math.max(0, props.maxHeight))
|
|
265
|
+
} : placed;
|
|
266
|
+
}
|
|
267
|
+
if (!sameBoxes(boxes.value, next)) boxes.value = next;
|
|
268
|
+
}
|
|
269
|
+
function requestPlace() {
|
|
270
|
+
if (typeof window === "undefined" || !open.value) return;
|
|
271
|
+
if (frame) return;
|
|
272
|
+
frame = window.requestAnimationFrame(() => {
|
|
273
|
+
frame = 0;
|
|
274
|
+
placeAll();
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
function observeLayers() {
|
|
278
|
+
if (typeof ResizeObserver === "undefined") return;
|
|
279
|
+
if (!resizeObserver) resizeObserver = new ResizeObserver(() => requestPlace());
|
|
280
|
+
resizeObserver.disconnect();
|
|
281
|
+
for (const el of layerEls.values()) resizeObserver.observe(el);
|
|
282
|
+
}
|
|
283
|
+
function setLayerEl(id, value) {
|
|
284
|
+
if (value instanceof HTMLElement) {
|
|
285
|
+
if (layerEls.get(id) === value) return;
|
|
286
|
+
layerEls.set(id, value);
|
|
287
|
+
} else {
|
|
288
|
+
if (!layerEls.has(id)) return;
|
|
289
|
+
layerEls.delete(id);
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
if (open.value) {
|
|
293
|
+
observeLayers();
|
|
294
|
+
requestPlace();
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
function layerRefFor(id) {
|
|
298
|
+
const existing = layerRefs.get(id);
|
|
299
|
+
if (existing) return existing;
|
|
300
|
+
const fn = (el) => setLayerEl(id, el);
|
|
301
|
+
layerRefs.set(id, fn);
|
|
302
|
+
return fn;
|
|
303
|
+
}
|
|
304
|
+
function itemsRefFor(id) {
|
|
305
|
+
const existing = itemRefs.get(id);
|
|
306
|
+
if (existing) return existing;
|
|
307
|
+
const fn = (el) => bindItems(id, el);
|
|
308
|
+
itemRefs.set(id, fn);
|
|
309
|
+
return fn;
|
|
310
|
+
}
|
|
311
|
+
function bindItems(id, value) {
|
|
312
|
+
if (value && typeof value === "object" && "getHighlight" in value && "setHighlight" in value && typeof value.getHighlight === "function" && typeof value.setHighlight === "function") {
|
|
313
|
+
itemLists.set(id, value);
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
itemLists.delete(id);
|
|
317
|
+
}
|
|
318
|
+
function layerStyle(id) {
|
|
319
|
+
const box = boxes.value[id];
|
|
320
|
+
const style = {
|
|
321
|
+
top: `${box?.top ?? anchor.value.y}px`,
|
|
322
|
+
left: `${box?.left ?? anchor.value.x}px`,
|
|
323
|
+
zIndex: "var(--rs-ctx-z)"
|
|
324
|
+
};
|
|
325
|
+
if (box) style.maxHeight = `${box.maxHeight}px`;
|
|
326
|
+
else if (props.maxHeight != null) style.maxHeight = `${Math.max(0, props.maxHeight)}px`;
|
|
327
|
+
if (props.radius) {
|
|
328
|
+
const radius = rsRadiusCss(props.radius);
|
|
329
|
+
style["--rs-ctx-radius"] = radius;
|
|
330
|
+
style["--rs-ctx-item-radius"] = radius;
|
|
331
|
+
}
|
|
332
|
+
return style;
|
|
333
|
+
}
|
|
334
|
+
function isInsideMenu(target) {
|
|
335
|
+
if (!(target instanceof Node)) return false;
|
|
336
|
+
for (const el of layerEls.values()) if (el === target || el.contains(target)) return true;
|
|
337
|
+
return false;
|
|
338
|
+
}
|
|
339
|
+
function layerIdFromTarget(target) {
|
|
340
|
+
if (target instanceof Node) for (const layer of [...layers.value].reverse()) {
|
|
341
|
+
const el = layerEls.get(layer.id);
|
|
342
|
+
if (el && (el === target || el.contains(target))) return layer.id;
|
|
343
|
+
}
|
|
344
|
+
return layers.value[layers.value.length - 1]?.id ?? "root";
|
|
345
|
+
}
|
|
346
|
+
function focusWithoutScroll(el) {
|
|
347
|
+
try {
|
|
348
|
+
el.focus({ preventScroll: true });
|
|
349
|
+
} catch {
|
|
350
|
+
el.focus();
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
function roundBox(box) {
|
|
354
|
+
return {
|
|
355
|
+
top: Math.round(box.top),
|
|
356
|
+
left: Math.round(box.left),
|
|
357
|
+
maxHeight: Math.round(box.maxHeight),
|
|
358
|
+
originX: box.originX,
|
|
359
|
+
originY: box.originY
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
function focusLayerItem(layerId, key) {
|
|
363
|
+
const root = layerEls.get(layerId);
|
|
364
|
+
if (!root) return;
|
|
365
|
+
if (!key) {
|
|
366
|
+
focusWithoutScroll(root);
|
|
367
|
+
return;
|
|
368
|
+
}
|
|
369
|
+
const el = root.querySelector(`[data-ctx-key="${escapeContextMenuSelector(key)}"]`);
|
|
370
|
+
if (el) focusWithoutScroll(el);
|
|
371
|
+
else focusWithoutScroll(root);
|
|
372
|
+
}
|
|
373
|
+
function clearSubOpen() {
|
|
374
|
+
if (!subOpenTimer) return;
|
|
375
|
+
clearTimeout(subOpenTimer);
|
|
376
|
+
subOpenTimer = void 0;
|
|
377
|
+
}
|
|
378
|
+
function clearSubClose() {
|
|
379
|
+
if (!subCloseTimer) return;
|
|
380
|
+
clearTimeout(subCloseTimer);
|
|
381
|
+
subCloseTimer = void 0;
|
|
382
|
+
}
|
|
383
|
+
function clearSubTimers() {
|
|
384
|
+
clearSubOpen();
|
|
385
|
+
clearSubClose();
|
|
386
|
+
}
|
|
387
|
+
function clearTypeahead() {
|
|
388
|
+
typeaheadQuery = "";
|
|
389
|
+
if (!typeaheadTimer) return;
|
|
390
|
+
clearTimeout(typeaheadTimer);
|
|
391
|
+
typeaheadTimer = void 0;
|
|
392
|
+
}
|
|
393
|
+
function openSubmenu(key, depth) {
|
|
394
|
+
clearSubTimers();
|
|
395
|
+
const next = submenuPath.value.slice(0, depth);
|
|
396
|
+
next.push(key);
|
|
397
|
+
const parent = findContextMenuItem(props.items, key);
|
|
398
|
+
if (!subHighlights.value[key]) subHighlights.value = {
|
|
399
|
+
...subHighlights.value,
|
|
400
|
+
[key]: firstEnabledContextMenuKey(parent?.children ?? [])
|
|
401
|
+
};
|
|
402
|
+
setPath(next);
|
|
403
|
+
const focusKey = subHighlights.value[key] ?? "";
|
|
404
|
+
settleLayers(() => focusLayerItem(key, focusKey));
|
|
405
|
+
}
|
|
406
|
+
function scheduleOpen(key, depth) {
|
|
407
|
+
clearSubOpen();
|
|
408
|
+
clearSubClose();
|
|
409
|
+
subOpenTimer = setTimeout(() => {
|
|
410
|
+
subOpenTimer = void 0;
|
|
411
|
+
openSubmenu(key, depth);
|
|
412
|
+
}, SUB_OPEN_MS);
|
|
413
|
+
}
|
|
414
|
+
function scheduleCloseFrom(depth) {
|
|
415
|
+
clearSubOpen();
|
|
416
|
+
clearSubClose();
|
|
417
|
+
subCloseTimer = setTimeout(() => {
|
|
418
|
+
subCloseTimer = void 0;
|
|
419
|
+
setPath(submenuPath.value.slice(0, depth));
|
|
420
|
+
}, SUB_CLOSE_MS);
|
|
421
|
+
}
|
|
422
|
+
function armLayerLeave() {
|
|
423
|
+
clearSubClose();
|
|
424
|
+
subCloseTimer = setTimeout(() => {
|
|
425
|
+
subCloseTimer = void 0;
|
|
426
|
+
clearSubOpen();
|
|
427
|
+
setPath([]);
|
|
428
|
+
}, SUB_CLOSE_MS);
|
|
429
|
+
}
|
|
430
|
+
function onItemHover(layerId, depth, item) {
|
|
431
|
+
clearSubClose();
|
|
432
|
+
if (item.disabled || !hasContextMenuChildren(item)) {
|
|
433
|
+
scheduleCloseFrom(depth);
|
|
434
|
+
return;
|
|
435
|
+
}
|
|
436
|
+
scheduleOpen(item.key, depth);
|
|
437
|
+
}
|
|
438
|
+
function onSelect(item, depth) {
|
|
439
|
+
if (item.disabled || isContextMenuSeparator(item)) return;
|
|
440
|
+
if (hasContextMenuChildren(item)) {
|
|
441
|
+
openSubmenu(item.key, depth);
|
|
442
|
+
return;
|
|
443
|
+
}
|
|
444
|
+
emit("select", item.key);
|
|
445
|
+
if (shouldCloseContextMenuOnSelect(item, props.hideOnSelect)) {
|
|
446
|
+
restoreOnClose = true;
|
|
447
|
+
setOpen(false);
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
function prunePath() {
|
|
451
|
+
const next = [];
|
|
452
|
+
let current = props.items;
|
|
453
|
+
for (const key of submenuPath.value) {
|
|
454
|
+
const parent = current.find((item) => item.key === key && hasContextMenuChildren(item));
|
|
455
|
+
if (!parent?.children?.length) break;
|
|
456
|
+
next.push(key);
|
|
457
|
+
current = parent.children;
|
|
458
|
+
}
|
|
459
|
+
if (next.length !== submenuPath.value.length) setPath(next);
|
|
460
|
+
}
|
|
461
|
+
function attach() {
|
|
462
|
+
if (overlayBound || typeof document === "undefined") return;
|
|
463
|
+
overlayBound = true;
|
|
464
|
+
document.addEventListener("pointerdown", onDocPointerDown, true);
|
|
465
|
+
document.addEventListener("keydown", onDocKeydown, true);
|
|
466
|
+
document.addEventListener("contextmenu", onDocContextMenu);
|
|
467
|
+
window.addEventListener("resize", requestPlace);
|
|
468
|
+
window.addEventListener("scroll", onWindowScroll, true);
|
|
469
|
+
}
|
|
470
|
+
function detach() {
|
|
471
|
+
if (typeof document !== "undefined" && overlayBound) {
|
|
472
|
+
document.removeEventListener("pointerdown", onDocPointerDown, true);
|
|
473
|
+
document.removeEventListener("keydown", onDocKeydown, true);
|
|
474
|
+
document.removeEventListener("contextmenu", onDocContextMenu);
|
|
475
|
+
window.removeEventListener("resize", requestPlace);
|
|
476
|
+
window.removeEventListener("scroll", onWindowScroll, true);
|
|
477
|
+
}
|
|
478
|
+
overlayBound = false;
|
|
479
|
+
if (frame && typeof window !== "undefined") {
|
|
480
|
+
window.cancelAnimationFrame(frame);
|
|
481
|
+
frame = 0;
|
|
482
|
+
}
|
|
483
|
+
resizeObserver?.disconnect();
|
|
484
|
+
resizeObserver = void 0;
|
|
485
|
+
}
|
|
486
|
+
function clearSwallow() {
|
|
487
|
+
if (swallowStop && typeof document !== "undefined") document.removeEventListener("click", swallowStop, true);
|
|
488
|
+
swallowStop = void 0;
|
|
489
|
+
}
|
|
490
|
+
function armSwallow() {
|
|
491
|
+
if (typeof document === "undefined") return;
|
|
492
|
+
clearSwallow();
|
|
493
|
+
const stop = (event) => {
|
|
494
|
+
event.preventDefault();
|
|
495
|
+
event.stopPropagation();
|
|
496
|
+
clearSwallow();
|
|
497
|
+
};
|
|
498
|
+
swallowStop = stop;
|
|
499
|
+
document.addEventListener("click", stop, true);
|
|
500
|
+
window.setTimeout(() => {
|
|
501
|
+
if (swallowStop === stop) clearSwallow();
|
|
502
|
+
}, 400);
|
|
503
|
+
}
|
|
504
|
+
function onDocPointerDown(event) {
|
|
505
|
+
if (!open.value || event.button !== 0) return;
|
|
506
|
+
if (isInsideMenu(event.target)) return;
|
|
507
|
+
armSwallow();
|
|
508
|
+
restoreOnClose = false;
|
|
509
|
+
setOpen(false);
|
|
510
|
+
}
|
|
511
|
+
function onDocContextMenu(event) {
|
|
512
|
+
if (!open.value || ignoreContextClose) return;
|
|
513
|
+
if (isInsideMenu(event.target)) {
|
|
514
|
+
event.preventDefault();
|
|
515
|
+
return;
|
|
516
|
+
}
|
|
517
|
+
if (triggerEl.value && event.target instanceof Node && triggerEl.value.contains(event.target)) return;
|
|
518
|
+
restoreOnClose = false;
|
|
519
|
+
setOpen(false);
|
|
520
|
+
}
|
|
521
|
+
function onWindowScroll(event) {
|
|
522
|
+
if (!open.value) return;
|
|
523
|
+
const target = event.target;
|
|
524
|
+
if (target instanceof Node && isInsideMenu(target)) return;
|
|
525
|
+
restoreOnClose = false;
|
|
526
|
+
setOpen(false);
|
|
527
|
+
}
|
|
528
|
+
function closeTopLayer() {
|
|
529
|
+
if (!submenuPath.value.length) {
|
|
530
|
+
restoreOnClose = true;
|
|
531
|
+
setOpen(false);
|
|
532
|
+
return;
|
|
533
|
+
}
|
|
534
|
+
setPath(submenuPath.value.slice(0, -1));
|
|
535
|
+
nextTick(() => {
|
|
536
|
+
const parent = layers.value.at(-1);
|
|
537
|
+
if (parent) focusLayerItem(parent.id, highlightOf(parent.id));
|
|
538
|
+
});
|
|
539
|
+
}
|
|
540
|
+
function moveHighlight(layerId, key) {
|
|
541
|
+
setHighlight(layerId, key);
|
|
542
|
+
focusLayerItem(layerId, key);
|
|
543
|
+
}
|
|
544
|
+
function onTypeahead(layerId, items, key) {
|
|
545
|
+
typeaheadQuery += key.toLowerCase();
|
|
546
|
+
if (typeaheadTimer) clearTimeout(typeaheadTimer);
|
|
547
|
+
typeaheadTimer = setTimeout(() => {
|
|
548
|
+
typeaheadQuery = "";
|
|
549
|
+
typeaheadTimer = void 0;
|
|
550
|
+
}, 500);
|
|
551
|
+
const list = listContextMenuLayerItems(items);
|
|
552
|
+
const from = list.findIndex((item) => item.key === highlightOf(layerId));
|
|
553
|
+
const index = matchContextMenuTypeahead(items, typeaheadQuery, from);
|
|
554
|
+
const next = index >= 0 ? list[index]?.key : "";
|
|
555
|
+
if (next) moveHighlight(layerId, next);
|
|
556
|
+
}
|
|
557
|
+
function onLayerKey(event, layer) {
|
|
558
|
+
const keys = resolveContextMenuKeys(isRtl.value);
|
|
559
|
+
if (event.key === "Escape") {
|
|
560
|
+
event.preventDefault();
|
|
561
|
+
event.stopPropagation();
|
|
562
|
+
closeTopLayer();
|
|
563
|
+
return;
|
|
564
|
+
}
|
|
565
|
+
if (event.key === "Tab") {
|
|
566
|
+
restoreOnClose = false;
|
|
567
|
+
setOpen(false);
|
|
568
|
+
return;
|
|
569
|
+
}
|
|
570
|
+
if (event.key === "ArrowDown" || event.key === "ArrowUp") {
|
|
571
|
+
event.preventDefault();
|
|
572
|
+
event.stopPropagation();
|
|
573
|
+
const delta = event.key === "ArrowDown" ? 1 : -1;
|
|
574
|
+
moveHighlight(layer.id, stepContextMenuKey(layer.items, highlightOf(layer.id), delta));
|
|
575
|
+
return;
|
|
576
|
+
}
|
|
577
|
+
if (event.key === "Home" || event.key === "End") {
|
|
578
|
+
event.preventDefault();
|
|
579
|
+
event.stopPropagation();
|
|
580
|
+
const next = event.key === "Home" ? firstEnabledContextMenuKey(layer.items) : lastEnabledContextMenuKey(layer.items);
|
|
581
|
+
moveHighlight(layer.id, next);
|
|
582
|
+
return;
|
|
583
|
+
}
|
|
584
|
+
if (event.key === keys.openSub) {
|
|
585
|
+
const current = listContextMenuLayerItems(layer.items).find((item) => item.key === highlightOf(layer.id));
|
|
586
|
+
if (current && hasContextMenuChildren(current) && !current.disabled) {
|
|
587
|
+
event.preventDefault();
|
|
588
|
+
event.stopPropagation();
|
|
589
|
+
openSubmenu(current.key, layer.depth);
|
|
590
|
+
}
|
|
591
|
+
return;
|
|
592
|
+
}
|
|
593
|
+
if (event.key === keys.closeSub && layer.depth > 0) {
|
|
594
|
+
event.preventDefault();
|
|
595
|
+
event.stopPropagation();
|
|
596
|
+
setPath(submenuPath.value.slice(0, layer.depth - 1));
|
|
597
|
+
nextTick(() => {
|
|
598
|
+
const parent = layers.value[layer.depth - 1];
|
|
599
|
+
if (parent) focusLayerItem(parent.id, highlightOf(parent.id));
|
|
600
|
+
});
|
|
601
|
+
return;
|
|
602
|
+
}
|
|
603
|
+
if (event.key.length === 1 && !event.ctrlKey && !event.metaKey && !event.altKey) {
|
|
604
|
+
event.preventDefault();
|
|
605
|
+
onTypeahead(layer.id, layer.items, event.key);
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
function onDocKeydown(event) {
|
|
609
|
+
if (!open.value || event.isComposing) return;
|
|
610
|
+
const target = event.target;
|
|
611
|
+
if (target instanceof HTMLElement && target.closest("input, textarea, select, [contenteditable=\"true\"]")) {
|
|
612
|
+
if (event.key !== "Escape") return;
|
|
613
|
+
event.preventDefault();
|
|
614
|
+
event.stopPropagation();
|
|
615
|
+
restoreOnClose = true;
|
|
616
|
+
setOpen(false);
|
|
617
|
+
return;
|
|
618
|
+
}
|
|
619
|
+
const layerId = layerIdFromTarget(target);
|
|
620
|
+
const layer = layers.value.find((item) => item.id === layerId) ?? layers.value.at(-1);
|
|
621
|
+
if (!layer) return;
|
|
622
|
+
onLayerKey(event, layer);
|
|
623
|
+
}
|
|
39
624
|
function onTriggerContextMenu(event) {
|
|
40
|
-
if (
|
|
625
|
+
if (props.disabled) return;
|
|
626
|
+
if (!hasActionableContextMenuItems(props.items)) {
|
|
41
627
|
event.preventDefault();
|
|
42
|
-
|
|
628
|
+
setOpen(false);
|
|
629
|
+
return;
|
|
43
630
|
}
|
|
631
|
+
event.preventDefault();
|
|
632
|
+
ignoreContextClose = true;
|
|
633
|
+
queueMicrotask(() => {
|
|
634
|
+
ignoreContextClose = false;
|
|
635
|
+
});
|
|
636
|
+
setOpen(true, {
|
|
637
|
+
x: event.clientX,
|
|
638
|
+
y: event.clientY
|
|
639
|
+
});
|
|
44
640
|
}
|
|
45
|
-
function
|
|
46
|
-
|
|
641
|
+
function onTriggerKeydown(event) {
|
|
642
|
+
if (props.disabled || event.isComposing || open.value) return;
|
|
643
|
+
if (event.key === "ContextMenu" || event.shiftKey && event.key === "F10") {
|
|
644
|
+
event.preventDefault();
|
|
645
|
+
setOpen(true);
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
function assignTrigger(value) {
|
|
649
|
+
triggerEl.value = resolveContextMenuElement(value);
|
|
650
|
+
}
|
|
651
|
+
function flattenNodes(nodes, out = []) {
|
|
652
|
+
if (nodes == null || typeof nodes === "boolean") return out;
|
|
653
|
+
if (Array.isArray(nodes)) {
|
|
654
|
+
for (const node of nodes) flattenNodes(node, out);
|
|
655
|
+
return out;
|
|
656
|
+
}
|
|
657
|
+
if (!isVNode(nodes)) return out;
|
|
658
|
+
if (nodes.type === Comment || nodes.type === Text) return out;
|
|
659
|
+
if (nodes.type === Fragment && Array.isArray(nodes.children)) {
|
|
660
|
+
flattenNodes(nodes.children, out);
|
|
661
|
+
return out;
|
|
662
|
+
}
|
|
663
|
+
out.push(nodes);
|
|
664
|
+
return out;
|
|
665
|
+
}
|
|
666
|
+
function callListeners(existing, event) {
|
|
667
|
+
if (typeof existing === "function") existing(event);
|
|
668
|
+
else if (Array.isArray(existing)) {
|
|
669
|
+
for (const fn of existing) if (typeof fn === "function") fn(event);
|
|
670
|
+
}
|
|
47
671
|
}
|
|
672
|
+
const TriggerHost = defineComponent({
|
|
673
|
+
name: "RsContextMenuTrigger",
|
|
674
|
+
setup() {
|
|
675
|
+
return () => {
|
|
676
|
+
const nodes = flattenNodes(slots.default?.());
|
|
677
|
+
const target = nodes[0];
|
|
678
|
+
if (!target) return null;
|
|
679
|
+
const cloned = cloneVNode(target, {
|
|
680
|
+
ref: assignTrigger,
|
|
681
|
+
"aria-haspopup": "menu",
|
|
682
|
+
"aria-expanded": open.value ? "true" : "false",
|
|
683
|
+
"aria-controls": open.value ? menuId.value : void 0,
|
|
684
|
+
onContextmenu: (event) => {
|
|
685
|
+
callListeners(target.props?.onContextmenu, event);
|
|
686
|
+
onTriggerContextMenu(event);
|
|
687
|
+
},
|
|
688
|
+
onKeydown: (event) => {
|
|
689
|
+
callListeners(target.props?.onKeydown, event);
|
|
690
|
+
onTriggerKeydown(event);
|
|
691
|
+
}
|
|
692
|
+
}, true);
|
|
693
|
+
return nodes.length === 1 ? cloned : [cloned, ...nodes.slice(1)];
|
|
694
|
+
};
|
|
695
|
+
}
|
|
696
|
+
});
|
|
697
|
+
__expose({
|
|
698
|
+
open: (point) => setOpen(true, point),
|
|
699
|
+
close: () => {
|
|
700
|
+
restoreOnClose = false;
|
|
701
|
+
setOpen(false);
|
|
702
|
+
}
|
|
703
|
+
});
|
|
704
|
+
watch(open, (isOpen) => {
|
|
705
|
+
const skip = !openWatchReady;
|
|
706
|
+
openWatchReady = true;
|
|
707
|
+
if (isOpen) {
|
|
708
|
+
if (props.disabled || !hasActionableContextMenuItems(props.items)) {
|
|
709
|
+
open.value = false;
|
|
710
|
+
return;
|
|
711
|
+
}
|
|
712
|
+
claimContextMenu(requestClose);
|
|
713
|
+
settled.value = {};
|
|
714
|
+
submenuPath.value = [];
|
|
715
|
+
subHighlights.value = {};
|
|
716
|
+
rootHighlight.value = firstEnabledContextMenuKey(props.items);
|
|
717
|
+
syncPanelChrome();
|
|
718
|
+
if (!pointLocked) anchor.value = pointFromTrigger();
|
|
719
|
+
attach();
|
|
720
|
+
if (typeof document !== "undefined") restoreTarget = document.activeElement instanceof HTMLElement ? document.activeElement : triggerEl.value;
|
|
721
|
+
settleLayers(() => focusLayerItem("root", rootHighlight.value), () => {
|
|
722
|
+
if (!pointLocked) anchor.value = pointFromTrigger();
|
|
723
|
+
syncPanelChrome();
|
|
724
|
+
observeLayers();
|
|
725
|
+
});
|
|
726
|
+
if (!skip) emit("openChange", true);
|
|
727
|
+
return;
|
|
728
|
+
}
|
|
729
|
+
detach();
|
|
730
|
+
releaseContextMenu(requestClose);
|
|
731
|
+
clearSubTimers();
|
|
732
|
+
clearTypeahead();
|
|
733
|
+
submenuPath.value = [];
|
|
734
|
+
settled.value = {};
|
|
735
|
+
boxes.value = {};
|
|
736
|
+
const shouldRestore = restoreOnClose;
|
|
737
|
+
restoreOnClose = false;
|
|
738
|
+
const back = restoreTarget;
|
|
739
|
+
restoreTarget = null;
|
|
740
|
+
pointLocked = false;
|
|
741
|
+
if (shouldRestore && back) focusWithoutScroll(back);
|
|
742
|
+
if (!skip) emit("openChange", false);
|
|
743
|
+
}, { immediate: true });
|
|
744
|
+
watch(() => props.items, (items) => {
|
|
745
|
+
if (!hasActionableContextMenuItems(items)) {
|
|
746
|
+
if (open.value) open.value = false;
|
|
747
|
+
return;
|
|
748
|
+
}
|
|
749
|
+
if (!open.value) return;
|
|
750
|
+
prunePath();
|
|
751
|
+
if (!listContextMenuLayerItems(items).some((item) => item.key === highlightOf("root") && !item.disabled)) {
|
|
752
|
+
const next = firstEnabledContextMenuKey(items);
|
|
753
|
+
rootHighlight.value = next;
|
|
754
|
+
itemLists.get("root")?.setHighlight(next);
|
|
755
|
+
}
|
|
756
|
+
requestPlace();
|
|
757
|
+
});
|
|
758
|
+
watch(() => props.disabled, (disabled) => {
|
|
759
|
+
if (disabled && open.value) open.value = false;
|
|
760
|
+
});
|
|
761
|
+
onUnmounted(() => {
|
|
762
|
+
detach();
|
|
763
|
+
releaseContextMenu(requestClose);
|
|
764
|
+
clearSubTimers();
|
|
765
|
+
clearTypeahead();
|
|
766
|
+
clearSwallow();
|
|
767
|
+
layerRefs.clear();
|
|
768
|
+
itemRefs.clear();
|
|
769
|
+
itemLists.clear();
|
|
770
|
+
});
|
|
48
771
|
return (_ctx, _cache) => {
|
|
49
|
-
return !__props.disabled ? (openBlock(), createBlock(unref(
|
|
50
|
-
key:
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
772
|
+
return openBlock(), createElementBlock(Fragment, null, [!__props.disabled ? (openBlock(), createBlock(unref(TriggerHost), { key: 0 })) : renderSlot(_ctx.$slots, "default", {}, void 0, void 0, 1), showPanel.value ? (openBlock(), createBlock(Teleport, {
|
|
773
|
+
key: 2,
|
|
774
|
+
to: portalTarget.value
|
|
775
|
+
}, [withDirectives(createElementVNode("div", _hoisted_1, [(openBlock(true), createElementBlock(Fragment, null, renderList(layers.value, (layer) => {
|
|
776
|
+
return openBlock(), createElementBlock("div", {
|
|
777
|
+
id: layer.id === "root" ? menuId.value : void 0,
|
|
778
|
+
key: layer.id,
|
|
779
|
+
ref_for: true,
|
|
780
|
+
ref: layerRefFor(layer.id),
|
|
781
|
+
class: normalizeClass(["rs-context-menu__content rs-native-scrollbar rs-motion-reduce", [
|
|
782
|
+
layer.id !== "root" && "rs-context-menu__sub-content",
|
|
783
|
+
__props.size && `rs-context-menu--${__props.size}`,
|
|
784
|
+
__props.popupClassName
|
|
785
|
+
]]),
|
|
786
|
+
role: "menu",
|
|
787
|
+
"aria-label": layer.id === "root" ? menuLabel.value : unref(t)("contextMenu.submenu"),
|
|
788
|
+
dir: panelDir.value,
|
|
789
|
+
lang: panelLang.value,
|
|
790
|
+
"data-rs-theme": panelTheme.value,
|
|
791
|
+
"data-placed": settled.value[layer.id] ? "" : void 0,
|
|
792
|
+
"data-origin-x": boxes.value[layer.id]?.originX,
|
|
793
|
+
"data-origin-y": boxes.value[layer.id]?.originY,
|
|
794
|
+
style: normalizeStyle(layerStyle(layer.id)),
|
|
795
|
+
tabindex: "-1",
|
|
796
|
+
onPointerenter: clearSubClose,
|
|
797
|
+
onPointerleave: armLayerLeave,
|
|
798
|
+
onContextmenu: _cache[0] || (_cache[0] = withModifiers(() => {}, ["prevent"]))
|
|
799
|
+
}, [createVNode(RsContextMenuItems_default, {
|
|
800
|
+
ref_for: true,
|
|
801
|
+
ref: itemsRefFor(layer.id),
|
|
802
|
+
items: layer.items,
|
|
803
|
+
highlight: layerHighlight(layer.id),
|
|
804
|
+
"open-key": layer.openKey,
|
|
805
|
+
"menu-id": menuId.value,
|
|
806
|
+
"layer-id": layer.id,
|
|
807
|
+
"icon-size": iconSize.value,
|
|
808
|
+
onSelect: ($event) => onSelect($event, layer.depth),
|
|
809
|
+
onHover: ($event) => onItemHover(layer.id, layer.depth, $event)
|
|
57
810
|
}, {
|
|
58
|
-
|
|
811
|
+
item: withCtx((slotProps) => [renderSlot(_ctx.$slots, "item", mergeProps({ ref_for: true }, slotProps), () => [createElementVNode("span", _hoisted_3, toDisplayString(slotProps.item.label), 1), slotProps.item.hint ? (openBlock(), createElementBlock("span", _hoisted_4, toDisplayString(slotProps.item.hint), 1)) : createCommentVNode("", true)])]),
|
|
59
812
|
_: 3
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
_: 1
|
|
72
|
-
})]),
|
|
73
|
-
_: 1
|
|
74
|
-
})]),
|
|
75
|
-
_: 3
|
|
76
|
-
}, 8, ["open"])) : renderSlot(_ctx.$slots, "default", {}, void 0, void 0, 1);
|
|
813
|
+
}, 8, [
|
|
814
|
+
"items",
|
|
815
|
+
"highlight",
|
|
816
|
+
"open-key",
|
|
817
|
+
"menu-id",
|
|
818
|
+
"layer-id",
|
|
819
|
+
"icon-size",
|
|
820
|
+
"onSelect",
|
|
821
|
+
"onHover"
|
|
822
|
+
])], 46, _hoisted_2);
|
|
823
|
+
}), 128))], 512), [[vShow, open.value]])], 8, ["to"])) : createCommentVNode("", true)], 64);
|
|
77
824
|
};
|
|
78
825
|
}
|
|
79
826
|
});
|