@kayord/ui 0.16.4 → 0.17.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.
@@ -5,7 +5,6 @@
5
5
  import DoubleArrowLeft from "@lucide/svelte/icons/arrow-left";
6
6
  import DoubleArrowRight from "@lucide/svelte/icons/arrow-right";
7
7
  import { Select, Button } from "../../..";
8
- import type { ShadTable } from "./shad-table.svelte";
9
8
 
10
9
  interface Props<T> {
11
10
  table: Table<T>;
@@ -1,2 +1,2 @@
1
1
  export { default as DataTable } from "./DataTable.svelte";
2
- export { ShadTable, createShadSvelteTable } from "./shad-table.svelte";
2
+ export { createShadTable } from "./shad-table.svelte";
@@ -1,2 +1,2 @@
1
1
  export { default as DataTable } from "./DataTable.svelte";
2
- export { ShadTable, createShadSvelteTable } from "./shad-table.svelte";
2
+ export { createShadTable } from "./shad-table.svelte";
@@ -1,18 +1,9 @@
1
- import { type ColumnDef, type RowData, type RowModel, type Table, type TableOptions, type TableState } from "@tanstack/table-core";
1
+ import { type RowData, type RowModel, type Table, type TableOptions, type TableState } from "@tanstack/table-core";
2
2
  interface ShadTableOptions<TData extends RowData> extends Omit<TableOptions<TData>, "getCoreRowModel"> {
3
3
  getCoreRowModel?: (table: Table<any>) => () => RowModel<any>;
4
4
  enablePaging?: boolean;
5
5
  enableVisibility?: boolean;
6
6
  enableRowSelectionUI?: boolean;
7
7
  }
8
- export declare function createShadSvelteTable<TData extends RowData>(shadOptions: ShadTableOptions<TData>, stateUpdate?: (state: Partial<TableState>) => void): Table<TData>;
9
- export declare class ShadTable<TData extends RowData> {
10
- #private;
11
- columns: ColumnDef<TData>[];
12
- table: Table<TData>;
13
- options: ShadTableOptions<TData>;
14
- constructor(initOptions: ShadTableOptions<TData>, stateUpdate?: (state: Partial<TableState>) => void);
15
- updateOptions(): void;
16
- private features;
17
- }
8
+ export declare function createShadTable<TData extends RowData>(shadOptions: ShadTableOptions<TData>, stateUpdate?: (state: Partial<TableState>) => void): Table<TData>;
18
9
  export {};
@@ -1,7 +1,7 @@
1
1
  import { createTable, getCoreRowModel, getPaginationRowModel, getSortedRowModel, } from "@tanstack/table-core";
2
2
  import DataTableCheckbox from "./DataTableCheckbox.svelte";
3
3
  import { renderComponent } from "../../ui";
4
- export function createShadSvelteTable(shadOptions, stateUpdate) {
4
+ export function createShadTable(shadOptions, stateUpdate) {
5
5
  if (!shadOptions.getCoreRowModel) {
6
6
  shadOptions.getCoreRowModel = getCoreRowModel();
7
7
  }
@@ -148,153 +148,6 @@ export function createShadSvelteTable(shadOptions, stateUpdate) {
148
148
  }
149
149
  return table;
150
150
  }
151
- export class ShadTable {
152
- columns;
153
- table;
154
- #state = $state({});
155
- #stateUpdate;
156
- options;
157
- constructor(initOptions, stateUpdate) {
158
- if (stateUpdate) {
159
- this.#stateUpdate = stateUpdate;
160
- }
161
- else {
162
- this.#stateUpdate = (state) => {
163
- this.#state = state;
164
- };
165
- }
166
- this.options = initOptions;
167
- if (!this.options.getCoreRowModel) {
168
- this.options.getCoreRowModel = getCoreRowModel();
169
- }
170
- if ((this.options.enablePaging ?? true) == false) {
171
- this.options.manualPagination = true;
172
- }
173
- const plainOptions = this.options;
174
- const resolvedOptions = mergeObjects({
175
- state: {},
176
- onStateChange() { },
177
- renderFallbackValue: null,
178
- mergeOptions: (defaultOptions, options) => {
179
- return mergeObjects(defaultOptions, options);
180
- },
181
- }, plainOptions);
182
- this.table = createTable(resolvedOptions);
183
- this.#state = this.table.initialState;
184
- this.columns = this.options.columns;
185
- this.features();
186
- this.updateOptions();
187
- $effect.pre(() => {
188
- this.updateOptions();
189
- });
190
- $effect(() => {
191
- this.#stateUpdate(this.#state);
192
- });
193
- }
194
- updateOptions() {
195
- this.table.setOptions((prev) => {
196
- return mergeObjects(prev, this.options, {
197
- state: mergeObjects(this.#state, this.options.state || {}),
198
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
199
- onStateChange: (updater) => {
200
- if (updater instanceof Function)
201
- this.#state = updater(this.#state);
202
- else
203
- this.#state = mergeObjects(this.#state, updater);
204
- this.options.onStateChange?.(updater);
205
- },
206
- });
207
- });
208
- }
209
- features() {
210
- // Sorting
211
- if ((this.options.enableSorting ?? true) && !this.options.getSortedRowModel) {
212
- this.options.getSortedRowModel = getSortedRowModel();
213
- this.options.onSortingChange = (updater) => {
214
- if (typeof updater === "function") {
215
- if (this.options.state?.sorting) {
216
- this.options.state.sorting = updater(this.options.state.sorting);
217
- }
218
- else if (this.#state.sorting) {
219
- this.#state.sorting = updater(this.#state.sorting);
220
- }
221
- }
222
- else {
223
- if (this.options.state?.sorting) {
224
- this.options.state.sorting = updater;
225
- }
226
- else {
227
- this.#state.sorting = updater;
228
- }
229
- }
230
- };
231
- }
232
- // Paging
233
- if ((this.options.enablePaging ?? true) && !this.options.getPaginationRowModel) {
234
- this.options.getPaginationRowModel = getPaginationRowModel();
235
- this.options.onPaginationChange = (updater) => {
236
- if (typeof updater === "function") {
237
- if (this.options.state?.pagination) {
238
- this.options.state.pagination = updater(this.options.state.pagination);
239
- }
240
- else if (this.#state.pagination) {
241
- this.#state.pagination = updater(this.#state.pagination);
242
- }
243
- }
244
- else {
245
- if (this.options.state?.pagination) {
246
- this.options.state.pagination = updater;
247
- }
248
- else {
249
- this.#state.pagination = updater;
250
- }
251
- }
252
- };
253
- }
254
- // Row Selection
255
- if ((this.options.enableRowSelection ?? true) && !this.options.onRowSelectionChange) {
256
- this.options.onRowSelectionChange = (updater) => {
257
- if (typeof updater === "function") {
258
- if (this.options.state?.rowSelection) {
259
- this.options.state.rowSelection = updater(this.options.state.rowSelection);
260
- }
261
- else if (this.#state.rowSelection) {
262
- this.#state.rowSelection = updater(this.#state.rowSelection);
263
- }
264
- }
265
- else {
266
- if (this.options.state?.rowSelection) {
267
- this.options.state.rowSelection = updater;
268
- }
269
- else {
270
- this.#state.rowSelection = updater;
271
- }
272
- }
273
- };
274
- }
275
- // Column Visibility
276
- if ((this.options.enableVisibility ?? false) && !this.options.onColumnVisibilityChange) {
277
- this.options.onColumnVisibilityChange = (updater) => {
278
- if (typeof updater === "function") {
279
- if (this.options.state?.columnVisibility) {
280
- this.options.state.columnVisibility = updater(this.options.state.columnVisibility);
281
- }
282
- else if (this.#state.columnVisibility) {
283
- this.#state.columnVisibility = updater(this.#state.columnVisibility);
284
- }
285
- }
286
- else {
287
- if (this.options.state?.columnVisibility) {
288
- this.options.state.columnVisibility = updater;
289
- }
290
- else {
291
- this.#state.columnVisibility = updater;
292
- }
293
- }
294
- };
295
- }
296
- }
297
- }
298
151
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
299
152
  function mergeObjects(...sources) {
300
153
  const target = {};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@kayord/ui",
3
3
  "private": false,
4
- "version": "0.16.4",
4
+ "version": "0.17.0",
5
5
  "exports": {
6
6
  ".": {
7
7
  "types": "./dist/index.d.ts",