@vuetkit/components 0.0.15 → 0.0.17

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,8 +1,27 @@
1
1
  import { RequestService } from "@vuetkit/core";
2
- import { 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, 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
 
6
+ //#region src/data/useCollapse/index.d.ts
7
+ interface CollapseColumn extends Partial<CollapseItemProps> {
8
+ title?: string;
9
+ name?: string | number;
10
+ render?: (val: unknown) => VNode;
11
+ renderTitle?: (val: unknown) => VNode;
12
+ renderIcon?: (val: unknown) => VNode;
13
+ }
14
+ interface CollapseOptions<T> extends Partial<CollapseProps> {
15
+ columns: CollapseColumn[];
16
+ service?: RequestService<T>;
17
+ params?: unknown;
18
+ formatData?: (data: T) => CollapseColumn[];
19
+ defaultActive?: CollapseModelValue;
20
+ onChange?: (activeNames: CollapseModelValue) => void;
21
+ }
22
+ type CollapseReturnType = [Component, Ref<CollapseModelValue>];
23
+ declare function useCollapse<T>(options: CollapseOptions<T>): CollapseReturnType;
24
+ //#endregion
6
25
  //#region src/data/useDescriptions/index.d.ts
7
26
  interface DescriptionsColumn extends Partial<DescriptionItemProps> {
8
27
  value?: string;
@@ -105,6 +124,29 @@ declare function setDeepProperty(data: Recordable, propArr: string[], value: unk
105
124
  declare function useForm(options: undefined): [null, Recordable];
106
125
  declare function useForm<T extends object>(options: FormOptions<T>): FormReturnType<T>;
107
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
108
150
  //#region src/navigation/useSteps/index.d.ts
109
151
  interface StepsColumn extends Partial<StepProps> {
110
152
  title?: string;
@@ -204,4 +246,4 @@ interface TableOptions<T extends DefaultRow> extends TableProps<T> {
204
246
  type TableReturn = [Component];
205
247
  declare function useTable<T extends DefaultRow>(options: TableOptions<T>): TableReturn;
206
248
  //#endregion
207
- export { AsyncConfirmOptions, CustomRender, DefaultComponentKey, DescriptionsColumn, DescriptionsOptions, DescriptionsReturnType, FormItemType, FormOptions, FormReturnType, FormRuleFn, FormSchema, PaginationOptions, Recordable, StepsColumn, StepsOptions, StepsReturnType, TableColumnOptions, TableOptions, TableReturn, TabsColumn, TabsOptions, TabsReturnType, setDeepProperty, useAsyncConfirm, useDescriptions, useDialog, useForm, useMessage, useSteps, useTable, useTabs };
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 };
package/dist/index.js CHANGED
@@ -1,7 +1,68 @@
1
1
  import { useRequest } from "@vuetkit/core";
2
- import { ElButton, ElCascader, ElCheckbox, ElCol, 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, 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";
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
+ //#region src/data/useCollapse/index.ts
6
+ function useCollapse(options) {
7
+ const { columns = [], service, params, formatData, defaultActive = [], onChange, ...rest } = options;
8
+ const { data, loading } = service ? useRequest(service, {
9
+ defaultParams: params,
10
+ formatData: formatData || void 0
11
+ }) : {};
12
+ const activeNames = ref(defaultActive);
13
+ const collapseColumns = computed(() => (data === null || data === void 0 ? void 0 : data.value) || columns);
14
+ return [defineComponent({
15
+ props: { modelValue: {
16
+ type: [
17
+ String,
18
+ Number,
19
+ Array
20
+ ],
21
+ default: void 0
22
+ } },
23
+ setup(props, { slots, emit }) {
24
+ const renderColumns = () => {
25
+ var _collapseColumns$valu;
26
+ return (_collapseColumns$valu = collapseColumns.value) === null || _collapseColumns$valu === void 0 ? void 0 : _collapseColumns$valu.map((item, index) => {
27
+ var _item$name;
28
+ const itemName = (_item$name = item.name) !== null && _item$name !== void 0 ? _item$name : index;
29
+ return h(ElCollapseItem, {
30
+ ...item,
31
+ name: itemName
32
+ }, {
33
+ default: () => {
34
+ if (item === null || item === void 0 ? void 0 : item.render) return item.render(item);
35
+ return "";
36
+ },
37
+ title: (item === null || item === void 0 ? void 0 : item.renderTitle) ? () => item.renderTitle(item.title) : void 0,
38
+ icon: (item === null || item === void 0 ? void 0 : item.renderIcon) ? () => item.renderIcon(item.icon) : void 0
39
+ });
40
+ });
41
+ };
42
+ const handleChange = (val) => {
43
+ activeNames.value = val;
44
+ onChange === null || onChange === void 0 || onChange(val);
45
+ emit("change", val);
46
+ };
47
+ return () => {
48
+ var _ref, _props$modelValue, _loading$value;
49
+ const finalActiveNames = (_ref = (_props$modelValue = props.modelValue) !== null && _props$modelValue !== void 0 ? _props$modelValue : rest.modelValue) !== null && _ref !== void 0 ? _ref : activeNames.value;
50
+ return withDirectives(h(ElCollapse, {
51
+ ...rest,
52
+ ...props,
53
+ "modelValue": finalActiveNames,
54
+ "onUpdate:modelValue": handleChange,
55
+ "onChange": handleChange
56
+ }, { default: () => {
57
+ if (slots.default) return slots.default();
58
+ if (!collapseColumns.value.length) return "";
59
+ return renderColumns();
60
+ } }), [[vLoading, (_loading$value = loading === null || loading === void 0 ? void 0 : loading.value) !== null && _loading$value !== void 0 ? _loading$value : false]]);
61
+ };
62
+ }
63
+ }), activeNames];
64
+ }
65
+ //#endregion
5
66
  //#region src/data/useDescriptions/index.ts
6
67
  function useDescriptions(options) {
7
68
  const { columns = [], service, params, formatData, ...rest } = options;
@@ -364,6 +425,67 @@ function useForm(options) {
364
425
  }];
365
426
  }
366
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
367
489
  //#region src/navigation/useSteps/index.ts
368
490
  function useSteps(options) {
369
491
  const { steps = [], service, params, formatData, defaultActive = 0, ...rest } = options;
@@ -637,4 +759,4 @@ function useTable(options) {
637
759
  })];
638
760
  }
639
761
  //#endregion
640
- export { setDeepProperty, useAsyncConfirm, useDescriptions, useDialog, useForm, useMessage, useSteps, useTable, useTabs };
762
+ export { setDeepProperty, useAsyncConfirm, useCollapse, useDescriptions, useDialog, useDropdown, useForm, 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.15",
4
+ "version": "0.0.17",
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.15",
25
- "@vuetkit/shared": "0.0.15"
24
+ "@vuetkit/core": "0.0.17",
25
+ "@vuetkit/shared": "0.0.17"
26
26
  },
27
27
  "scripts": {
28
28
  "build": "tsdown --config-loader tsx"