@vuetkit/components 0.0.16 → 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, 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
 
@@ -124,6 +124,64 @@ declare function setDeepProperty(data: Recordable, propArr: string[], value: unk
124
124
  declare function useForm(options: undefined): [null, Recordable];
125
125
  declare function useForm<T extends object>(options: FormOptions<T>): FormReturnType<T>;
126
126
  //#endregion
127
+ //#region src/navigation/useDropdown/index.d.ts
128
+ type ElDropdownProps = InstanceType<typeof ElDropdown>['$props'];
129
+ interface DropdownItem {
130
+ label?: string;
131
+ command?: string | number | object;
132
+ disabled?: boolean;
133
+ divided?: boolean;
134
+ icon?: string | Component;
135
+ render?: (val: unknown) => VNode;
136
+ }
137
+ interface DropdownOptions<T> extends Partial<ElDropdownProps> {
138
+ items?: DropdownItem[];
139
+ service?: RequestService<T>;
140
+ params?: unknown;
141
+ formatData?: (data: T) => DropdownItem[];
142
+ defaultCommand?: string | number | object;
143
+ onCommand?: (command: string | number | object) => void;
144
+ onVisibleChange?: (visible: boolean) => void;
145
+ onClick?: () => void;
146
+ }
147
+ type DropdownReturnType = [Component, Ref<string | number | object | undefined>];
148
+ declare function useDropdown<T>(options: DropdownOptions<T>): DropdownReturnType;
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
127
185
  //#region src/navigation/useSteps/index.d.ts
128
186
  interface StepsColumn extends Partial<StepProps> {
129
187
  title?: string;
@@ -223,4 +281,4 @@ interface TableOptions<T extends DefaultRow> extends TableProps<T> {
223
281
  type TableReturn = [Component];
224
282
  declare function useTable<T extends DefaultRow>(options: TableOptions<T>): TableReturn;
225
283
  //#endregion
226
- export { AsyncConfirmOptions, CollapseColumn, CollapseOptions, CollapseReturnType, CustomRender, DefaultComponentKey, DescriptionsColumn, DescriptionsOptions, DescriptionsReturnType, FormItemType, FormOptions, FormReturnType, FormRuleFn, FormSchema, PaginationOptions, Recordable, StepsColumn, StepsOptions, StepsReturnType, TableColumnOptions, TableOptions, TableReturn, TabsColumn, TabsOptions, TabsReturnType, setDeepProperty, useAsyncConfirm, useCollapse, useDescriptions, useDialog, 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, 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
@@ -425,6 +425,139 @@ function useForm(options) {
425
425
  }];
426
426
  }
427
427
  //#endregion
428
+ //#region src/navigation/useDropdown/index.ts
429
+ function useDropdown(options) {
430
+ const { items = [], service, params, formatData, defaultCommand, onCommand, onVisibleChange, onClick, ...rest } = options;
431
+ const { data, loading } = service ? useRequest(service, {
432
+ defaultParams: params,
433
+ formatData: formatData || void 0
434
+ }) : {};
435
+ const command = ref(defaultCommand);
436
+ const dropdownColumns = computed(() => (data === null || data === void 0 ? void 0 : data.value) || items);
437
+ return [defineComponent({ setup(_, { slots, emit }) {
438
+ const renderItems = () => {
439
+ var _dropdownColumns$valu;
440
+ return (_dropdownColumns$valu = dropdownColumns.value) === null || _dropdownColumns$valu === void 0 ? void 0 : _dropdownColumns$valu.map((item) => {
441
+ return h(ElDropdownItem, {
442
+ command: item.command,
443
+ disabled: item.disabled,
444
+ divided: item.divided,
445
+ icon: item.icon
446
+ }, { default: () => {
447
+ if (item === null || item === void 0 ? void 0 : item.render) return item.render(item);
448
+ return item.label || "";
449
+ } });
450
+ });
451
+ };
452
+ const handleCommand = (cmd) => {
453
+ command.value = cmd;
454
+ onCommand === null || onCommand === void 0 || onCommand(cmd);
455
+ emit("command", cmd);
456
+ };
457
+ const handleVisibleChange = (visible) => {
458
+ onVisibleChange === null || onVisibleChange === void 0 || onVisibleChange(visible);
459
+ emit("visible-change", visible);
460
+ };
461
+ const handleClick = () => {
462
+ onClick === null || onClick === void 0 || onClick();
463
+ emit("click");
464
+ };
465
+ return () => {
466
+ var _loading$value;
467
+ return withDirectives(h(ElDropdown, {
468
+ ...rest,
469
+ "onCommand": handleCommand,
470
+ "onVisible-change": handleVisibleChange,
471
+ "onClick": handleClick
472
+ }, {
473
+ default: () => {
474
+ if (slots.default) return slots.default();
475
+ return "";
476
+ },
477
+ dropdown: () => {
478
+ if (slots.dropdown) return slots.dropdown();
479
+ return h(ElDropdownMenu, {}, { default: () => {
480
+ if (!dropdownColumns.value.length) return "";
481
+ return renderItems();
482
+ } });
483
+ }
484
+ }), [[vLoading, (_loading$value = loading === null || loading === void 0 ? void 0 : loading.value) !== null && _loading$value !== void 0 ? _loading$value : false]]);
485
+ };
486
+ } }), command];
487
+ }
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
428
561
  //#region src/navigation/useSteps/index.ts
429
562
  function useSteps(options) {
430
563
  const { steps = [], service, params, formatData, defaultActive = 0, ...rest } = options;
@@ -698,4 +831,4 @@ function useTable(options) {
698
831
  })];
699
832
  }
700
833
  //#endregion
701
- export { setDeepProperty, useAsyncConfirm, useCollapse, useDescriptions, useDialog, 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.16",
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.16",
25
- "@vuetkit/shared": "0.0.16"
24
+ "@vuetkit/core": "0.0.18",
25
+ "@vuetkit/shared": "0.0.18"
26
26
  },
27
27
  "scripts": {
28
28
  "build": "tsdown --config-loader tsx"