stk-table-vue 0.11.0-beta.3 → 0.11.0

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.
@@ -1,26 +1,28 @@
1
1
  /**
2
2
  * name: stk-table-vue
3
- * version: v0.11.0-beta.2
3
+ * version: v0.11.0-beta.4
4
4
  * description: High performance realtime virtual table for vue3 and vue2.7
5
5
  * author: japlus
6
6
  * homepage: https://ja-plus.github.io/stk-table-vue/
7
7
  * license: MIT
8
8
  */
9
- import { defineComponent, ref, h, onMounted, onUnmounted, createElementBlock, openBlock, withModifiers, normalizeStyle, createVNode, createElementVNode } from "vue";
9
+ import { defineComponent, ref, reactive, h, onMounted, onUnmounted, createElementBlock, openBlock, withModifiers, normalizeStyle, normalizeClass, createElementVNode, createVNode } from "vue";
10
10
  import { StkTable as _sfc_main$1 } from "./stk-table-vue.js";
11
11
  const _sfc_main = /* @__PURE__ */ defineComponent({
12
12
  __name: "index",
13
- emits: ["confirm"],
14
- setup(__props, { expose: __expose, emit: __emit }) {
13
+ setup(__props, { expose: __expose }) {
14
+ const theme = ref("light");
15
+ const checkedTempValueSet = reactive(/* @__PURE__ */ new Set());
15
16
  const columns = ref([
16
17
  {
17
18
  title: "",
18
19
  dataIndex: "value",
20
+ width: 30,
19
21
  className: "stk-filter-dropdown-checkbox",
20
22
  customCell: ({ row }) => h("input", {
21
23
  type: "checkbox",
22
- checked: row.selected,
23
- onChange: (e) => handleSelectChange(e, row)
24
+ checked: checkedTempValueSet.has(row.value),
25
+ onClick: (e) => e.preventDefault()
24
26
  })
25
27
  },
26
28
  { title: "", dataIndex: "label", customCell: ({ row }) => h("span", [row.label]) }
@@ -29,24 +31,19 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
29
31
  const position = ref({ x: 0, y: 0 });
30
32
  const options = ref([]);
31
33
  const dropdownEl = ref();
32
- const checkedTempValue = ref(/* @__PURE__ */ new Set());
33
- const emit = __emit;
34
34
  onMounted(() => {
35
35
  document.addEventListener("click", handleClickOutside);
36
36
  });
37
37
  onUnmounted(() => {
38
38
  document.removeEventListener("click", handleClickOutside);
39
39
  });
40
- function show(pos, opt) {
40
+ let onConfirmFn;
41
+ function show(pos, opt, onConfirm) {
41
42
  visible.value = true;
42
43
  position.value = pos;
43
44
  options.value = opt || [];
44
45
  initChecked();
45
- }
46
- function clear() {
47
- options.value = [];
48
- checkedTempValue.value.clear();
49
- confirm();
46
+ onConfirmFn = onConfirm;
50
47
  }
51
48
  async function handleClickOutside(e) {
52
49
  var _a;
@@ -54,51 +51,68 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
54
51
  hide();
55
52
  }
56
53
  function initChecked() {
57
- checkedTempValue.value = new Set(options.value.filter((opt) => opt.selected).map((opt) => opt.value));
54
+ options.value.forEach((opt) => {
55
+ if (opt.selected) {
56
+ checkedTempValueSet.add(opt.value);
57
+ }
58
+ });
58
59
  }
59
- function handleSelectChange(e, row) {
60
- const target = e.target;
61
- if (target.checked) {
62
- checkedTempValue.value.add(row.value);
60
+ function updateChecked(checked, row) {
61
+ if (checked) {
62
+ checkedTempValueSet.add(row.value);
63
63
  } else {
64
- checkedTempValue.value.delete(row.value);
64
+ checkedTempValueSet.delete(row.value);
65
65
  }
66
66
  }
67
67
  function confirm() {
68
- options.value.forEach((opt) => opt.selected = checkedTempValue.value.has(opt.value));
69
- emit("confirm", Array.from(checkedTempValue.value));
68
+ options.value.forEach((opt) => opt.selected = checkedTempValueSet.has(opt.value));
69
+ onConfirmFn(Array.from(checkedTempValueSet));
70
70
  hide();
71
71
  }
72
72
  function hide() {
73
73
  visible.value = false;
74
+ options.value = [];
75
+ checkedTempValueSet.clear();
76
+ }
77
+ function handleRowClick(e, row) {
78
+ const selected = checkedTempValueSet.has(row.value);
79
+ updateChecked(!selected, row);
80
+ }
81
+ function setTheme(t) {
82
+ theme.value = t;
83
+ }
84
+ function handleClear() {
85
+ checkedTempValueSet.clear();
74
86
  }
75
- __expose({ visible, show, clear, hide });
87
+ __expose({ visible, show, hide, setTheme });
76
88
  return (_ctx, _cache) => {
77
89
  return openBlock(), createElementBlock("div", {
78
90
  ref_key: "dropdownEl",
79
91
  ref: dropdownEl,
80
- class: "stk-filter-dropdown",
92
+ class: normalizeClass(["stk-filter-dropdown", [`stk-filter-dropdown--${theme.value}`]]),
81
93
  style: normalizeStyle({ top: position.value.y + "px", left: position.value.x + "px", display: visible.value ? void 0 : "none" }),
82
94
  onClick: _cache[0] || (_cache[0] = withModifiers(() => {
83
95
  }, ["stop"]))
84
96
  }, [
97
+ _cache[1] || (_cache[1] = createElementVNode("div", { style: { "padding": "4px" } }, "Filter (Beta)", -1)),
85
98
  createVNode(_sfc_main$1, {
86
99
  "row-key": "id",
87
- theme: "dark",
88
100
  headless: "",
89
101
  virtual: "",
90
102
  "no-data-full": "",
103
+ theme: theme.value,
91
104
  "row-active": false,
92
105
  "row-height": 20,
93
106
  bordered: false,
94
107
  columns: columns.value,
95
- "data-source": options.value
96
- }, null, 8, ["columns", "data-source"]),
108
+ "data-source": options.value,
109
+ onRowClick: handleRowClick
110
+ }, null, 8, ["theme", "columns", "data-source"]),
97
111
  createElementVNode("footer", null, [
98
- createElementVNode("button", { onClick: clear }, ""),
99
- createElementVNode("button", { onClick: confirm }, "✔️")
112
+ createElementVNode("button", { onClick: handleClear }, ""),
113
+ createElementVNode("button", { onClick: confirm }, "")
100
114
  ])
101
- ], 4);
115
+ ], 6);
102
116
  };
103
117
  }
104
118
  });
@@ -4,7 +4,9 @@ import { ScrollbarOptions } from './useScrollbar';
4
4
 
5
5
  /** Generic stands for DataType */
6
6
  type DT = any & PrivateRowDT;
7
- declare function setFilter(status: Record<UniqKey, FilterStatus>): void;
7
+ declare function setFilter(status: Record<UniqKey, FilterStatus> | null, option?: {
8
+ remote?: boolean;
9
+ }): void;
8
10
  /**
9
11
  * 选中一行
10
12
  *
@@ -105,6 +107,8 @@ declare const __VLS_component: import('vue').DefineComponent<import('vue').Extra
105
107
  rowCurrentRevokable?: boolean;
106
108
  /** 表头行高。default = rowHeight */
107
109
  headerRowHeight?: number | string | null;
110
+ /** 表尾行高。default = rowHeight */
111
+ footerRowHeight?: number | string | null;
108
112
  /** 虚拟滚动 */
109
113
  virtual?: boolean;
110
114
  /** x轴虚拟滚动(必须设置列宽)*/
@@ -222,6 +226,8 @@ declare const __VLS_component: import('vue').DefineComponent<import('vue').Extra
222
226
  * 实验性功能配置
223
227
  */
224
228
  experimental?: ExperimentalConfig;
229
+ /** 表格底部合计行数据 */
230
+ footerData?: DT[];
225
231
  }>, {
226
232
  width: string;
227
233
  fixedMode: boolean;
@@ -232,10 +238,12 @@ declare const __VLS_component: import('vue').DefineComponent<import('vue').Extra
232
238
  theme: string;
233
239
  rowHeight: number;
234
240
  autoRowHeight: () => false;
241
+ footerData: () => never[];
235
242
  rowHover: boolean;
236
243
  rowActive: () => Required<RowActiveOption<any>>;
237
244
  rowCurrentRevokable: boolean;
238
245
  headerRowHeight: number;
246
+ footerRowHeight: number;
239
247
  virtual: boolean;
240
248
  virtualX: boolean;
241
249
  columns: () => never[];
@@ -531,6 +539,8 @@ declare const __VLS_component: import('vue').DefineComponent<import('vue').Extra
531
539
  rowCurrentRevokable?: boolean;
532
540
  /** 表头行高。default = rowHeight */
533
541
  headerRowHeight?: number | string | null;
542
+ /** 表尾行高。default = rowHeight */
543
+ footerRowHeight?: number | string | null;
534
544
  /** 虚拟滚动 */
535
545
  virtual?: boolean;
536
546
  /** x轴虚拟滚动(必须设置列宽)*/
@@ -648,6 +658,8 @@ declare const __VLS_component: import('vue').DefineComponent<import('vue').Extra
648
658
  * 实验性功能配置
649
659
  */
650
660
  experimental?: ExperimentalConfig;
661
+ /** 表格底部合计行数据 */
662
+ footerData?: DT[];
651
663
  }>, {
652
664
  width: string;
653
665
  fixedMode: boolean;
@@ -658,10 +670,12 @@ declare const __VLS_component: import('vue').DefineComponent<import('vue').Extra
658
670
  theme: string;
659
671
  rowHeight: number;
660
672
  autoRowHeight: () => false;
673
+ footerData: () => never[];
661
674
  rowHover: boolean;
662
675
  rowActive: () => Required<RowActiveOption<any>>;
663
676
  rowCurrentRevokable: boolean;
664
677
  headerRowHeight: number;
678
+ footerRowHeight: number;
665
679
  virtual: boolean;
666
680
  virtualX: boolean;
667
681
  columns: () => never[];
@@ -778,6 +792,7 @@ declare const __VLS_component: import('vue').DefineComponent<import('vue').Extra
778
792
  rowHover: boolean;
779
793
  rowActive: boolean | RowActiveOption<DT>;
780
794
  rowCurrentRevokable: boolean;
795
+ footerRowHeight: number | string | null;
781
796
  virtual: boolean;
782
797
  virtualX: boolean;
783
798
  columns: StkTableColumn<DT>[];
@@ -813,6 +828,7 @@ declare const __VLS_component: import('vue').DefineComponent<import('vue').Extra
813
828
  smoothScroll: boolean;
814
829
  scrollRowByRow: boolean | "scrollbar";
815
830
  experimental: ExperimentalConfig;
831
+ footerData: DT[];
816
832
  }, {}, {}, {}, string, import('vue').ComponentProvideOptions, true, {}, any>;
817
833
  declare const _default: __VLS_WithTemplateSlots<typeof __VLS_component, ReturnType<typeof __VLS_template>>;
818
834
  export default _default;
@@ -1,32 +1,24 @@
1
- import { FilterOption } from '../types';
2
-
3
- export declare function getDropdownIns(onConfirm: (values: FilterOption['value'][]) => void): Promise<import('vue').CreateComponentPublicInstanceWithMixins<Readonly<{}> & Readonly<{
4
- onConfirm?: ((options: FilterOption[]) => any) | undefined;
5
- }>, {
1
+ export declare function getDropdownIns(): Promise<import('vue').CreateComponentPublicInstanceWithMixins<Readonly<{}> & Readonly<{}>, {
6
2
  visible: import('vue').Ref<boolean, boolean>;
7
3
  show: (pos: {
8
4
  x: number;
9
5
  y: number;
10
- }, opt?: FilterOption[]) => void;
11
- clear: () => void;
6
+ }, opt: import('../types').FilterOption[], onConfirm: (values: import('../types').FilterOption["value"][]) => void) => void;
12
7
  hide: () => void;
13
- }, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {
14
- confirm: (options: FilterOption[]) => void;
15
- }, import('vue').PublicProps, {}, true, {}, {}, import('vue').GlobalComponents, import('vue').GlobalDirectives, string, {}, any, import('vue').ComponentProvideOptions, {
8
+ setTheme: (t: "light" | "dark") => void;
9
+ }, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, import('vue').PublicProps, {}, true, {}, {}, import('vue').GlobalComponents, import('vue').GlobalDirectives, string, {}, any, import('vue').ComponentProvideOptions, {
16
10
  P: {};
17
11
  B: {};
18
12
  D: {};
19
13
  C: {};
20
14
  M: {};
21
15
  Defaults: {};
22
- }, Readonly<{}> & Readonly<{
23
- onConfirm?: ((options: FilterOption[]) => any) | undefined;
24
- }>, {
16
+ }, Readonly<{}> & Readonly<{}>, {
25
17
  visible: import('vue').Ref<boolean, boolean>;
26
18
  show: (pos: {
27
19
  x: number;
28
20
  y: number;
29
- }, opt?: FilterOption[]) => void;
30
- clear: () => void;
21
+ }, opt: import('../types').FilterOption[], onConfirm: (values: import('../types').FilterOption["value"][]) => void) => void;
31
22
  hide: () => void;
23
+ setTheme: (t: "light" | "dark") => void;
32
24
  }, {}, {}, {}, {}>>;
@@ -3,17 +3,13 @@ import { FilterOption } from '../types';
3
3
  declare function show(pos: {
4
4
  x: number;
5
5
  y: number;
6
- }, opt?: FilterOption[]): void;
7
- declare function clear(): void;
6
+ }, opt: FilterOption[], onConfirm: (values: FilterOption['value'][]) => void): void;
8
7
  declare function hide(): void;
8
+ declare function setTheme(t: 'light' | 'dark'): void;
9
9
  declare const _default: import('vue').DefineComponent<{}, {
10
10
  visible: import('vue').Ref<boolean, boolean>;
11
11
  show: typeof show;
12
- clear: typeof clear;
13
12
  hide: typeof hide;
14
- }, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {
15
- confirm: (options: FilterOption[]) => void;
16
- }, string, import('vue').PublicProps, Readonly<{}> & Readonly<{
17
- onConfirm?: ((options: FilterOption[]) => any) | undefined;
18
- }>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, true, {}, any>;
13
+ setTheme: typeof setTheme;
14
+ }, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, true, {}, any>;
19
15
  export default _default;
@@ -5,15 +5,17 @@ declare function __VLS_template(): {
5
5
  default?(_: {}): any;
6
6
  };
7
7
  declare const __VLS_component: import('vue').DefineComponent<import('vue').ExtractPropTypes<__VLS_TypePropsToRuntimeProps<CustomHeaderCellProps<any> & {
8
+ theme?: "light" | "dark";
8
9
  active?: boolean;
9
- options?: FilterOption[];
10
+ options: FilterOption[];
10
11
  }>>, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {
11
- "update:filterStatus": (value: any[]) => void;
12
+ change: (value: any[]) => void;
12
13
  }, string, import('vue').PublicProps, Readonly<import('vue').ExtractPropTypes<__VLS_TypePropsToRuntimeProps<CustomHeaderCellProps<any> & {
14
+ theme?: "light" | "dark";
13
15
  active?: boolean;
14
- options?: FilterOption[];
16
+ options: FilterOption[];
15
17
  }>>> & Readonly<{
16
- "onUpdate:filterStatus"?: ((value: any[]) => any) | undefined;
18
+ onChange?: ((value: any[]) => any) | undefined;
17
19
  }>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, true, {}, any>;
18
20
  declare const _default: __VLS_WithTemplateSlots<typeof __VLS_component, ReturnType<typeof __VLS_template>>;
19
21
  export default _default;
@@ -2,15 +2,9 @@ export interface FilterOption {
2
2
  label: string;
3
3
  value: any;
4
4
  selected?: boolean;
5
- /**
6
- * TODO: 自定义筛选函数
7
- * @param row 行数据
8
- * @returns 是否匹配
9
- */
10
- matchFn?: (row: any) => boolean;
11
5
  }
12
6
  export interface FilterStatus {
13
- value: any[];
7
+ value: FilterOption['value'][];
14
8
  }
15
9
  export interface UseFilterOptions {
16
10
  filterRemote: boolean;
@@ -2,12 +2,20 @@ import { UniqKey } from '../../types';
2
2
  import { VNode } from 'vue';
3
3
  import { FilterOption, FilterStatus } from './types';
4
4
 
5
+ /**
6
+ * 从数据源提取筛选选项
7
+ * @param dataSource 数据源
8
+ * @param columnKey 列名
9
+ * @returns 筛选选项数组
10
+ // */
5
11
  /**
6
12
  * 表格筛选功能Hook (BETA)
7
13
  * @beta
8
14
  * @returns
9
15
  */
10
- export declare function useFilter(): {
16
+ export declare function useFilter(option?: {
17
+ remote?: boolean;
18
+ }): {
11
19
  Filter: (config?: {
12
20
  options?: FilterOption[];
13
21
  }, component?: VNode) => import('vue').Raw<import('vue').DefineComponent<{
@@ -27,6 +27,13 @@ export type CustomHeaderCellProps<T extends Record<string, any>> = {
27
27
  rowIndex: number;
28
28
  colIndex: number;
29
29
  };
30
+ export type CustomFooterCellProps<T extends Record<string, any>> = {
31
+ col: StkTableColumn<T>;
32
+ row: T;
33
+ cellValue: any;
34
+ rowIndex: number;
35
+ colIndex: number;
36
+ };
30
37
  export type MergeCellsParam<T extends Record<string, any>> = {
31
38
  row: T;
32
39
  col: StkTableColumn<T>;
@@ -89,6 +96,8 @@ export type StkTableColumn<T extends Record<string, any>> = {
89
96
  sortConfig?: Omit<SortConfig<T>, 'defaultSort'>;
90
97
  /** 固定列 */
91
98
  fixed?: 'left' | 'right' | null;
99
+ /** 是否隐藏列 */
100
+ hidden?: boolean;
92
101
  /**
93
102
  * 自定义 td 渲染内容。
94
103
  *
@@ -109,6 +118,17 @@ export type StkTableColumn<T extends Record<string, any>> = {
109
118
  * @param props.colIndex 列索引
110
119
  */
111
120
  customHeaderCell?: CustomCell<CustomHeaderCellProps<T>, T>;
121
+ /**
122
+ * 自定义 tfoot td 渲染内容
123
+ *
124
+ * 组件prop入参:
125
+ * @param props.row tfoot行的记录。
126
+ * @param props.col 列配置
127
+ * @param props.cellValue row[col.dataIndex] 的值
128
+ * @param props.rowIndex tfoot行索引(从0开始)
129
+ * @param props.colIndex 列索引
130
+ */
131
+ customFooterCell?: CustomCell<CustomFooterCellProps<T>, T>;
112
132
  /** 二级表头 */
113
133
  children?: StkTableColumn<T>[];
114
134
  /** 单元格合并 */
@@ -124,22 +144,22 @@ export type PrivateStkTableColumn<T extends Record<string, any>> = StkTableColum
124
144
  * parent not ref
125
145
  * @private
126
146
  */
127
- __PARENT__?: StkTableColumn<T> | null;
147
+ __P__?: StkTableColumn<T> | null;
128
148
  /**
129
149
  * Save the calculated width. Used for horizontal virtual scrolling.
130
150
  * @private
131
151
  */
132
- __WIDTH__?: number;
152
+ __W__?: number;
133
153
  };
134
154
  /** private row keys */
135
155
  export type PrivateRowDT = {
136
156
  /**
137
157
  * Only expanded row will add this key
138
158
  *
139
- * If user define the `__ROW_K__` in table data, this value will be used as the row key
159
+ * If user define the `__R_K__` in table data, this value will be used as the row key
140
160
  * @private
141
161
  */
142
- __ROW_K__?: string;
162
+ __R_K__?: string;
143
163
  /**
144
164
  * if row expanded
145
165
  * @private
@@ -218,7 +238,9 @@ export type SortConfig<T extends Record<string, any>> = {
218
238
  /** th td type */
219
239
  export declare const enum TagType {
220
240
  TH = 0,
221
- TD = 1
241
+ TD = 1,
242
+ /** tfoot */
243
+ TF = 2
222
244
  }
223
245
  export type HighlightConfig = {
224
246
  /** Duration of the highlight in seconds */