@r2digisolutions/ui 0.22.3 → 0.22.4

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,12 +1,11 @@
1
- <script module lang="ts">
2
- import * as DataTableTypes from './core/types.js';
3
- export type { DataTableTypes };
4
- </script>
5
-
6
1
  <script lang="ts" generics="T extends { id?: any }">
7
2
  import type { Snippet } from 'svelte';
8
3
  import { tick } from 'svelte';
9
- import type { CellContext, ColumnDef, TableOptions } from './core/types.js';
4
+ import type {
5
+ TDataTableCellContext,
6
+ TDataTableColumnDef,
7
+ TDataTableTableOptions
8
+ } from './core/types.js';
10
9
  import type { Entry } from './components/ContextMenu.svelte';
11
10
  import type { FilterField } from './core/filters/types.js';
12
11
  import { DataTableManager } from './core/DataTableManager.svelte';
@@ -19,9 +18,9 @@
19
18
 
20
19
  interface Props<T> {
21
20
  filters?: Snippet;
22
- options: TableOptions<T>;
21
+ options: TDataTableTableOptions<T>;
23
22
  rowId?: (row: T) => any;
24
- actions?: (rows: T[], ctx?: CellContext<T> | null) => Entry[];
23
+ actions?: (rows: T[], ctx?: TDataTableCellContext<T> | null) => Entry[];
25
24
  rowActions?: (row: T) => any;
26
25
  onRowClick?: (row: T) => void;
27
26
  density?: 'compact' | 'normal' | 'comfortable';
@@ -54,7 +53,7 @@
54
53
  let filterValues = $state<Record<string, any>>({});
55
54
  let container: HTMLDivElement | null = $state(null);
56
55
  let rightMenu = $state<{ open: boolean; x: number; y: number }>({ open: false, x: 0, y: 0 });
57
- let rightClickContext = $state<CellContext<T> | null>(null);
56
+ let rightClickContext = $state<TDataTableCellContext<T> | null>(null);
58
57
  let measuring = $state(true);
59
58
 
60
59
  const sizeRow = $derived.by(() =>
@@ -112,7 +111,7 @@
112
111
  measureColumns();
113
112
  });
114
113
 
115
- function headerClick(c: ColumnDef<T>) {
114
+ function headerClick(c: TDataTableColumnDef<T>) {
116
115
  if (!c.sortable) return;
117
116
  manager.setSort(c.id);
118
117
  }
@@ -133,7 +132,7 @@
133
132
  columnIndex,
134
133
  event: e,
135
134
  column: columnId ? manager.getColumn(columnId) : null
136
- } as CellContext<T>;
135
+ } as TDataTableCellContext<T>;
137
136
  }
138
137
 
139
138
  function selectedRows(): T[] {
@@ -1,14 +1,12 @@
1
- import * as DataTableTypes from './core/types.js';
2
- export type { DataTableTypes };
3
1
  import type { Snippet } from 'svelte';
4
- import type { CellContext, TableOptions } from './core/types.js';
2
+ import type { TDataTableCellContext, TDataTableTableOptions } from './core/types.js';
5
3
  import type { Entry } from './components/ContextMenu.svelte';
6
4
  import type { FilterField } from './core/filters/types.js';
7
5
  interface Props<T> {
8
6
  filters?: Snippet;
9
- options: TableOptions<T>;
7
+ options: TDataTableTableOptions<T>;
10
8
  rowId?: (row: T) => any;
11
- actions?: (rows: T[], ctx?: CellContext<T> | null) => Entry[];
9
+ actions?: (rows: T[], ctx?: TDataTableCellContext<T> | null) => Entry[];
12
10
  rowActions?: (row: T) => any;
13
11
  onRowClick?: (row: T) => void;
14
12
  density?: 'compact' | 'normal' | 'comfortable';
@@ -1,9 +1,9 @@
1
1
  <script lang="ts" generics="T">
2
- import type { ColumnDef } from '../core/types.js';
2
+ import type { TDataTableColumnDef } from '../core/types.js';
3
3
  import { Check, X, ExternalLink } from 'lucide-svelte';
4
4
 
5
5
  interface Props<T> {
6
- column: ColumnDef<T>;
6
+ column: TDataTableColumnDef<T>;
7
7
  row: T;
8
8
  measuring?: boolean;
9
9
  }
@@ -1,6 +1,6 @@
1
- import type { ColumnDef } from '../core/types.js';
1
+ import type { TDataTableColumnDef } from '../core/types.js';
2
2
  interface Props<T> {
3
- column: ColumnDef<T>;
3
+ column: TDataTableColumnDef<T>;
4
4
  row: T;
5
5
  measuring?: boolean;
6
6
  }
@@ -1,8 +1,8 @@
1
1
  <script lang="ts">
2
- import type { ColumnDef } from '../core/types.js';
2
+ import type { TDataTableColumnDef } from '../core/types.js';
3
3
 
4
4
  interface Props {
5
- columns?: ColumnDef<any>[];
5
+ columns?: TDataTableColumnDef<any>[];
6
6
  visible?: string[];
7
7
  onToggle: (id: string, show: boolean) => void;
8
8
  buttonText?: string;
@@ -1,6 +1,6 @@
1
- import type { ColumnDef } from '../core/types.js';
1
+ import type { TDataTableColumnDef } from '../core/types.js';
2
2
  interface Props {
3
- columns?: ColumnDef<any>[];
3
+ columns?: TDataTableColumnDef<any>[];
4
4
  visible?: string[];
5
5
  onToggle: (id: string, show: boolean) => void;
6
6
  buttonText?: string;
@@ -1,9 +1,9 @@
1
1
  <script lang="ts">
2
- import type { FilterDef } from '../core/types.js';
2
+ import type { TDataTableFilterDef } from '../core/types.js';
3
3
 
4
4
  interface Props {
5
- filters: FilterDef<any>[];
6
- onapply: (filters: FilterDef<any>[]) => void;
5
+ filters: TDataTableFilterDef<any>[];
6
+ onapply: (filters: TDataTableFilterDef<any>[]) => void;
7
7
  }
8
8
 
9
9
  const { filters, onapply }: Props = $props();
@@ -12,7 +12,7 @@
12
12
 
13
13
  function submit() {
14
14
  const base = filters.filter((f) => f.meta?.kind !== 'quick');
15
- const q: FilterDef<any> = {
15
+ const q: TDataTableFilterDef<any> = {
16
16
  id: 'q',
17
17
  label: 'Búsqueda',
18
18
  op: 'contains',
@@ -1,7 +1,7 @@
1
- import type { FilterDef } from '../core/types.js';
1
+ import type { TDataTableFilterDef } from '../core/types.js';
2
2
  interface Props {
3
- filters: FilterDef<any>[];
4
- onapply: (filters: FilterDef<any>[]) => void;
3
+ filters: TDataTableFilterDef<any>[];
4
+ onapply: (filters: TDataTableFilterDef<any>[]) => void;
5
5
  }
6
6
  declare const QuickFilters: import("svelte").Component<Props, {}, "">;
7
7
  type QuickFilters = ReturnType<typeof QuickFilters>;
@@ -1,28 +1,28 @@
1
1
  import { SvelteSet } from 'svelte/reactivity';
2
- import type { TableOptions, TableState, VisibilityPlan } from './types.js';
2
+ import type { TDataTableTableOptions, TDataTableTableState, TDataTableVisibilityPlan } from './types.js';
3
3
  export declare class DataTableManager<T extends {
4
4
  id?: any;
5
5
  } = any> {
6
- options: TableOptions<T>;
7
- state: TableState<T>;
6
+ options: TDataTableTableOptions<T>;
7
+ state: TDataTableTableState<T>;
8
8
  measured: Record<string, number>;
9
9
  reservedWidth: number;
10
10
  forcedVisible: SvelteSet<string>;
11
11
  forcedHidden: SvelteSet<string>;
12
12
  expanded: SvelteSet<any>;
13
13
  lastWidth: number | null;
14
- constructor(opts: TableOptions<T>);
14
+ constructor(opts: TDataTableTableOptions<T>);
15
15
  setMeasuredWidths(map: Record<string, number>): void;
16
- get columns(): import("./types.js").ColumnDef<T>[];
17
- getColumn(id: string): import("./types.js").ColumnDef<T>;
16
+ get columns(): import("./types.js").TDataTableColumnDef<T>[];
17
+ getColumn(id: string): import("./types.js").TDataTableColumnDef<T>;
18
18
  isExpanded(id: any): boolean;
19
19
  toggleExpand(id: any): void;
20
20
  setColumnVisibility(id: string, show: boolean): void;
21
21
  setReservedWidth(n: number): void;
22
22
  clearColumnOverrides(): void;
23
- visibilityPlan(containerWidth: number): VisibilityPlan;
23
+ visibilityPlan(containerWidth: number): TDataTableVisibilityPlan;
24
24
  private mergeWithOverrides;
25
- applyVisibility(plan: VisibilityPlan): void;
25
+ applyVisibility(plan: TDataTableVisibilityPlan): void;
26
26
  reflowForWidth(width: number): void;
27
27
  reflow(): void;
28
28
  setPerPage(n: number): Promise<void>;
@@ -1,4 +1,4 @@
1
- import type { FilterOp } from "../types.js";
1
+ import type { TDataTableFilterOp } from "../types.js";
2
2
  export type FilterInputType = 'text' | 'select' | 'number' | 'range' | 'checkbox' | 'multiselect' | 'date' | 'rating';
3
3
  export type SelectOption = {
4
4
  label: string;
@@ -10,7 +10,7 @@ export type FilterField<T> = {
10
10
  type: FilterInputType;
11
11
  columnId?: string;
12
12
  options?: SelectOption[];
13
- op?: FilterOp;
13
+ op?: TDataTableFilterOp;
14
14
  placeholder?: string;
15
15
  min?: number;
16
16
  max?: number;
@@ -1,3 +1,3 @@
1
- import type { FilterDef } from "../types.js";
1
+ import type { TDataTableFilterDef } from "../types.js";
2
2
  import type { FilterField } from "./types.js";
3
- export declare function buildFilterDefs<T>(fields: FilterField<T>[], values: Record<string, any>): FilterDef<T>[];
3
+ export declare function buildFilterDefs<T>(fields: FilterField<T>[], values: Record<string, any>): TDataTableFilterDef<T>[];
@@ -1,9 +1,9 @@
1
- export type RowId = string | number;
2
- export type SortDir = 'asc' | 'desc' | null;
3
- export type ColumnKey<T> = Extract<keyof T, string>;
1
+ export type TDataTableRowId = string | number;
2
+ export type TDataTableSortDir = 'asc' | 'desc' | null;
3
+ export type TDataTableColumnKey<T> = Extract<keyof T, string>;
4
4
  export type Accessor<T, R = any> = (row: T) => R;
5
- export type ColumnType = 'text' | 'number' | 'currency' | 'date' | 'datetime' | 'boolean' | 'badge' | 'link' | 'code';
6
- type BaseColumn<T> = {
5
+ export type TDataTableColumnType = 'text' | 'number' | 'currency' | 'date' | 'datetime' | 'boolean' | 'badge' | 'link' | 'code';
6
+ type TDataTableBaseColumn<T> = {
7
7
  header: string;
8
8
  width?: number;
9
9
  minWidth?: number;
@@ -13,64 +13,64 @@ type BaseColumn<T> = {
13
13
  hideOnMobile?: boolean;
14
14
  responsiveLabel?: string;
15
15
  class?: string;
16
- type?: ColumnType;
16
+ type?: TDataTableColumnType;
17
17
  format?: Intl.NumberFormatOptions | Intl.DateTimeFormatOptions;
18
18
  trueLabel?: string;
19
19
  falseLabel?: string;
20
20
  };
21
21
  /** Columna ligada a una key existente de T (autocomplete de keys) */
22
- export type KeyColumn<T, K extends ColumnKey<T> = ColumnKey<T>> = BaseColumn<T> & {
22
+ export type TDataTableKeyColumn<T, K extends TDataTableColumnKey<T> = TDataTableColumnKey<T>> = TDataTableBaseColumn<T> & {
23
23
  id: K;
24
24
  accessor?: (row: T) => T[K];
25
25
  renderCell?: (row: T) => any;
26
26
  renderCollapsed?: (row: T) => any;
27
27
  };
28
28
  /** Columna virtual (id libre), requiere accessor explícito */
29
- export type VirtualColumn<T> = BaseColumn<T> & {
29
+ export type TDataTableVirtualColumn<T> = TDataTableBaseColumn<T> & {
30
30
  id: string;
31
31
  accessor: Accessor<T>;
32
32
  renderCell?: (row: T) => any;
33
33
  renderCollapsed?: (row: T) => any;
34
34
  };
35
- export type ColumnDef<T> = KeyColumn<T>;
36
- export type FilterOp = 'equals' | 'not_equals' | 'contains' | 'starts_with' | 'ends_with' | 'gt' | 'lt' | 'gte' | 'lte' | 'in' | 'not_in' | 'is_empty' | 'is_not_empty';
37
- export type FilterDef<T> = {
35
+ export type TDataTableColumnDef<T> = TDataTableKeyColumn<T>;
36
+ export type TDataTableFilterOp = 'equals' | 'not_equals' | 'contains' | 'starts_with' | 'ends_with' | 'gt' | 'lt' | 'gte' | 'lte' | 'in' | 'not_in' | 'is_empty' | 'is_not_empty';
37
+ export type TDataTableFilterDef<T> = {
38
38
  id: string;
39
39
  label: string;
40
40
  columnId?: string;
41
- op: FilterOp;
41
+ op: TDataTableFilterOp;
42
42
  value?: any;
43
43
  meta?: Record<string, any>;
44
44
  };
45
- export type FetchResult<T> = {
45
+ export type TDataTableFetchResult<T> = {
46
46
  items: T[];
47
47
  total: number;
48
48
  nextCursor?: string;
49
49
  };
50
- export type FetchParams = {
50
+ export type TDataTableFetchParams = {
51
51
  page: number;
52
52
  perPage: number;
53
53
  cursor?: string;
54
54
  sortBy?: string | null;
55
- sortDir?: SortDir;
56
- filters: FilterDef<any>[];
55
+ sortDir?: TDataTableSortDir;
56
+ filters: TDataTableFilterDef<any>[];
57
57
  };
58
- export type LoadMode = 'local' | 'remote' | 'cursor';
59
- export type TableOptions<T> = {
58
+ export type TDataTableLoadMode = 'local' | 'remote' | 'cursor';
59
+ export type TDataTableTableOptions<T> = {
60
60
  id?: string;
61
- columns: ColumnDef<T>[];
62
- loadMode: LoadMode;
61
+ columns: TDataTableColumnDef<T>[];
62
+ loadMode: TDataTableLoadMode;
63
63
  data?: T[];
64
- fetcher?: (params: FetchParams) => Promise<FetchResult<T>>;
64
+ fetcher?: (params: TDataTableFetchParams) => Promise<TDataTableFetchResult<T>>;
65
65
  perPage?: number;
66
66
  perPageOptions?: number[];
67
67
  multiSelect?: boolean;
68
68
  keepSelectionOnPageChange?: boolean;
69
69
  initialSortBy?: string | null;
70
- initialSortDir?: SortDir;
71
- initialFilters?: FilterDef<T>[];
70
+ initialSortDir?: TDataTableSortDir;
71
+ initialFilters?: TDataTableFilterDef<T>[];
72
72
  };
73
- export type TableState<T> = {
73
+ export type TDataTableTableState<T> = {
74
74
  ready: boolean;
75
75
  items: T[];
76
76
  page: number;
@@ -78,23 +78,23 @@ export type TableState<T> = {
78
78
  total: number;
79
79
  cursor?: string;
80
80
  sortBy: string | null;
81
- sortDir: SortDir;
82
- filters: FilterDef<T>[];
81
+ sortDir: TDataTableSortDir;
82
+ filters: TDataTableFilterDef<T>[];
83
83
  visibleColumns: string[];
84
84
  hiddenColumns: string[];
85
- selected: Set<RowId>;
85
+ selected: Set<TDataTableRowId>;
86
86
  loading: boolean;
87
87
  error?: string;
88
88
  };
89
- export type VisibilityPlan = {
89
+ export type TDataTableVisibilityPlan = {
90
90
  visible: string[];
91
91
  hidden: string[];
92
92
  };
93
- export type CellContext<T> = {
93
+ export type TDataTableCellContext<T> = {
94
94
  row: T | null;
95
95
  rowIndex: number | null;
96
96
  columnId: string | null;
97
- column: ColumnDef<T> | null;
97
+ column: TDataTableColumnDef<T> | null;
98
98
  columnIndex: number | null;
99
99
  event: MouseEvent;
100
100
  };
@@ -1,5 +1,5 @@
1
- import type { ColumnDef, FilterOp } from './types.js';
2
- export declare function normalize<T>(columns: ColumnDef<T>[]): ColumnDef<T>[];
1
+ import type { TDataTableColumnDef, TDataTableFilterOp } from './types.js';
2
+ export declare function normalize<T>(columns: TDataTableColumnDef<T>[]): TDataTableColumnDef<T>[];
3
3
  export declare function defaultAccessor<T>(row: any, id: string): any;
4
4
  export declare function compareValues(a: any, b: any): number;
5
- export declare function applyFilterOp(value: any, op: FilterOp, target: any): boolean;
5
+ export declare function applyFilterOp(value: any, op: TDataTableFilterOp, target: any): boolean;
@@ -1,2 +1,3 @@
1
1
  import DataTable from './DataTable/DataTable.svelte';
2
+ export * from './DataTable/core/types.js';
2
3
  export { DataTable };
@@ -1,2 +1,3 @@
1
1
  import DataTable from './DataTable/DataTable.svelte';
2
+ export * from './DataTable/core/types.js';
2
3
  export { DataTable };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@r2digisolutions/ui",
3
- "version": "0.22.3",
3
+ "version": "0.22.4",
4
4
  "private": false,
5
5
  "packageManager": "bun@1.2.22",
6
6
  "publishConfig": {