@webx-ui/core 0.1.0 → 0.2.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.
@@ -0,0 +1,45 @@
1
+ import { PaginationProps } from './types';
2
+ type __VLS_Props = PaginationProps;
3
+ type __VLS_PublicProps = {
4
+ 'page'?: number | undefined;
5
+ 'perPage'?: number | undefined;
6
+ } & __VLS_Props;
7
+ declare function __VLS_template(): {
8
+ attrs: Partial<{}>;
9
+ slots: {
10
+ total?(_: {
11
+ from: number | null;
12
+ to: number | null;
13
+ total: number;
14
+ }): any;
15
+ };
16
+ refs: {};
17
+ rootEl: HTMLElement;
18
+ };
19
+ type __VLS_TemplateResult = ReturnType<typeof __VLS_template>;
20
+ declare const __VLS_component: import('vue').DefineComponent<__VLS_PublicProps, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {
21
+ change: (value: import('./types').PaginationChange) => any;
22
+ "update:page": (value: number | undefined) => any;
23
+ "update:perPage": (value: number | undefined) => any;
24
+ }, string, import('vue').PublicProps, Readonly<__VLS_PublicProps> & Readonly<{
25
+ onChange?: ((value: import('./types').PaginationChange) => any) | undefined;
26
+ "onUpdate:page"?: ((value: number | undefined) => any) | undefined;
27
+ "onUpdate:perPage"?: ((value: number | undefined) => any) | undefined;
28
+ }>, {
29
+ size: import('../..').ControlSize;
30
+ disabled: boolean;
31
+ ariaLabel: string;
32
+ paginator: import('..').Paginated<unknown> | null;
33
+ total: number;
34
+ lastPage: number;
35
+ siblings: number;
36
+ perPageOptions: number[];
37
+ showTotal: boolean;
38
+ }, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, HTMLElement>;
39
+ declare const _default: __VLS_WithTemplateSlots<typeof __VLS_component, __VLS_TemplateResult["slots"]>;
40
+ export default _default;
41
+ type __VLS_WithTemplateSlots<T, S> = T & {
42
+ new (): {
43
+ $slots: S;
44
+ };
45
+ };
@@ -0,0 +1,2 @@
1
+ export { default as WxPagination } from './Pagination';
2
+ export type * from './types';
@@ -0,0 +1,29 @@
1
+ import { ControlSize } from '../../composables/useFormField';
2
+ import { Paginated } from '../Table/types';
3
+ export interface PaginationProps {
4
+ /**
5
+ * A page as `->paginate()` serialises it. The current page, the page size and the
6
+ * totals are all read from it, so the usual case needs no other prop.
7
+ */
8
+ paginator?: Paginated<unknown> | null;
9
+ /** Rows in total. Only needed without a paginator. */
10
+ total?: number;
11
+ /** Last page number. Worked out from `total` and the page size when missing. */
12
+ lastPage?: number;
13
+ /** Page buttons kept either side of the current one. */
14
+ siblings?: number;
15
+ /** Offers a page-size control. Empty leaves it out. */
16
+ perPageOptions?: number[];
17
+ /** Shows the "1–15 of 128" line. */
18
+ showTotal?: boolean;
19
+ disabled?: boolean;
20
+ size?: ControlSize;
21
+ ariaLabel?: string;
22
+ }
23
+ export interface PaginationChange {
24
+ page: number;
25
+ perPage: number;
26
+ }
27
+ export interface PaginationEmits {
28
+ change: [value: PaginationChange];
29
+ }
@@ -0,0 +1,34 @@
1
+ import { RowKey, TableProps, TableRow, TableSort, TableState } from './types';
2
+ declare const _default: <T extends TableRow = TableRow>(__VLS_props: NonNullable<Awaited<typeof __VLS_setup>>["props"], __VLS_ctx?: __VLS_PrettifyLocal<Pick<NonNullable<Awaited<typeof __VLS_setup>>, "attrs" | "emit" | "slots">>, __VLS_expose?: NonNullable<Awaited<typeof __VLS_setup>>["expose"], __VLS_setup?: Promise<{
3
+ props: __VLS_PrettifyLocal<Pick<Partial<{}> & Omit<{
4
+ readonly onSearch?: ((term: string) => any) | undefined;
5
+ readonly "onUpdate:page"?: ((value: number) => any) | undefined;
6
+ readonly "onUpdate:perPage"?: ((value: number) => any) | undefined;
7
+ readonly "onUpdate:selected"?: ((value: RowKey[]) => any) | undefined;
8
+ readonly "onUpdate:expanded"?: ((value: RowKey[]) => any) | undefined;
9
+ readonly "onUpdate:sort"?: ((value: TableSort | null) => any) | undefined;
10
+ readonly "onUpdate:search"?: ((value: string) => any) | undefined;
11
+ readonly "onRow-click"?: ((row: T, index: number, event: MouseEvent) => any) | undefined;
12
+ readonly "onSort-change"?: ((sort: TableSort | null) => any) | undefined;
13
+ readonly "onSelection-change"?: ((keys: RowKey[], rows: T[]) => any) | undefined;
14
+ readonly "onExpand-change"?: ((keys: RowKey[], rows: T[]) => any) | undefined;
15
+ readonly "onState-change"?: ((state: TableState) => any) | undefined;
16
+ } & import('vue').VNodeProps & import('vue').AllowedComponentProps & import('vue').ComponentCustomProps, never>, "onUpdate:page" | "onUpdate:perPage" | "onSearch" | "onUpdate:selected" | "onUpdate:expanded" | "onUpdate:sort" | "onUpdate:search" | "onRow-click" | "onSort-change" | "onSelection-change" | "onExpand-change" | "onState-change"> & ({
17
+ selected?: RowKey[];
18
+ expanded?: RowKey[];
19
+ sort?: TableSort | null;
20
+ search?: string;
21
+ page?: number;
22
+ perPage?: number;
23
+ } & TableProps<T>) & any> & import('vue').PublicProps;
24
+ expose(exposed: import('vue').ShallowUnwrapRef<{}>): void;
25
+ attrs: any;
26
+ slots: any;
27
+ emit: (((evt: "search", term: string) => void) & ((evt: "row-click", row: T, index: number, event: MouseEvent) => void) & ((evt: "sort-change", sort: TableSort | null) => void) & ((evt: "selection-change", keys: RowKey[], rows: T[]) => void) & ((evt: "expand-change", keys: RowKey[], rows: T[]) => void) & ((evt: "state-change", state: TableState) => void)) & (((evt: "update:page", value: number) => void) & ((evt: "update:perPage", value: number) => void) & ((evt: "update:selected", value: RowKey[]) => void) & ((evt: "update:expanded", value: RowKey[]) => void) & ((evt: "update:sort", value: TableSort | null) => void) & ((evt: "update:search", value: string) => void));
28
+ }>) => import('vue').VNode & {
29
+ __ctx?: Awaited<typeof __VLS_setup>;
30
+ };
31
+ export default _default;
32
+ type __VLS_PrettifyLocal<T> = {
33
+ [K in keyof T]: T[K];
34
+ } & {};
@@ -0,0 +1,2 @@
1
+ export { default as WxTable } from './Table';
2
+ export type * from './types';
@@ -0,0 +1,142 @@
1
+ import { ControlSize } from '../../composables/useFormField';
2
+ /**
3
+ * A page as Laravel's `->paginate()` serialises it. Taken as it arrives, with the
4
+ * snake_case keys intact — renaming them in every controller is work the table can
5
+ * spare the caller.
6
+ */
7
+ export interface Paginated<T = TableRow> {
8
+ data: T[];
9
+ current_page: number;
10
+ last_page: number;
11
+ per_page: number;
12
+ total: number;
13
+ from: number | null;
14
+ to: number | null;
15
+ }
16
+ export type TableRow = Record<string, unknown>;
17
+ export type SortOrder = 'asc' | 'desc';
18
+ export interface TableSort {
19
+ /** Column key. Sent to the backend as it is. */
20
+ key: string;
21
+ order: SortOrder;
22
+ }
23
+ export type RowKey = string | number;
24
+ export type TableAlign = 'left' | 'center' | 'right';
25
+ export interface TableColumn<T = TableRow> {
26
+ /**
27
+ * Identifies the column and reads the value out of the row. A dotted path walks
28
+ * into nested objects, so an eager-loaded relation works: `user.name`.
29
+ */
30
+ key: string;
31
+ /** Heading text. Use the `header-<key>` slot for anything richer. */
32
+ label?: string;
33
+ width?: string | number;
34
+ minWidth?: string | number;
35
+ align?: TableAlign;
36
+ /** Adds a sort control to the heading. The table reports, it does not reorder. */
37
+ sortable?: boolean;
38
+ /**
39
+ * Pins the column to an edge while the rest scrolls sideways. A pinned column needs
40
+ * a `width`: the offsets of the ones behind it are worked out from the declared
41
+ * widths, and a column of unknown width cannot say where the next one starts.
42
+ */
43
+ fixed?: 'left' | 'right';
44
+ /** Turns the raw value into the text of the cell. */
45
+ formatter?: (value: unknown, row: T, index: number) => string;
46
+ headerClass?: string;
47
+ cellClass?: string;
48
+ /** Leaves the column out without changing the array. */
49
+ hidden?: boolean;
50
+ }
51
+ /**
52
+ * One line of the summary under the table. `label` occupies every column ahead of the
53
+ * first one carrying a value, which is what a total wants: a caption on the left and a
54
+ * figure under its column.
55
+ */
56
+ export interface TableSummaryRow {
57
+ /** Caption on the left. */
58
+ label?: string;
59
+ /** Values by column key. */
60
+ cells?: Record<string, unknown>;
61
+ /** Draws the line as the one that matters — the total rather than its parts. */
62
+ strong?: boolean;
63
+ class?: string;
64
+ }
65
+ /** Everything the table asks the backend for, in one object. */
66
+ export interface TableState {
67
+ page: number;
68
+ perPage: number;
69
+ sort: TableSort | null;
70
+ search: string;
71
+ }
72
+ export interface TableProps<T = TableRow> {
73
+ /** Rows, or a whole paginator — the table reads `data` out of it. */
74
+ data?: T[] | Paginated<T> | null;
75
+ columns: TableColumn<T>[];
76
+ /**
77
+ * Where a stable row id comes from. A missing key falls back to the row's position,
78
+ * which is enough to render but too weak to survive a reorder — name one when rows
79
+ * can be selected or expanded.
80
+ */
81
+ rowKey?: string | ((row: T, index: number) => RowKey);
82
+ /** Heading above the table. */
83
+ title?: string;
84
+ /** Adds the search field to the header. */
85
+ searchable?: boolean;
86
+ searchPlaceholder?: string;
87
+ /** How long typing settles before `search` fires. Zero reports every keystroke. */
88
+ searchDebounce?: number;
89
+ loading?: boolean;
90
+ /** Shown in place of the rows when there are none. */
91
+ emptyText?: string;
92
+ stripe?: boolean;
93
+ bordered?: boolean;
94
+ /** Highlight the row under the pointer. */
95
+ hover?: boolean;
96
+ size?: ControlSize;
97
+ /** Adds the checkbox column. */
98
+ selectable?: boolean;
99
+ /** Rows this returns `false` for cannot be selected. */
100
+ selectableIf?: (row: T) => boolean;
101
+ /** Adds the disclosure column and renders the `expanded` slot underneath a row. */
102
+ expandable?: boolean;
103
+ /** Rows this returns `false` for have nothing to open. */
104
+ expandableIf?: (row: T) => boolean;
105
+ /** Lines under the table: totals, discounts, whatever the figures are. */
106
+ summary?: TableSummaryRow[];
107
+ /**
108
+ * Puts the pagination in the footer. On by default as soon as `data` is a paginator,
109
+ * since a paginated response is a promise that there are more pages to reach.
110
+ */
111
+ pagination?: boolean;
112
+ /** Page sizes offered by the built-in pagination. Empty leaves the control out. */
113
+ perPageOptions?: number[];
114
+ /**
115
+ * Remembers the page, the sort, the page size and the search term under this key, so
116
+ * a reload lands where the user left off. One key per table per application.
117
+ */
118
+ persist?: string;
119
+ /**
120
+ * Caps the height and scrolls the rows between a stuck header and a stuck footer.
121
+ * A number is pixels; a string is any CSS length, so `60vh` follows the window.
122
+ */
123
+ maxHeight?: string | number;
124
+ /** Extra class per row, for status colouring and the like. */
125
+ rowClass?: (row: T, index: number) => string | undefined;
126
+ /** Fixes the column widths instead of letting the content decide. */
127
+ layout?: 'auto' | 'fixed';
128
+ ariaLabel?: string;
129
+ }
130
+ export interface TableEmits<T = TableRow> {
131
+ 'row-click': [row: T, index: number, event: MouseEvent];
132
+ 'sort-change': [sort: TableSort | null];
133
+ 'selection-change': [keys: RowKey[], rows: T[]];
134
+ 'expand-change': [keys: RowKey[], rows: T[]];
135
+ search: [term: string];
136
+ /**
137
+ * Everything the backend needs, together. Fires once on mount — with whatever
138
+ * `persist` restored — and again whenever any part of it changes, which makes it the
139
+ * single place to hang the fetch on.
140
+ */
141
+ 'state-change': [state: TableState];
142
+ }
@@ -10,6 +10,7 @@ export * from './Form';
10
10
  export * from './FormItem';
11
11
  export * from './Input';
12
12
  export * from './InputNumber';
13
+ export * from './Pagination';
13
14
  export * from './Radio';
14
15
  export * from './RadioGroup';
15
16
  export * from './Rate';
@@ -17,6 +18,7 @@ export * from './RichText';
17
18
  export * from './Select';
18
19
  export * from './Slider';
19
20
  export * from './Switch';
21
+ export * from './Table';
20
22
  export * from './TagsInput';
21
23
  export * from './Textarea';
22
24
  export * from './TimePicker';