@vuetkit/components 0.0.17 → 0.0.18

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/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { RequestService } from "@vuetkit/core";
2
- import { CollapseItemProps, CollapseModelValue, CollapseProps, ComponentSize, DescriptionItemProps, DescriptionProps, DialogProps, ElDropdown, FormRules, MessageProps, MessageType, PaginationProps, StepProps, StepsProps, TabPaneName, TableProps, TabsPaneContext, TabsProps } from "element-plus";
2
+ import { CollapseItemProps, CollapseModelValue, CollapseProps, ComponentSize, DescriptionItemProps, DescriptionProps, DialogProps, ElDropdown, ElMenu, FormRules, MessageProps, MessageType, PaginationProps, StepProps, StepsProps, TabPaneName, TableProps, TabsPaneContext, TabsProps } from "element-plus";
3
3
  import { CSSProperties, Component, MaybeRef, Ref, VNode } from "vue";
4
4
  import { TableColumnProps } from "element-plus/es/components/table/src/table-column/defaults.mjs";
5
5
 
@@ -147,6 +147,41 @@ interface DropdownOptions<T> extends Partial<ElDropdownProps> {
147
147
  type DropdownReturnType = [Component, Ref<string | number | object | undefined>];
148
148
  declare function useDropdown<T>(options: DropdownOptions<T>): DropdownReturnType;
149
149
  //#endregion
150
+ //#region src/navigation/useMenu/index.d.ts
151
+ type ElMenuProps = InstanceType<typeof ElMenu>['$props'];
152
+ interface MenuColumn {
153
+ index: string;
154
+ label?: string;
155
+ disabled?: boolean;
156
+ route?: unknown;
157
+ children?: MenuColumn[];
158
+ render?: (val: unknown) => VNode;
159
+ renderTitle?: (val: unknown) => VNode;
160
+ groupTitle?: string;
161
+ popperClass?: string;
162
+ popperStyle?: string | CSSProperties;
163
+ showTimeout?: number;
164
+ hideTimeout?: number;
165
+ teleported?: boolean;
166
+ popperOffset?: number;
167
+ expandCloseIcon?: string | Component;
168
+ expandOpenIcon?: string | Component;
169
+ collapseCloseIcon?: string | Component;
170
+ collapseOpenIcon?: string | Component;
171
+ }
172
+ interface MenuOptions<T> extends Partial<ElMenuProps> {
173
+ items?: MenuColumn[];
174
+ service?: RequestService<T>;
175
+ params?: unknown;
176
+ formatData?: (data: T) => MenuColumn[];
177
+ defaultActive?: string;
178
+ onSelect?: (index: string, indexPath: string[], item: unknown, routerResult?: Promise<unknown>) => void;
179
+ onOpen?: (index: string, indexPath: string[]) => void;
180
+ onClose?: (index: string, indexPath: string[]) => void;
181
+ }
182
+ type MenuReturnType = [Component, Ref<string>];
183
+ declare function useMenu<T>(options: MenuOptions<T>): MenuReturnType;
184
+ //#endregion
150
185
  //#region src/navigation/useSteps/index.d.ts
151
186
  interface StepsColumn extends Partial<StepProps> {
152
187
  title?: string;
@@ -246,4 +281,4 @@ interface TableOptions<T extends DefaultRow> extends TableProps<T> {
246
281
  type TableReturn = [Component];
247
282
  declare function useTable<T extends DefaultRow>(options: TableOptions<T>): TableReturn;
248
283
  //#endregion
249
- export { AsyncConfirmOptions, CollapseColumn, CollapseOptions, CollapseReturnType, CustomRender, DefaultComponentKey, DescriptionsColumn, DescriptionsOptions, DescriptionsReturnType, DropdownItem, DropdownOptions, DropdownReturnType, FormItemType, FormOptions, FormReturnType, FormRuleFn, FormSchema, PaginationOptions, Recordable, StepsColumn, StepsOptions, StepsReturnType, TableColumnOptions, TableOptions, TableReturn, TabsColumn, TabsOptions, TabsReturnType, setDeepProperty, useAsyncConfirm, useCollapse, useDescriptions, useDialog, useDropdown, useForm, useMessage, useSteps, useTable, useTabs };
284
+ export { AsyncConfirmOptions, CollapseColumn, CollapseOptions, CollapseReturnType, CustomRender, DefaultComponentKey, DescriptionsColumn, DescriptionsOptions, DescriptionsReturnType, DropdownItem, DropdownOptions, DropdownReturnType, FormItemType, FormOptions, FormReturnType, FormRuleFn, FormSchema, MenuColumn, MenuOptions, MenuReturnType, PaginationOptions, Recordable, StepsColumn, StepsOptions, StepsReturnType, TableColumnOptions, TableOptions, TableReturn, TabsColumn, TabsOptions, TabsReturnType, setDeepProperty, useAsyncConfirm, useCollapse, useDescriptions, useDialog, useDropdown, useForm, useMenu, useMessage, useSteps, useTable, useTabs };
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { useRequest } from "@vuetkit/core";
2
- import { ElButton, ElCascader, ElCheckbox, ElCol, ElCollapse, ElCollapseItem, ElColorPicker, ElDatePicker, ElDescriptions, ElDescriptionsItem, ElDialog, ElDropdown, ElDropdownItem, ElDropdownMenu, ElForm, ElFormItem, ElInput, ElInputNumber, ElInputOtp, ElMention, ElMessage, ElMessageBox, ElPagination, ElRadio, ElRate, ElRow, ElScrollbar, ElSelect, ElSelectV2, ElSlider, ElStep, ElSteps, ElSwitch, ElTabPane, ElTable, ElTableColumn, ElTabs, ElTimePicker, ElTimeSelect, ElTransfer, ElTreeSelect, ElUpload, vLoading } from "element-plus";
2
+ import { ElButton, ElCascader, ElCheckbox, ElCol, ElCollapse, ElCollapseItem, ElColorPicker, ElDatePicker, ElDescriptions, ElDescriptionsItem, ElDialog, ElDropdown, ElDropdownItem, ElDropdownMenu, ElForm, ElFormItem, ElInput, ElInputNumber, ElInputOtp, ElMention, ElMenu, ElMenuItem, ElMenuItemGroup, ElMessage, ElMessageBox, ElPagination, ElRadio, ElRate, ElRow, ElScrollbar, ElSelect, ElSelectV2, ElSlider, ElStep, ElSteps, ElSubMenu, ElSwitch, ElTabPane, ElTable, ElTableColumn, ElTabs, ElTimePicker, ElTimeSelect, ElTransfer, ElTreeSelect, ElUpload, vLoading } from "element-plus";
3
3
  import { computed, defineComponent, h, nextTick, onMounted, reactive, ref, toValue, useTemplateRef, watch, withDirectives } from "vue";
4
4
  import { isFunc, realObj } from "@vuetkit/shared";
5
5
  //#region src/data/useCollapse/index.ts
@@ -486,6 +486,78 @@ function useDropdown(options) {
486
486
  } }), command];
487
487
  }
488
488
  //#endregion
489
+ //#region src/navigation/useMenu/index.ts
490
+ function useMenu(options) {
491
+ const { items = [], service, params, formatData, defaultActive = "", onSelect, onOpen, onClose, ...rest } = options;
492
+ const { data, loading } = service ? useRequest(service, {
493
+ defaultParams: params,
494
+ formatData: formatData || void 0
495
+ }) : {};
496
+ const activeIndex = ref(defaultActive);
497
+ const menuColumns = computed(() => (data === null || data === void 0 ? void 0 : data.value) || items);
498
+ const renderMenuItem = (item) => {
499
+ var _item$children, _item$children2;
500
+ if (((_item$children = item.children) === null || _item$children === void 0 ? void 0 : _item$children.length) && item.groupTitle) return h(ElMenuItemGroup, { title: item.groupTitle }, { default: () => item.children.map((child) => renderMenuItem(child)) });
501
+ if ((_item$children2 = item.children) === null || _item$children2 === void 0 ? void 0 : _item$children2.length) return h(ElSubMenu, {
502
+ index: item.index,
503
+ disabled: item.disabled,
504
+ popperClass: item.popperClass,
505
+ popperStyle: item.popperStyle,
506
+ showTimeout: item.showTimeout,
507
+ hideTimeout: item.hideTimeout,
508
+ teleported: item.teleported,
509
+ popperOffset: item.popperOffset,
510
+ expandCloseIcon: item.expandCloseIcon,
511
+ expandOpenIcon: item.expandOpenIcon,
512
+ collapseCloseIcon: item.collapseCloseIcon,
513
+ collapseOpenIcon: item.collapseOpenIcon
514
+ }, {
515
+ title: () => {
516
+ if (item === null || item === void 0 ? void 0 : item.renderTitle) return item.renderTitle(item);
517
+ return item.label || "";
518
+ },
519
+ default: () => item.children.map((child) => renderMenuItem(child))
520
+ });
521
+ return h(ElMenuItem, {
522
+ index: item.index,
523
+ disabled: item.disabled,
524
+ route: item.route
525
+ }, { default: () => {
526
+ if (item === null || item === void 0 ? void 0 : item.render) return item.render(item);
527
+ return item.label || "";
528
+ } });
529
+ };
530
+ return [defineComponent({ setup(_, { slots, emit }) {
531
+ const handleSelect = (index, indexPath, item, routerResult) => {
532
+ activeIndex.value = index;
533
+ onSelect === null || onSelect === void 0 || onSelect(index, indexPath, item, routerResult);
534
+ emit("select", index, indexPath, item, routerResult);
535
+ };
536
+ const handleOpen = (index, indexPath) => {
537
+ onOpen === null || onOpen === void 0 || onOpen(index, indexPath);
538
+ emit("open", index, indexPath);
539
+ };
540
+ const handleClose = (index, indexPath) => {
541
+ onClose === null || onClose === void 0 || onClose(index, indexPath);
542
+ emit("close", index, indexPath);
543
+ };
544
+ return () => {
545
+ var _loading$value;
546
+ return withDirectives(h(ElMenu, {
547
+ ...rest,
548
+ defaultActive: activeIndex.value,
549
+ onSelect: handleSelect,
550
+ onOpen: handleOpen,
551
+ onClose: handleClose
552
+ }, { default: () => {
553
+ if (slots.default) return slots.default();
554
+ if (!menuColumns.value.length) return "";
555
+ return menuColumns.value.map((item) => renderMenuItem(item));
556
+ } }), [[vLoading, (_loading$value = loading === null || loading === void 0 ? void 0 : loading.value) !== null && _loading$value !== void 0 ? _loading$value : false]]);
557
+ };
558
+ } }), activeIndex];
559
+ }
560
+ //#endregion
489
561
  //#region src/navigation/useSteps/index.ts
490
562
  function useSteps(options) {
491
563
  const { steps = [], service, params, formatData, defaultActive = 0, ...rest } = options;
@@ -759,4 +831,4 @@ function useTable(options) {
759
831
  })];
760
832
  }
761
833
  //#endregion
762
- export { setDeepProperty, useAsyncConfirm, useCollapse, useDescriptions, useDialog, useDropdown, useForm, useMessage, useSteps, useTable, useTabs };
834
+ export { setDeepProperty, useAsyncConfirm, useCollapse, useDescriptions, useDialog, useDropdown, useForm, useMenu, useMessage, useSteps, useTable, useTabs };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vuetkit/components",
3
3
  "type": "module",
4
- "version": "0.0.17",
4
+ "version": "0.0.18",
5
5
  "description": "Collection of business development components for Vue3 projects",
6
6
  "author": "Kalu5",
7
7
  "license": "MIT",
@@ -21,8 +21,8 @@
21
21
  "vue": "^3.5.35"
22
22
  },
23
23
  "dependencies": {
24
- "@vuetkit/core": "0.0.17",
25
- "@vuetkit/shared": "0.0.17"
24
+ "@vuetkit/core": "0.0.18",
25
+ "@vuetkit/shared": "0.0.18"
26
26
  },
27
27
  "scripts": {
28
28
  "build": "tsdown --config-loader tsx"