@perspective-dev/viewer-datagrid 4.1.0 → 4.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.
Files changed (39) hide show
  1. package/dist/cdn/perspective-viewer-datagrid.js +4 -4
  2. package/dist/cdn/perspective-viewer-datagrid.js.map +4 -4
  3. package/dist/esm/event_handlers/click/edit_click.d.ts +1 -1
  4. package/dist/esm/model/create.d.ts +1 -1
  5. package/dist/esm/perspective-viewer-datagrid.js +3 -3
  6. package/dist/esm/perspective-viewer-datagrid.js.map +3 -3
  7. package/dist/esm/style_handlers/body.d.ts +1 -1
  8. package/dist/esm/style_handlers/column_header.d.ts +1 -1
  9. package/dist/esm/style_handlers/consolidated.d.ts +2 -5
  10. package/dist/esm/style_handlers/table_cell/boolean.d.ts +1 -5
  11. package/dist/esm/style_handlers/table_cell/cell_flash.d.ts +2 -2
  12. package/dist/esm/style_handlers/table_cell/datetime.d.ts +1 -5
  13. package/dist/esm/style_handlers/table_cell/row_header.d.ts +2 -2
  14. package/dist/esm/style_handlers/types.d.ts +2 -5
  15. package/dist/esm/types.d.ts +1 -1
  16. package/package.json +3 -3
  17. package/src/ts/color_utils.ts +0 -1
  18. package/src/ts/event_handlers/click/edit_click.ts +13 -10
  19. package/src/ts/event_handlers/dispatch_click.ts +2 -4
  20. package/src/ts/event_handlers/expand_collapse.ts +4 -3
  21. package/src/ts/event_handlers/focus.ts +1 -1
  22. package/src/ts/event_handlers/header_click.ts +1 -1
  23. package/src/ts/event_handlers/keydown/edit_keydown.ts +2 -2
  24. package/src/ts/event_handlers/row_select_click.ts +6 -4
  25. package/src/ts/event_handlers/select_region.ts +23 -11
  26. package/src/ts/event_handlers/sort.ts +1 -1
  27. package/src/ts/get_cell_config.ts +1 -0
  28. package/src/ts/model/create.ts +11 -18
  29. package/src/ts/style_handlers/body.ts +16 -21
  30. package/src/ts/style_handlers/column_header.ts +15 -4
  31. package/src/ts/style_handlers/consolidated.ts +8 -13
  32. package/src/ts/style_handlers/focus.ts +4 -10
  33. package/src/ts/style_handlers/group_header.ts +6 -3
  34. package/src/ts/style_handlers/table_cell/boolean.ts +2 -5
  35. package/src/ts/style_handlers/table_cell/cell_flash.ts +2 -2
  36. package/src/ts/style_handlers/table_cell/datetime.ts +2 -5
  37. package/src/ts/style_handlers/table_cell/row_header.ts +8 -7
  38. package/src/ts/style_handlers/types.ts +6 -6
  39. package/src/ts/types.ts +15 -1
@@ -12,12 +12,7 @@
12
12
 
13
13
  import { RegularTableElement } from "regular-table";
14
14
  import type { DatagridModel, SelectedPosition } from "../types.js";
15
-
16
- import {
17
- CollectedCell,
18
- LocalSelectedPositionMap,
19
- CellMetaExtended,
20
- } from "./types.js";
15
+ import { CollectedCell, LocalSelectedPositionMap } from "./types.js";
21
16
 
22
17
  /**
23
18
  * Apply focus style to the selected cell.
@@ -35,6 +30,7 @@ export function applyFocusStyle(
35
30
  if (selected_position) {
36
31
  for (const { element: td, metadata } of cells) {
37
32
  if (
33
+ metadata.type === "body" &&
38
34
  metadata.x === selected_position.x &&
39
35
  metadata.y === selected_position.y
40
36
  ) {
@@ -77,11 +73,9 @@ export function focusSelectedCell(
77
73
  if (tbody) {
78
74
  for (const tr of tbody.children) {
79
75
  for (const cell of tr.children) {
80
- const metadata = regularTable.getMeta(cell) as
81
- | CellMetaExtended
82
- | undefined;
76
+ const metadata = regularTable.getMeta(cell as HTMLElement);
83
77
  if (
84
- metadata &&
78
+ metadata?.type === "body" &&
85
79
  metadata.x === selected_position.x &&
86
80
  metadata.y === selected_position.y
87
81
  ) {
@@ -38,8 +38,10 @@ export function applyGroupHeaderStyles(
38
38
  td.style.backgroundColor = "";
39
39
 
40
40
  const needs_border =
41
- (header_depth > 0 && metadata.row_header_x === header_depth) ||
42
- (metadata.x ?? -1) >= 0;
41
+ (metadata.type === "corner" &&
42
+ header_depth > 0 &&
43
+ metadata.row_header_x === header_depth) ||
44
+ (metadata.type === "column_header" && metadata.x >= 0);
43
45
 
44
46
  td.classList.toggle("psp-align-right", false);
45
47
  td.classList.toggle("psp-align-left", false);
@@ -48,8 +50,9 @@ export function applyGroupHeaderStyles(
48
50
  td.classList.toggle("psp-header-border", needs_border);
49
51
  td.classList.toggle(
50
52
  "psp-header-group-corner",
51
- typeof metadata.x === "undefined",
53
+ metadata.type === "corner",
52
54
  );
55
+
53
56
  td.classList.toggle("psp-color-mode-bar", false);
54
57
  td.classList.toggle("psp-header-sort-asc", false);
55
58
  td.classList.toggle("psp-header-sort-desc", false);
@@ -13,16 +13,13 @@
13
13
  import { CellMetadata } from "regular-table/dist/esm/types.js";
14
14
  import type { DatagridModel, ColumnConfig, ColorRecord } from "../../types.js";
15
15
 
16
- interface CellMetaWithFlags extends CellMetadata {
17
- _is_hidden_by_aggregate_depth?: boolean;
18
- }
19
-
20
16
  export function cell_style_boolean(
21
17
  this: DatagridModel,
22
18
  _plugin: ColumnConfig | undefined,
23
19
  td: HTMLElement,
24
- metadata: CellMetaWithFlags,
20
+ metadata: CellMetadata,
25
21
  ): void {
22
+ // @ts-ignore
26
23
  if (metadata._is_hidden_by_aggregate_depth) {
27
24
  td.style.backgroundColor = "";
28
25
  td.style.color = "";
@@ -10,12 +10,12 @@
10
10
  // ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃
11
11
  // ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
12
12
 
13
- import { CellMetadata } from "regular-table/dist/esm/types.js";
13
+ import { CellMetadataBody } from "regular-table/dist/esm/types.js";
14
14
  import type { DatagridModel, ColorRecord } from "../../types.js";
15
15
 
16
16
  export function style_cell_flash(
17
17
  this: DatagridModel,
18
- metadata: CellMetadata,
18
+ metadata: CellMetadataBody,
19
19
  td: HTMLElement,
20
20
  [, , , , , pos_s, pos_e]: ColorRecord,
21
21
  [, , , , , neg_s, neg_e]: ColorRecord,
@@ -17,15 +17,11 @@ import {
17
17
  } from "../../color_utils.js";
18
18
  import type { DatagridModel, ColumnConfig, ColorRecord } from "../../types.js";
19
19
 
20
- interface CellMetaWithFlags extends CellMetadata {
21
- _is_hidden_by_aggregate_depth?: boolean;
22
- }
23
-
24
20
  export function cell_style_datetime(
25
21
  this: DatagridModel,
26
22
  plugin: ColumnConfig,
27
23
  td: HTMLElement,
28
- metadata: CellMetaWithFlags,
24
+ metadata: CellMetadata,
29
25
  ): void {
30
26
  const colorRecord: ColorRecord = //(() => {
31
27
  // if (plugin?.color !== undefined) {
@@ -38,6 +34,7 @@ export function cell_style_datetime(
38
34
 
39
35
  const [hex, r, g, b] = colorRecord;
40
36
 
37
+ // @ts-ignore
41
38
  if (metadata._is_hidden_by_aggregate_depth) {
42
39
  td.style.backgroundColor = "";
43
40
  td.style.color = "";
@@ -10,19 +10,18 @@
10
10
  // ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃
11
11
  // ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
12
12
 
13
- import { CellMetadata } from "regular-table/dist/esm/types.js";
13
+ import {
14
+ CellMetadata,
15
+ CellMetadataRowHeader,
16
+ } from "regular-table/dist/esm/types.js";
14
17
  import type { DatagridModel } from "../../types.js";
15
18
  import { RegularTableElement } from "regular-table";
16
19
 
17
- interface NextMeta {
18
- row_header?: unknown[];
19
- }
20
-
21
20
  export function cell_style_row_header(
22
21
  this: DatagridModel,
23
22
  regularTable: RegularTableElement,
24
23
  td: HTMLElement,
25
- metadata: CellMetadata,
24
+ metadata: CellMetadataRowHeader,
26
25
  ): void {
27
26
  const is_not_empty =
28
27
  metadata.value !== undefined &&
@@ -33,12 +32,14 @@ export function cell_style_row_header(
33
32
  const next = regularTable.getMeta({
34
33
  dx: 0,
35
34
  dy: (metadata.y ?? 0) - (metadata.y0 ?? 0) + 1,
36
- } as unknown as Element) as NextMeta | undefined;
35
+ } as CellMetadata);
36
+
37
37
  const is_collapse =
38
38
  next &&
39
39
  next.row_header &&
40
40
  typeof next.row_header[(metadata.row_header_x ?? 0) + 1] !==
41
41
  "undefined";
42
+
42
43
  td.classList.toggle("psp-tree-label", is_not_empty && !is_leaf);
43
44
  td.classList.toggle(
44
45
  "psp-tree-label-expand",
@@ -11,16 +11,16 @@
11
11
  // ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
12
12
 
13
13
  import { RegularTableElement } from "regular-table";
14
- import { CellMetadata } from "regular-table/dist/esm/types.js";
14
+ import {
15
+ CellMetadata,
16
+ CellMetadataBody,
17
+ CellMetadataRowHeader,
18
+ } from "regular-table/dist/esm/types.js";
15
19
  import type { SelectedPosition } from "../types.js";
16
20
 
17
- export interface CellMetaExtended extends CellMetadata {
18
- _is_hidden_by_aggregate_depth?: boolean;
19
- }
20
-
21
21
  export interface CollectedCell {
22
22
  element: HTMLElement;
23
- metadata: CellMetaExtended;
23
+ metadata: CellMetadataRowHeader | CellMetadataBody;
24
24
  isHeader: boolean;
25
25
  }
26
26
 
package/src/ts/types.ts CHANGED
@@ -23,7 +23,21 @@ import { CellMetadata, DataResponse } from "regular-table/dist/esm/types";
23
23
 
24
24
  // Re-export types from regular-table for use throughout the codebase
25
25
  export type { RegularTableElement as RegularTable };
26
- export type { CellMetadata as CellMeta };
26
+
27
+ export function get_psp_type(
28
+ model: DatagridModel,
29
+ metadata: CellMetadata,
30
+ ): ColumnType {
31
+ if (
32
+ metadata.type === "body" ||
33
+ metadata.type === "column_header" ||
34
+ metadata.type === "corner"
35
+ ) {
36
+ return model._column_types[metadata.x];
37
+ } else {
38
+ return model._row_header_types[(metadata.row_header_x ?? 0) - 1];
39
+ }
40
+ }
27
41
 
28
42
  // Edit mode for the datagrid
29
43
  export type EditMode =