@gemologic/sheen-table 0.1.0-rc.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.
- package/LICENSE +19 -0
- package/README.md +19 -0
- package/dist/DataTable.d.ts +159 -0
- package/dist/DataTable.js +2724 -0
- package/dist/DataTableToolbar.d.ts +28 -0
- package/dist/DataTableToolbar.js +132 -0
- package/dist/FilterBar.d.ts +24 -0
- package/dist/FilterBar.js +681 -0
- package/dist/QueryBuilder.d.ts +11 -0
- package/dist/QueryBuilder.js +693 -0
- package/dist/cell-edit.d.ts +50 -0
- package/dist/cell-edit.js +178 -0
- package/dist/client-state.d.ts +28 -0
- package/dist/client-state.js +57 -0
- package/dist/client-view.d.ts +31 -0
- package/dist/client-view.js +30 -0
- package/dist/column-layout.d.ts +10 -0
- package/dist/column-layout.js +34 -0
- package/dist/columns.d.ts +108 -0
- package/dist/columns.js +217 -0
- package/dist/core.d.ts +54 -0
- package/dist/core.js +28 -0
- package/dist/export.d.ts +14 -0
- package/dist/export.js +27 -0
- package/dist/facets.d.ts +15 -0
- package/dist/facets.js +41 -0
- package/dist/filter-bar-state.d.ts +22 -0
- package/dist/filter-bar-state.js +128 -0
- package/dist/filter-client.d.ts +9 -0
- package/dist/filter-client.js +69 -0
- package/dist/filter.d.ts +64 -0
- package/dist/filter.js +132 -0
- package/dist/grouping.d.ts +37 -0
- package/dist/grouping.js +126 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +31 -0
- package/dist/messages.d.ts +115 -0
- package/dist/messages.js +121 -0
- package/dist/pagination.d.ts +36 -0
- package/dist/pagination.js +102 -0
- package/dist/query-builder-state.d.ts +28 -0
- package/dist/query-builder-state.js +128 -0
- package/dist/requests.d.ts +26 -0
- package/dist/requests.js +106 -0
- package/dist/row-hierarchy.d.ts +32 -0
- package/dist/row-hierarchy.js +170 -0
- package/dist/row-identity.d.ts +11 -0
- package/dist/row-identity.js +36 -0
- package/dist/saved-views.d.ts +52 -0
- package/dist/saved-views.js +153 -0
- package/dist/search-controller.d.ts +22 -0
- package/dist/search-controller.js +75 -0
- package/dist/search.d.ts +28 -0
- package/dist/search.js +111 -0
- package/dist/selection-client.d.ts +9 -0
- package/dist/selection-client.js +14 -0
- package/dist/selection.d.ts +25 -0
- package/dist/selection.js +60 -0
- package/dist/server-export.d.ts +27 -0
- package/dist/server-export.js +105 -0
- package/dist/sorting.d.ts +17 -0
- package/dist/sorting.js +58 -0
- package/dist/table-state-changes.d.ts +27 -0
- package/dist/table-state-changes.js +67 -0
- package/dist/table-state.d.ts +20 -0
- package/dist/table-state.js +77 -0
- package/dist/text-normalization.d.ts +2 -0
- package/dist/text-normalization.js +12 -0
- package/dist/url-state.d.ts +39 -0
- package/dist/url-state.js +75 -0
- package/package.json +66 -0
- package/src/DataTable.tsx +2322 -0
- package/src/DataTableToolbar.tsx +69 -0
- package/src/FilterBar.tsx +396 -0
- package/src/QueryBuilder.tsx +274 -0
- package/src/cell-edit.ts +187 -0
- package/src/client-state.ts +52 -0
- package/src/client-view.ts +61 -0
- package/src/column-layout.ts +47 -0
- package/src/columns.ts +271 -0
- package/src/core.ts +54 -0
- package/src/export.ts +39 -0
- package/src/facets.ts +46 -0
- package/src/filter-bar-state.ts +118 -0
- package/src/filter-client.ts +79 -0
- package/src/filter.ts +113 -0
- package/src/grouping.ts +185 -0
- package/src/index.ts +7 -0
- package/src/messages.ts +29 -0
- package/src/pagination.ts +81 -0
- package/src/query-builder-state.ts +105 -0
- package/src/requests.ts +85 -0
- package/src/row-hierarchy.ts +280 -0
- package/src/row-identity.ts +39 -0
- package/src/saved-views.ts +143 -0
- package/src/search-controller.ts +61 -0
- package/src/search.ts +137 -0
- package/src/selection-client.ts +23 -0
- package/src/selection.ts +62 -0
- package/src/server-export.ts +89 -0
- package/src/sorting.ts +63 -0
- package/src/styles.css +197 -0
- package/src/table-state-changes.ts +51 -0
- package/src/table-state.ts +72 -0
- package/src/text-normalization.ts +14 -0
- package/src/url-state.ts +62 -0
package/src/url-state.ts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { deserializeState, serializeState } from "./table-state.ts";
|
|
2
|
+
import type { TableState, TableStateSchema } from "./table-state.ts";
|
|
3
|
+
|
|
4
|
+
export interface TableUrlLocation { readonly pathname: string; readonly search: string; readonly hash: string }
|
|
5
|
+
export interface TableUrlRouter {
|
|
6
|
+
readonly location: () => TableUrlLocation;
|
|
7
|
+
readonly navigate: (to: string, options?: { readonly replace?: boolean; readonly scroll?: boolean }) => void;
|
|
8
|
+
}
|
|
9
|
+
export type TableUrlRead =
|
|
10
|
+
| { readonly kind: "absent" }
|
|
11
|
+
| { readonly kind: "accepted"; readonly state: TableState }
|
|
12
|
+
| { readonly kind: "invalid"; readonly error: unknown };
|
|
13
|
+
export type TableUrlWrite =
|
|
14
|
+
| { readonly kind: "unchanged"; readonly to: string }
|
|
15
|
+
| { readonly kind: "navigated"; readonly to: string };
|
|
16
|
+
|
|
17
|
+
function parameterName(value: string): string {
|
|
18
|
+
if (!/^[A-Za-z][A-Za-z0-9_.-]*$/.test(value)) throw new Error("Table URL parameter must start with a letter and contain only letters, digits, dot, underscore, or hyphen");
|
|
19
|
+
return value;
|
|
20
|
+
}
|
|
21
|
+
function locationParts(location: TableUrlLocation): { pathname: string; parameters: URLSearchParams; hash: string } {
|
|
22
|
+
if (!location.pathname.startsWith("/") || location.pathname.includes("?") || location.pathname.includes("#")) throw new Error("Router pathname must be an absolute path without query or hash");
|
|
23
|
+
if (location.hash && !location.hash.startsWith("#")) throw new Error("Router hash must be empty or start with #");
|
|
24
|
+
return { pathname: location.pathname, parameters: new URLSearchParams(location.search), hash: location.hash };
|
|
25
|
+
}
|
|
26
|
+
function target(pathname: string, parameters: URLSearchParams, hash: string): string {
|
|
27
|
+
const search = parameters.toString();
|
|
28
|
+
return `${pathname}${search ? `?${search}` : ""}${hash}`;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Pull-based URL state using the same structural adapter as AppShell. */
|
|
32
|
+
export function createTableUrlState(router: TableUrlRouter, parameter: string, schema: TableStateSchema) {
|
|
33
|
+
const name = parameterName(parameter);
|
|
34
|
+
function read(): TableUrlRead {
|
|
35
|
+
try {
|
|
36
|
+
const { parameters } = locationParts(router.location());
|
|
37
|
+
const values = parameters.getAll(name);
|
|
38
|
+
if (values.length === 0) return Object.freeze({ kind: "absent" });
|
|
39
|
+
if (values.length !== 1) throw new Error(`Table URL parameter ${name} must occur exactly once`);
|
|
40
|
+
return Object.freeze({ kind: "accepted", state: deserializeState(values[0] ?? "", schema) });
|
|
41
|
+
} catch (error) { return Object.freeze({ kind: "invalid", error }); }
|
|
42
|
+
}
|
|
43
|
+
function write(state: TableState, options: { readonly replace?: boolean } = {}): TableUrlWrite {
|
|
44
|
+
const current = locationParts(router.location());
|
|
45
|
+
const present = target(current.pathname, current.parameters, current.hash);
|
|
46
|
+
current.parameters.set(name, serializeState(state, schema));
|
|
47
|
+
const to = target(current.pathname, current.parameters, current.hash);
|
|
48
|
+
if (to === present) return Object.freeze({ kind: "unchanged", to });
|
|
49
|
+
router.navigate(to, { replace: options.replace ?? true, scroll: false });
|
|
50
|
+
return Object.freeze({ kind: "navigated", to });
|
|
51
|
+
}
|
|
52
|
+
function clear(options: { readonly replace?: boolean } = {}): TableUrlWrite {
|
|
53
|
+
const current = locationParts(router.location());
|
|
54
|
+
const present = target(current.pathname, current.parameters, current.hash);
|
|
55
|
+
current.parameters.delete(name);
|
|
56
|
+
const to = target(current.pathname, current.parameters, current.hash);
|
|
57
|
+
if (to === present) return Object.freeze({ kind: "unchanged", to });
|
|
58
|
+
router.navigate(to, { replace: options.replace ?? true, scroll: false });
|
|
59
|
+
return Object.freeze({ kind: "navigated", to });
|
|
60
|
+
}
|
|
61
|
+
return { read, write, clear };
|
|
62
|
+
}
|