argus-table 0.2.2 → 0.4.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/README.md +1 -1
- package/dist/argus-column-group.js +66 -0
- package/dist/argus-column-group.js.map +1 -0
- package/dist/argus-column.js +28 -26
- package/dist/argus-column.js.map +1 -1
- package/dist/argus-table.js +1497 -285
- package/dist/argus-table.js.map +1 -1
- package/dist/attributes.js +21 -0
- package/dist/attributes.js.map +1 -0
- package/dist/cdn/argus-table.js +120 -61
- package/dist/cdn/argus-table.js.map +1 -1
- package/dist/column-registry.js +23 -0
- package/dist/column-registry.js.map +1 -0
- package/dist/controllers/auto-width.js +16 -4
- package/dist/controllers/auto-width.js.map +1 -1
- package/dist/controllers/column-children.js +32 -9
- package/dist/controllers/column-children.js.map +1 -1
- package/dist/controllers/column-window.js +135 -0
- package/dist/controllers/column-window.js.map +1 -0
- package/dist/controllers/data-controller.js +9 -4
- package/dist/controllers/data-controller.js.map +1 -1
- package/dist/controllers/plugins.js +121 -0
- package/dist/controllers/plugins.js.map +1 -0
- package/dist/controllers/reorder-drag.js +19 -17
- package/dist/controllers/reorder-drag.js.map +1 -1
- package/dist/controllers/row-measure.js +122 -0
- package/dist/controllers/row-measure.js.map +1 -0
- package/dist/controllers/virtual-controller.js +315 -21
- package/dist/controllers/virtual-controller.js.map +1 -1
- package/dist/core/src/columns/column-groups.js +129 -0
- package/dist/core/src/columns/column-groups.js.map +1 -0
- package/dist/core/src/columns/column-order.js +125 -27
- package/dist/core/src/columns/column-order.js.map +1 -1
- package/dist/core/src/columns/resolve-columns.js +18 -5
- package/dist/core/src/columns/resolve-columns.js.map +1 -1
- package/dist/core/src/columns/spread-width.js +43 -0
- package/dist/core/src/columns/spread-width.js.map +1 -0
- package/dist/core/src/data/page-cache.js +4 -0
- package/dist/core/src/data/page-cache.js.map +1 -1
- package/dist/core/src/filters/filter.js +183 -0
- package/dist/core/src/filters/filter.js.map +1 -0
- package/dist/core/src/grid/row-layout.js +19 -11
- package/dist/core/src/grid/row-layout.js.map +1 -1
- package/dist/core/src/state/selection.js +71 -0
- package/dist/core/src/state/selection.js.map +1 -0
- package/dist/core/src/table/create-table.js +276 -66
- package/dist/core/src/table/create-table.js.map +1 -1
- package/dist/core/src/table/filtered-row-model.js +48 -0
- package/dist/core/src/table/filtered-row-model.js.map +1 -0
- package/dist/core/src/table/sorted-row-model.js +13 -2
- package/dist/core/src/table/sorted-row-model.js.map +1 -1
- package/dist/core/src/virtual/column-window.js +72 -0
- package/dist/core/src/virtual/column-window.js.map +1 -0
- package/dist/core/src/virtual/row-pool.js +2 -1
- package/dist/core/src/virtual/row-pool.js.map +1 -1
- package/dist/core/src/virtual/row-sizes.js +152 -0
- package/dist/core/src/virtual/row-sizes.js.map +1 -0
- package/dist/core/src/virtual/scroll-scale.js +41 -3
- package/dist/core/src/virtual/scroll-scale.js.map +1 -1
- package/dist/custom-elements.json +1683 -211
- package/dist/events.js +16 -8
- package/dist/events.js.map +1 -1
- package/dist/index.d.ts +808 -127
- package/dist/index.js +4 -2
- package/dist/interactive.js +22 -0
- package/dist/interactive.js.map +1 -0
- package/dist/max-height.js +22 -8
- package/dist/max-height.js.map +1 -1
- package/dist/render/body.js +48 -8
- package/dist/render/body.js.map +1 -1
- package/dist/render/cells.js +22 -11
- package/dist/render/cells.js.map +1 -1
- package/dist/render/content-directive.js +115 -0
- package/dist/render/content-directive.js.map +1 -0
- package/dist/render/content.js +33 -10
- package/dist/render/content.js.map +1 -1
- package/dist/render/header.js +104 -22
- package/dist/render/header.js.map +1 -1
- package/dist/render/pinned-rows.js +1 -1
- package/dist/render/pinned-rows.js.map +1 -1
- package/dist/styles/base.js +1 -1
- package/dist/styles/base.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// src/column-registry.ts
|
|
2
|
+
/**
|
|
3
|
+
* Elements watching their `<argus-column>` and `<argus-column-group>` children,
|
|
4
|
+
* by element: tables, and groups (which pass it on to their own parent). Columns
|
|
5
|
+
* and groups call their parent's entry when they connect, disconnect or change,
|
|
6
|
+
* so the table needs no MutationObserver on its own children (which would fire on
|
|
7
|
+
* every light-DOM cell render while scrolling).
|
|
8
|
+
*/
|
|
9
|
+
var watchers = /* @__PURE__ */ new WeakMap();
|
|
10
|
+
/** Calls `onChange` whenever a column or group child of `host` is added, removed, moved or changed. */
|
|
11
|
+
function watchColumns(host, onChange) {
|
|
12
|
+
watchers.set(host, onChange);
|
|
13
|
+
}
|
|
14
|
+
function unwatchColumns(host) {
|
|
15
|
+
watchers.delete(host);
|
|
16
|
+
}
|
|
17
|
+
/** Tells a column's or group's parent that it changed. */
|
|
18
|
+
function notify(parent) {
|
|
19
|
+
if (parent) watchers.get(parent)?.();
|
|
20
|
+
}
|
|
21
|
+
export { notify, unwatchColumns, watchColumns };
|
|
22
|
+
|
|
23
|
+
//# sourceMappingURL=column-registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"column-registry.js","names":[],"sources":["../src/column-registry.ts"],"sourcesContent":["/**\n * Elements watching their `<argus-column>` and `<argus-column-group>` children,\n * by element: tables, and groups (which pass it on to their own parent). Columns\n * and groups call their parent's entry when they connect, disconnect or change,\n * so the table needs no MutationObserver on its own children (which would fire on\n * every light-DOM cell render while scrolling).\n */\nconst watchers = new WeakMap<Element, () => void>();\n\n/** Calls `onChange` whenever a column or group child of `host` is added, removed, moved or changed. */\nexport function watchColumns(host: Element, onChange: () => void): void {\n watchers.set(host, onChange);\n}\n\nexport function unwatchColumns(host: Element): void {\n watchers.delete(host);\n}\n\n/** Tells a column's or group's parent that it changed. */\nexport function notify(parent: Element | null): void {\n if (parent) watchers.get(parent)?.();\n}\n"],"mappings":";;;;;;;;AAOA,IAAM,2BAAW,IAAI,QAA6B;;AAGlD,SAAgB,aAAa,MAAe,UAA4B;CACtE,SAAS,IAAI,MAAM,QAAQ;AAC7B;AAEA,SAAgB,eAAe,MAAqB;CAClD,SAAS,OAAO,IAAI;AACtB;;AAGA,SAAgB,OAAO,QAA8B;CACnD,IAAI,QAAQ,SAAS,IAAI,MAAM,CAAC,GAAG;AACrC"}
|
|
@@ -49,14 +49,26 @@ var AutoWidths = class {
|
|
|
49
49
|
if (kept.length !== Object.keys(this.widths).length) this.widths = Object.fromEntries(kept);
|
|
50
50
|
}
|
|
51
51
|
/**
|
|
52
|
+
* The auto columns still to be measured: never, or without loaded rows yet.
|
|
53
|
+
* With `virtualizeColumns` they render out of view until they are.
|
|
54
|
+
*/
|
|
55
|
+
pending(columns) {
|
|
56
|
+
return this.#due(columns, true);
|
|
57
|
+
}
|
|
58
|
+
/** The auto columns never measured, or measured without loaded rows when there are some now. */
|
|
59
|
+
#due(columns, hasLoadedRows) {
|
|
60
|
+
return columns.filter((c) => {
|
|
61
|
+
if (!c.auto) return false;
|
|
62
|
+
const state = this.#state.get(c.id);
|
|
63
|
+
return state === void 0 || state === "provisional" && hasLoadedRows;
|
|
64
|
+
}).map((c) => c.id);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
52
67
|
* Measures the auto columns that need it. Returns `true` if a width changed;
|
|
53
68
|
* the caller then renders again (the one extra pass of the render cycle).
|
|
54
69
|
*/
|
|
55
70
|
measure(root, columns, hasLoadedRows) {
|
|
56
|
-
const due = columns
|
|
57
|
-
const state = this.#state.get(id);
|
|
58
|
-
return state === void 0 || state === "provisional" && hasLoadedRows;
|
|
59
|
-
});
|
|
71
|
+
const due = this.#due(columns, hasLoadedRows);
|
|
60
72
|
if (due.length === 0) return false;
|
|
61
73
|
const measured = measureColumns(root, due);
|
|
62
74
|
const fontsLoading = typeof document !== "undefined" && document.fonts.status === "loading";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auto-width.js","names":[],"sources":["../../src/controllers/auto-width.ts"],"sourcesContent":["import type { ColumnSizingState } from '@argus-table/core';\n\n/**\n * The width each column's content needs, in px, from the cells rendered now:\n * the header, the pinned rows and the rendered body rows. Rows that haven't\n * loaded are skipped (their skeleton bars say nothing about the content).\n *\n * Every cell of the columns gets `data-measure`, which sizes it to its\n * `max-content` (base styles), so the browser accounts for padding, the sort\n * indicator and whatever the content is. One forced layout, no paint: the\n * attribute is gone before the frame ends. A column with nothing laid out\n * (the table is hidden) is left out.\n */\nexport function measureColumns(root: ParentNode, ids: Iterable<string>): Map<string, number> {\n const wanted = new Set(ids);\n const widths = new Map<string, number>();\n if (wanted.size === 0) return widths;\n const cells = [...root.querySelectorAll<HTMLElement>('[data-col]')].filter(\n (cell) =>\n wanted.has(cell.dataset.col ?? '') && !cell.parentElement?.matches('[part~=\"row-loading\"]'),\n );\n for (const cell of cells) cell.setAttribute('data-measure', '');\n for (const cell of cells) {\n const id = cell.dataset.col ?? '';\n const px = Math.ceil(cell.getBoundingClientRect().width);\n if (px > 0 && px > (widths.get(id) ?? 0)) widths.set(id, px);\n }\n for (const cell of cells) cell.removeAttribute('data-measure');\n return widths;\n}\n\n/**\n * - `provisional`: measured without loaded body rows (the header and pinned rows only).\n * - `final`: measured with loaded rows; kept until the column goes away.\n * - `fonts`: measured while web fonts were loading; measured again once they are ready.\n */\ntype State = 'provisional' | 'final' | 'fonts';\n\n/**\n * Widths of `width: 'auto'` columns. A column measures once its first loaded\n * rows render, and before that fits the header and pinned rows. So each column\n * is measured at most twice (three times if fonts were still loading), and a\n * table that stays empty doesn't measure on every update. State is keyed by\n * column id, so new `columns` arrays with the same ids don't measure again.\n */\nexport class AutoWidths {\n /** Measured widths by column id; a new object whenever one changes. */\n widths: ColumnSizingState = {};\n readonly #state = new Map<string, State>();\n #fontsPending = false;\n readonly #requestUpdate: () => void;\n\n constructor(requestUpdate: () => void) {\n this.#requestUpdate = requestUpdate;\n }\n\n /** Forgets columns that are gone or no longer `'auto'`, given the ids of the auto columns. */\n sync(ids: Iterable<string>): void {\n const auto = new Set(ids);\n for (const id of this.#state.keys()) {\n if (!auto.has(id)) this.#state.delete(id);\n }\n const kept = Object.entries(this.widths).filter(([id]) => auto.has(id));\n if (kept.length !== Object.keys(this.widths).length) this.widths = Object.fromEntries(kept);\n }\n\n /**\n *
|
|
1
|
+
{"version":3,"file":"auto-width.js","names":[],"sources":["../../src/controllers/auto-width.ts"],"sourcesContent":["import type { ColumnSizingState } from '@argus-table/core';\n\n/**\n * The width each column's content needs, in px, from the cells rendered now:\n * the header, the pinned rows and the rendered body rows. Rows that haven't\n * loaded are skipped (their skeleton bars say nothing about the content).\n *\n * Every cell of the columns gets `data-measure`, which sizes it to its\n * `max-content` (base styles), so the browser accounts for padding, the sort\n * indicator and whatever the content is. One forced layout, no paint: the\n * attribute is gone before the frame ends. A column with nothing laid out\n * (the table is hidden) is left out.\n */\nexport function measureColumns(root: ParentNode, ids: Iterable<string>): Map<string, number> {\n const wanted = new Set(ids);\n const widths = new Map<string, number>();\n if (wanted.size === 0) return widths;\n const cells = [...root.querySelectorAll<HTMLElement>('[data-col]')].filter(\n (cell) =>\n wanted.has(cell.dataset.col ?? '') && !cell.parentElement?.matches('[part~=\"row-loading\"]'),\n );\n for (const cell of cells) cell.setAttribute('data-measure', '');\n for (const cell of cells) {\n const id = cell.dataset.col ?? '';\n const px = Math.ceil(cell.getBoundingClientRect().width);\n if (px > 0 && px > (widths.get(id) ?? 0)) widths.set(id, px);\n }\n for (const cell of cells) cell.removeAttribute('data-measure');\n return widths;\n}\n\n/**\n * - `provisional`: measured without loaded body rows (the header and pinned rows only).\n * - `final`: measured with loaded rows; kept until the column goes away.\n * - `fonts`: measured while web fonts were loading; measured again once they are ready.\n */\ntype State = 'provisional' | 'final' | 'fonts';\n\n/**\n * Widths of `width: 'auto'` columns. A column measures once its first loaded\n * rows render, and before that fits the header and pinned rows. So each column\n * is measured at most twice (three times if fonts were still loading), and a\n * table that stays empty doesn't measure on every update. State is keyed by\n * column id, so new `columns` arrays with the same ids don't measure again.\n */\nexport class AutoWidths {\n /** Measured widths by column id; a new object whenever one changes. */\n widths: ColumnSizingState = {};\n readonly #state = new Map<string, State>();\n #fontsPending = false;\n readonly #requestUpdate: () => void;\n\n constructor(requestUpdate: () => void) {\n this.#requestUpdate = requestUpdate;\n }\n\n /** Forgets columns that are gone or no longer `'auto'`, given the ids of the auto columns. */\n sync(ids: Iterable<string>): void {\n const auto = new Set(ids);\n for (const id of this.#state.keys()) {\n if (!auto.has(id)) this.#state.delete(id);\n }\n const kept = Object.entries(this.widths).filter(([id]) => auto.has(id));\n if (kept.length !== Object.keys(this.widths).length) this.widths = Object.fromEntries(kept);\n }\n\n /**\n * The auto columns still to be measured: never, or without loaded rows yet.\n * With `virtualizeColumns` they render out of view until they are.\n */\n pending(columns: readonly { id: string; auto: boolean }[]): string[] {\n return this.#due(columns, true);\n }\n\n /** The auto columns never measured, or measured without loaded rows when there are some now. */\n #due(columns: readonly { id: string; auto: boolean }[], hasLoadedRows: boolean): string[] {\n return columns\n .filter((c) => {\n if (!c.auto) return false;\n const state = this.#state.get(c.id);\n return state === undefined || (state === 'provisional' && hasLoadedRows);\n })\n .map((c) => c.id);\n }\n\n /**\n * Measures the auto columns that need it. Returns `true` if a width changed;\n * the caller then renders again (the one extra pass of the render cycle).\n */\n measure(\n root: ParentNode,\n columns: readonly { id: string; auto: boolean }[],\n hasLoadedRows: boolean,\n ): boolean {\n const due = this.#due(columns, hasLoadedRows);\n if (due.length === 0) return false;\n const measured = measureColumns(root, due);\n const fontsLoading = typeof document !== 'undefined' && document.fonts.status === 'loading';\n let next: ColumnSizingState | undefined;\n for (const [id, px] of measured) {\n this.#state.set(id, fontsLoading ? 'fonts' : hasLoadedRows ? 'final' : 'provisional');\n if (this.widths[id] !== px) (next ??= { ...this.widths })[id] = px;\n }\n if (fontsLoading && measured.size > 0) this.#remeasureAfterFonts();\n if (next) this.widths = next;\n return next !== undefined;\n }\n\n /** Once web fonts are ready, columns measured meanwhile measure again. */\n #remeasureAfterFonts(): void {\n if (this.#fontsPending) return;\n this.#fontsPending = true;\n void document.fonts.ready.then(() => {\n this.#fontsPending = false;\n let any = false;\n for (const [id, state]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|
|
|
1
|
-
import { ArgusColumn
|
|
1
|
+
import { ArgusColumn } from "../argus-column.js";
|
|
2
|
+
import { ArgusColumnGroup } from "../argus-column-group.js";
|
|
3
|
+
import { unwatchColumns, watchColumns } from "../column-registry.js";
|
|
2
4
|
// src/controllers/column-children.ts
|
|
5
|
+
var NO_GROUPS = [];
|
|
6
|
+
/** The `<argus-column>`s among an element's children and in its groups, in document order. */
|
|
7
|
+
function columnsIn(parent) {
|
|
8
|
+
return [...parent.children].flatMap((c) => {
|
|
9
|
+
if (c instanceof ArgusColumn) return [c];
|
|
10
|
+
if (c instanceof ArgusColumnGroup) return columnsIn(c);
|
|
11
|
+
return [];
|
|
12
|
+
});
|
|
13
|
+
}
|
|
3
14
|
/**
|
|
4
|
-
* Reads the host's `<argus-column>` children
|
|
5
|
-
*
|
|
6
|
-
* `
|
|
15
|
+
* Reads the host's `<argus-column>` children, and those in its
|
|
16
|
+
* `<argus-column-group>` children, into `ColumnDef`s, and the groups into
|
|
17
|
+
* `ColumnGroup`s. Columns and groups tell the host when they change
|
|
18
|
+
* (`watchColumns`); the lists are rebuilt only then, so they keep their identity
|
|
19
|
+
* between changes.
|
|
7
20
|
*/
|
|
8
21
|
var ColumnChildrenController = class {
|
|
9
22
|
#host;
|
|
10
23
|
#defs = [];
|
|
24
|
+
#groups = NO_GROUPS;
|
|
11
25
|
#dirty = true;
|
|
12
26
|
constructor(host) {
|
|
13
27
|
this.#host = host;
|
|
@@ -27,14 +41,23 @@ var ColumnChildrenController = class {
|
|
|
27
41
|
get present() {
|
|
28
42
|
return this.defs.length > 0;
|
|
29
43
|
}
|
|
30
|
-
/** The children's columns, in document order. */
|
|
44
|
+
/** The children's columns, in document order, those in groups included. */
|
|
31
45
|
get defs() {
|
|
32
|
-
|
|
33
|
-
this.#dirty = false;
|
|
34
|
-
this.#defs = [...this.#host.children].filter((c) => c instanceof ArgusColumn).map((c) => c.toColumnDef());
|
|
35
|
-
}
|
|
46
|
+
this.#read();
|
|
36
47
|
return this.#defs;
|
|
37
48
|
}
|
|
49
|
+
/** The `<argus-column-group>` children's groups, in document order. */
|
|
50
|
+
get groups() {
|
|
51
|
+
this.#read();
|
|
52
|
+
return this.#groups;
|
|
53
|
+
}
|
|
54
|
+
#read() {
|
|
55
|
+
if (!this.#dirty) return;
|
|
56
|
+
this.#dirty = false;
|
|
57
|
+
this.#defs = columnsIn(this.#host).map((c) => c.toColumnDef());
|
|
58
|
+
const groups = [...this.#host.children].filter((c) => c instanceof ArgusColumnGroup).map((c) => c.toColumnGroup());
|
|
59
|
+
this.#groups = groups.length ? groups : NO_GROUPS;
|
|
60
|
+
}
|
|
38
61
|
};
|
|
39
62
|
export { ColumnChildrenController };
|
|
40
63
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"column-children.js","names":[],"sources":["../../src/controllers/column-children.ts"],"sourcesContent":["import type { ReactiveController, ReactiveControllerHost } from 'lit';\nimport { ArgusColumn
|
|
1
|
+
{"version":3,"file":"column-children.js","names":[],"sources":["../../src/controllers/column-children.ts"],"sourcesContent":["import type { ReactiveController, ReactiveControllerHost } from 'lit';\nimport { ArgusColumn } from '../argus-column.js';\nimport { ArgusColumnGroup } from '../argus-column-group.js';\nimport { unwatchColumns, watchColumns } from '../column-registry.js';\nimport type { ColumnDef, ColumnGroup } from '../types.js';\n\nconst NO_GROUPS: readonly ColumnGroup[] = [];\n\n/** The `<argus-column>`s among an element's children and in its groups, in document order. */\nfunction columnsIn<T>(parent: Element): ArgusColumn<T>[] {\n return [...parent.children].flatMap((c) => {\n if (c instanceof ArgusColumn) return [c as ArgusColumn<T>];\n if (c instanceof ArgusColumnGroup) return columnsIn<T>(c);\n return [];\n });\n}\n\n/**\n * Reads the host's `<argus-column>` children, and those in its\n * `<argus-column-group>` children, into `ColumnDef`s, and the groups into\n * `ColumnGroup`s. Columns and groups tell the host when they change\n * (`watchColumns`); the lists are rebuilt only then, so they keep their identity\n * between changes.\n */\nexport class ColumnChildrenController<T> implements ReactiveController {\n readonly #host: ReactiveControllerHost & HTMLElement;\n #defs: readonly ColumnDef<T>[] = [];\n #groups: readonly ColumnGroup[] = NO_GROUPS;\n #dirty = true;\n\n constructor(host: ReactiveControllerHost & HTMLElement) {\n this.#host = host;\n host.addController(this);\n }\n\n hostConnected(): void {\n this.#dirty = true;\n watchColumns(this.#host, () => {\n this.#dirty = true;\n this.#host.requestUpdate();\n });\n }\n\n hostDisconnected(): void {\n unwatchColumns(this.#host);\n }\n\n /** Whether the host has any `<argus-column>` child. */\n get present(): boolean {\n return this.defs.length > 0;\n }\n\n /** The children's columns, in document order, those in groups included. */\n get defs(): readonly ColumnDef<T>[] {\n this.#read();\n return this.#defs;\n }\n\n /** The `<argus-column-group>` children's groups, in document order. */\n get groups(): readonly ColumnGroup[] {\n this.#read();\n return this.#groups;\n }\n\n #read(): void {\n if (!this.#dirty) return;\n this.#dirty = false;\n this.#defs = columnsIn<T>(this.#host).map((c) => c.toColumnDef());\n const groups = [...this.#host.children]\n .filter((c): c is ArgusColumnGroup => c instanceof ArgusColumnGroup)\n .map((c) => c.toColumnGroup());\n this.#groups = groups.length ? groups : NO_GROUPS;\n }\n}\n"],"mappings":";;;;AAMA,IAAM,YAAoC,CAAC;;AAG3C,SAAS,UAAa,QAAmC;CACvD,OAAO,CAAC,GAAG,OAAO,QAAQ,CAAC,CAAC,SAAS,MAAM;EACzC,IAAI,aAAa,aAAa,OAAO,CAAC,CAAmB;EACzD,IAAI,aAAa,kBAAkB,OAAO,UAAa,CAAC;EACxD,OAAO,CAAC;CACV,CAAC;AACH;;;;;;;;AASA,IAAa,2BAAb,MAAuE;CACrE;CACA,QAAiC,CAAC;CAClC,UAAkC;CAClC,SAAS;CAET,YAAY,MAA4C;EACtD,KAAK,QAAQ;EACb,KAAK,cAAc,IAAI;CACzB;CAEA,gBAAsB;EACpB,KAAK,SAAS;EACd,aAAa,KAAK,aAAa;GAC7B,KAAK,SAAS;GACd,KAAK,MAAM,cAAc;EAC3B,CAAC;CACH;CAEA,mBAAyB;EACvB,eAAe,KAAK,KAAK;CAC3B;;CAGA,IAAI,UAAmB;EACrB,OAAO,KAAK,KAAK,SAAS;CAC5B;;CAGA,IAAI,OAAgC;EAClC,KAAK,MAAM;EACX,OAAO,KAAK;CACd;;CAGA,IAAI,SAAiC;EACnC,KAAK,MAAM;EACX,OAAO,KAAK;CACd;CAEA,QAAc;EACZ,IAAI,CAAC,KAAK,QAAQ;EAClB,KAAK,SAAS;EACd,KAAK,QAAQ,UAAa,KAAK,KAAK,CAAC,CAAC,KAAK,MAAM,EAAE,YAAY,CAAC;EAChE,MAAM,SAAS,CAAC,GAAG,KAAK,MAAM,QAAQ,CAAC,CACpC,QAAQ,MAA6B,aAAa,gBAAgB,CAAC,CACnE,KAAK,MAAM,EAAE,cAAc,CAAC;EAC/B,KAAK,UAAU,OAAO,SAAS,SAAS;CAC1C;AACF"}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { columnWindow, maxVisibleColumns } from "../core/src/virtual/column-window.js";
|
|
2
|
+
import { RowPool } from "../core/src/virtual/row-pool.js";
|
|
3
|
+
/**
|
|
4
|
+
* Column virtualization (`virtualizeColumns`): which columns render, and which
|
|
5
|
+
* pool slot's DOM each one uses.
|
|
6
|
+
*
|
|
7
|
+
* Off, every column renders in visual order, its slot is its `colIndex` and
|
|
8
|
+
* its cells are keyed by column id: the DOM is what it always was.
|
|
9
|
+
*
|
|
10
|
+
* On, the scrolling columns in view render, plus `COLUMN_OVERSCAN` on each
|
|
11
|
+
* side, and the pinned columns, the checkbox column and the columns the table
|
|
12
|
+
* keeps (the active one, one being dragged, auto widths still to measure)
|
|
13
|
+
* whatever the scroll position. They are pooled like rows (ADR 0001): a column
|
|
14
|
+
* entering the view reuses the cells, slots and content of one that left, so
|
|
15
|
+
* the DOM is updated in place, and the window has one size, so the pool fills
|
|
16
|
+
* on the first render and scrolling only reuses it (in WebKit, new slots
|
|
17
|
+
* while scrolling cut a wheel scroll short; see `steadyWindow`). DOM order is
|
|
18
|
+
* then pool order: each cell is placed in its grid column explicitly, and
|
|
19
|
+
* `aria-colindex` carries the position, as `aria-rowindex` does for rows.
|
|
20
|
+
*/
|
|
21
|
+
var ColumnWindowController = class {
|
|
22
|
+
#host;
|
|
23
|
+
#scroller;
|
|
24
|
+
#pool = new RowPool();
|
|
25
|
+
#attached;
|
|
26
|
+
#resize;
|
|
27
|
+
#enabled = false;
|
|
28
|
+
/** The columns of the last render, and what the window was computed from. */
|
|
29
|
+
#columns = [];
|
|
30
|
+
#scrolling = [];
|
|
31
|
+
#pinnedWidth = 0;
|
|
32
|
+
#maxVisible;
|
|
33
|
+
/** First index and size of the last window rendered. */
|
|
34
|
+
#key = "";
|
|
35
|
+
constructor(host, scroller) {
|
|
36
|
+
this.#host = host;
|
|
37
|
+
this.#scroller = scroller;
|
|
38
|
+
host.addController(this);
|
|
39
|
+
}
|
|
40
|
+
hostConnected() {
|
|
41
|
+
this.#attach();
|
|
42
|
+
}
|
|
43
|
+
hostUpdated() {
|
|
44
|
+
this.#attach();
|
|
45
|
+
}
|
|
46
|
+
hostDisconnected() {
|
|
47
|
+
this.#attached?.removeEventListener("scroll", this.#onScroll);
|
|
48
|
+
this.#resize?.disconnect();
|
|
49
|
+
this.#attached = void 0;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* The columns to render, given the model's columns in visual order. With
|
|
53
|
+
* `enabled`, `keep` names columns to render wherever they are. Call once per
|
|
54
|
+
* render.
|
|
55
|
+
*/
|
|
56
|
+
compute(columns, enabled, keep) {
|
|
57
|
+
this.#enabled = enabled;
|
|
58
|
+
if (!enabled) {
|
|
59
|
+
this.#pool.clear();
|
|
60
|
+
this.#key = "";
|
|
61
|
+
return columns.map((c) => ({
|
|
62
|
+
...c,
|
|
63
|
+
slot: c.colIndex,
|
|
64
|
+
key: c.id,
|
|
65
|
+
place: void 0
|
|
66
|
+
}));
|
|
67
|
+
}
|
|
68
|
+
if (columns !== this.#columns) {
|
|
69
|
+
this.#columns = columns;
|
|
70
|
+
this.#scrolling = columns.filter((c) => c.kind === "data" && c.pin === void 0);
|
|
71
|
+
this.#pinnedWidth = columns.reduce((sum, c) => c.pin ? sum + c.width : sum, 0);
|
|
72
|
+
}
|
|
73
|
+
const wanted = new Set(keep);
|
|
74
|
+
const window = this.#window();
|
|
75
|
+
for (const i of window) wanted.add(this.#scrolling[i]?.id);
|
|
76
|
+
this.#key = keyOf(window);
|
|
77
|
+
const ids = [];
|
|
78
|
+
const byId = /* @__PURE__ */ new Map();
|
|
79
|
+
for (const c of columns) if (c.pin !== void 0 || c.kind !== "data" || wanted.has(c.id)) {
|
|
80
|
+
ids.push(c.id);
|
|
81
|
+
byId.set(c.id, c);
|
|
82
|
+
}
|
|
83
|
+
const rendered = [];
|
|
84
|
+
for (const { id, slot } of this.#pool.update(ids)) {
|
|
85
|
+
const c = byId.get(id);
|
|
86
|
+
if (c) rendered.push({
|
|
87
|
+
...c,
|
|
88
|
+
slot,
|
|
89
|
+
key: slot,
|
|
90
|
+
place: c.colIndex
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
return rendered;
|
|
94
|
+
}
|
|
95
|
+
/** The window's indexes in the scrolling columns, for the scroller as it is now. */
|
|
96
|
+
#window() {
|
|
97
|
+
const s = this.#attached ?? this.#scroller();
|
|
98
|
+
const view = Math.max(0, (s ?? this.#host).clientWidth - this.#pinnedWidth);
|
|
99
|
+
const columns = this.#scrolling;
|
|
100
|
+
let max = this.#maxVisible;
|
|
101
|
+
if (max?.columns !== this.#columns || max.view !== view) {
|
|
102
|
+
max = {
|
|
103
|
+
columns: this.#columns,
|
|
104
|
+
view,
|
|
105
|
+
value: maxVisibleColumns(columns, view)
|
|
106
|
+
};
|
|
107
|
+
this.#maxVisible = max;
|
|
108
|
+
}
|
|
109
|
+
const offset = Math.abs(s?.scrollLeft ?? 0);
|
|
110
|
+
return columnWindow(columns, offset, view, 2, max.value);
|
|
111
|
+
}
|
|
112
|
+
#attach() {
|
|
113
|
+
const s = this.#scroller();
|
|
114
|
+
if (!s || s === this.#attached) return;
|
|
115
|
+
this.#attached?.removeEventListener("scroll", this.#onScroll);
|
|
116
|
+
this.#attached = s;
|
|
117
|
+
s.addEventListener("scroll", this.#onScroll, { passive: true });
|
|
118
|
+
this.#resize ??= new ResizeObserver(() => {
|
|
119
|
+
this.#onScroll();
|
|
120
|
+
});
|
|
121
|
+
this.#resize.disconnect();
|
|
122
|
+
this.#resize.observe(s);
|
|
123
|
+
}
|
|
124
|
+
/** Renders again when the window moves: not on every scroll event. */
|
|
125
|
+
#onScroll = () => {
|
|
126
|
+
if (!this.#enabled) return;
|
|
127
|
+
if (keyOf(this.#window()) !== this.#key) this.#host.requestUpdate();
|
|
128
|
+
};
|
|
129
|
+
};
|
|
130
|
+
function keyOf(window) {
|
|
131
|
+
return `${String(window[0] ?? -1)}:${String(window.length)}`;
|
|
132
|
+
}
|
|
133
|
+
export { ColumnWindowController };
|
|
134
|
+
|
|
135
|
+
//# sourceMappingURL=column-window.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"column-window.js","names":[],"sources":["../../src/controllers/column-window.ts"],"sourcesContent":["import type { ReactiveController, ReactiveControllerHost } from 'lit';\nimport { columnWindow, maxVisibleColumns, RowPool, type ColumnView } from '@argus-table/core';\nimport type { CellContent } from '../types.js';\n\n/** Scrolling columns rendered beyond each side of the visible ones. */\nexport const COLUMN_OVERSCAN = 2;\n\n/**\n * A rendered column: the column, the slot its cells and light-DOM content use\n * (`h-{slot}`, `c-{row}-{slot}`), the key its cells are rendered by, and with\n * `virtualizeColumns` the grid track it is placed in.\n */\nexport type RenderedColumn<T> = ColumnView<T, CellContent> & {\n slot: number;\n key: unknown;\n /** Grid column the cells are placed in; `undefined`: in DOM order. */\n place: number | undefined;\n};\n\ntype Column<T> = ColumnView<T, CellContent>;\n\n/**\n * Column virtualization (`virtualizeColumns`): which columns render, and which\n * pool slot's DOM each one uses.\n *\n * Off, every column renders in visual order, its slot is its `colIndex` and\n * its cells are keyed by column id: the DOM is what it always was.\n *\n * On, the scrolling columns in view render, plus `COLUMN_OVERSCAN` on each\n * side, and the pinned columns, the checkbox column and the columns the table\n * keeps (the active one, one being dragged, auto widths still to measure)\n * whatever the scroll position. They are pooled like rows (ADR 0001): a column\n * entering the view reuses the cells, slots and content of one that left, so\n * the DOM is updated in place, and the window has one size, so the pool fills\n * on the first render and scrolling only reuses it (in WebKit, new slots\n * while scrolling cut a wheel scroll short; see `steadyWindow`). DOM order is\n * then pool order: each cell is placed in its grid column explicitly, and\n * `aria-colindex` carries the position, as `aria-rowindex` does for rows.\n */\nexport class ColumnWindowController<T> implements ReactiveController {\n readonly #host: ReactiveControllerHost & HTMLElement;\n readonly #scroller: () => HTMLElement | null;\n readonly #pool = new RowPool();\n #attached: HTMLElement | undefined;\n #resize: ResizeObserver | undefined;\n #enabled = false;\n /** The columns of the last render, and what the window was computed from. */\n #columns: readonly Column<T>[] = [];\n #scrolling: Column<T>[] = [];\n #pinnedWidth = 0;\n #maxVisible: { columns: readonly Column<T>[]; view: number; value: number } | undefined;\n /** First index and size of the last window rendered. */\n #key = '';\n\n constructor(host: ReactiveControllerHost & HTMLElement, scroller: () => HTMLElement | null) {\n this.#host = host;\n this.#scroller = scroller;\n host.addController(this);\n }\n\n hostConnected(): void {\n this.#attach();\n }\n\n hostUpdated(): void {\n this.#attach();\n }\n\n hostDisconnected(): void {\n this.#attached?.removeEventListener('scroll', this.#onScroll);\n this.#resize?.disconnect();\n this.#attached = undefined;\n }\n\n /**\n * The columns to render, given the model's columns in visual order. With\n * `enabled`, `keep` names columns to render wherever they are. Call once per\n * render.\n */\n compute(\n columns: readonly Column<T>[],\n enabled: boolean,\n keep: Iterable<string | undefined>,\n ): RenderedColumn<T>[] {\n this.#enabled = enabled;\n if (!enabled) {\n this.#pool.clear();\n this.#key = '';\n return columns.map((c) => ({ ...c, slot: c.colIndex, key: c.id, place: undefined }));\n }\n if (columns !== this.#columns) {\n this.#columns = columns;\n this.#scrolling = columns.filter((c) => c.kind === 'data' && c.pin === undefined);\n this.#pinnedWidth = columns.reduce((sum, c) => (c.pin ? sum + c.width : sum), 0);\n }\n const wanted = new Set<string | undefined>(keep);\n const window = this.#window();\n for (const i of window) wanted.add(this.#scrolling[i]?.id);\n this.#key = keyOf(window);\n // In visual order, so the first render's slots (and DOM order) follow the columns.\n const ids: string[] = [];\n const byId = new Map<string, Column<T>>();\n for (const c of columns) {\n if (c.pin !== undefined || c.kind !== 'data' || wanted.has(c.id)) {\n ids.push(c.id);\n byId.set(c.id, c);\n }\n }\n const rendered: RenderedColumn<T>[] = [];\n for (const { id, slot } of this.#pool.update(ids)) {\n const c = byId.get(id);\n if (c) rendered.push({ ...c, slot, key: slot, place: c.colIndex });\n }\n return rendered;\n }\n\n /** The window's indexes in the scrolling columns, for the scroller as it is now. */\n #window(): number[] {\n // Before the first render there is no scroller: the host is as wide.\n const s = this.#attached ?? this.#scroller();\n const view = Math.max(0, (s ?? this.#host).clientWidth - this.#pinnedWidth);\n const columns = this.#scrolling;\n let max = this.#maxVisible;\n if (max?.columns !== this.#columns || max.view !== view) {\n max = { columns: this.#columns, view, value: maxVisibleColumns(columns, view) };\n this.#maxVisible = max;\n }\n // Negative in RTL.\n const offset = Math.abs(s?.scrollLeft ?? 0);\n return columnWindow(columns, offset, view, COLUMN_OVERSCAN, max.value);\n }\n\n #attach(): void {\n const s = this.#scroller();\n if (!s || s === this.#attached) return;\n this.#attached?.removeEventListener('scroll', this.#onScroll);\n this.#attached = s;\n s.addEventListener('scroll', this.#onScroll, { passive: true });\n this.#resize ??= new ResizeObserver(() => {\n this.#onScroll();\n });\n this.#resize.disconnect();\n this.#resize.observe(s);\n }\n\n /** Renders again when the window moves: not on every scroll event. */\n readonly #onScroll = () => {\n if (!this.#enabled) return;\n const window = this.#window();\n if (keyOf(window) !== this.#key) this.#host.requestUpdate();\n };\n}\n\nfunction keyOf(window: readonly number[]): string {\n return `${String(window[0] ?? -1)}:${String(window.length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KAAK,MAAM,KAAK,MAAM,cAAc;CAC5D;AACF;AAEA,SAAS,MAAM,QAAmC;CAChD,OAAO,GAAG,OAAO,OAAO,MAAM,EAAE,EAAE,GAAG,OAAO,OAAO,MAAM;AAC3D"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { PageCache } from "../core/src/data/page-cache.js";
|
|
2
2
|
/**
|
|
3
3
|
* Loads `dataSource` pages for the rendered rows (infinite loading). It owns the
|
|
4
|
-
* page cache: a new source, sort order or row id function starts a fresh one, and
|
|
4
|
+
* page cache: a new source, sort order, filter or row id function starts a fresh one, and
|
|
5
5
|
* answers for an old cache are dropped. Requests wait until the range has been
|
|
6
6
|
* quiet for `LOAD_DEBOUNCE_MS`; pages that scrolled away are aborted.
|
|
7
7
|
*/
|
|
@@ -10,6 +10,8 @@ var DataController = class {
|
|
|
10
10
|
#config = {
|
|
11
11
|
source: void 0,
|
|
12
12
|
sorting: [],
|
|
13
|
+
filters: {},
|
|
14
|
+
quickFilter: "",
|
|
13
15
|
getRowId: void 0
|
|
14
16
|
};
|
|
15
17
|
#cache;
|
|
@@ -34,8 +36,9 @@ var DataController = class {
|
|
|
34
36
|
return this.#cache;
|
|
35
37
|
}
|
|
36
38
|
/**
|
|
37
|
-
* Takes the source, sort order and row id function. Any change starts a
|
|
38
|
-
* cache; a sort or row id change keeps the row count (the rows are the same)
|
|
39
|
+
* Takes the source, sort order, filters and row id function. Any change starts a
|
|
40
|
+
* fresh cache; a sort or row id change keeps the row count (the rows are the same),
|
|
41
|
+
* a new source or filter doesn't (the rows aren't).
|
|
39
42
|
*/
|
|
40
43
|
configure(next) {
|
|
41
44
|
const prev = this.#config;
|
|
@@ -44,7 +47,7 @@ var DataController = class {
|
|
|
44
47
|
this.#reset(void 0);
|
|
45
48
|
return;
|
|
46
49
|
}
|
|
47
|
-
if (next.source !== prev.source || !this.#cache) this.#reset({
|
|
50
|
+
if (next.source !== prev.source || !this.#cache || next.filters !== prev.filters || next.quickFilter !== prev.quickFilter) this.#reset({
|
|
48
51
|
rowCount: void 0,
|
|
49
52
|
totalKnown: false
|
|
50
53
|
});
|
|
@@ -147,6 +150,8 @@ var DataController = class {
|
|
|
147
150
|
start,
|
|
148
151
|
end,
|
|
149
152
|
sorting: this.#config.sorting,
|
|
153
|
+
filters: this.#config.filters,
|
|
154
|
+
quickFilter: this.#config.quickFilter,
|
|
150
155
|
signal: controller.signal
|
|
151
156
|
}));
|
|
152
157
|
} catch (error) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data-controller.js","names":[],"sources":["../../src/controllers/data-controller.ts"],"sourcesContent":["import type { ReactiveController, ReactiveControllerHost } from 'lit';\nimport {\n PageCache,\n type DataSource,\n type LoadErrorDetail,\n type RowState,\n type SortState,\n} from '@argus-table/core';\n\n/** Rows per request when the data source sets no `pageSize`. */\nexport const DEFAULT_PAGE_SIZE = 100;\n\n/** Quiet time after the last range change before pages load, so fast scrolling loads only where it stops. */\nexport const LOAD_DEBOUNCE_MS = 50;\n\nexport interface DataConfig<T> {\n source: DataSource<T> | undefined;\n sorting: SortState;\n getRowId: ((row: T, index: number) => string) | undefined;\n}\n\n/**\n * Loads `dataSource` pages for the rendered rows (infinite loading). It owns the\n * page cache: a new source, sort order or row id function starts a fresh one, and\n * answers for an old cache are dropped. Requests wait until the range has been\n * quiet for `LOAD_DEBOUNCE_MS`; pages that scrolled away are aborted.\n */\nexport class DataController<T> implements ReactiveController {\n readonly #host: ReactiveControllerHost;\n #config: DataConfig<T> = { source: undefined, sorting: [], getRowId: undefined };\n #cache: PageCache<T> | undefined;\n readonly #requests = new Map<number, AbortController>();\n #range: { start: number; end: number } | undefined;\n #timer: ReturnType<typeof setTimeout> | undefined;\n #errors: LoadErrorDetail[] = [];\n\n constructor(host: ReactiveControllerHost) {\n this.#host = host;\n host.addController(this);\n }\n\n hostDisconnected(): void {\n clearTimeout(this.#timer);\n this.#timer = undefined;\n this.#abortAll();\n }\n\n hostConnected(): void {\n // Requests aborted on disconnect load again on the next range request.\n this.#range = undefined;\n }\n\n /** The page cache, while a data source is set: the model reads rows from it. */\n get rows(): PageCache<T> | undefined {\n return this.#cache;\n }\n\n /**\n * Takes the source, sort order and row id function. Any change starts a fresh\n * cache; a sort or row id change keeps the row count (the rows are the same).\n */\n configure(next: DataConfig<T>): void {\n const prev = this.#config;\n this.#config = next;\n if (!next.source) {\n this.#reset(undefined);\n return;\n }\n if (next.source !== prev.source || !this.#cache) {\n this.#reset({ rowCount: undefined, totalKnown: false });\n } else if (next.sorting !== prev.sorting || next.getRowId !== prev.getRowId) {\n this.#reset({ rowCount: this.#cache.rowCount, totalKnown: this.#cache.totalKnown });\n }\n }\n\n /** Drops every loaded page and loads the rendered ones again. The row count stays until pages answer. */\n refresh(): void {\n if (!this.#cache) return;\n this.#reset({ rowCount: this.#cache.rowCount, totalKnown: false });\n this.#host.requestUpdate();\n }\n\n stateAt(index: number): RowState {\n return this.#cache?.stateAt(index) ?? 'loaded';\n }\n\n /**\n * The rendered rows, `start` to `end` (exclusive). Loads what's missing once the\n * range has been quiet for a moment. Call after every update.\n */\n request(start: number, end: number): void {\n const cache = this.#cache;\n if (!cache) return;\n const prev = this.#range;\n const moved = prev?.start !== start || prev.end !== end;\n this.#range = { start, end };\n if (moved) {\n clearTimeout(this.#timer);\n } else if (this.#timer !== undefined || cache.missingPages(start, end).length === 0) {\n return;\n }\n this.#timer = setTimeout(() => {\n this.#timer = undefined;\n this.#load();\n }, LOAD_DEBOUNCE_MS);\n }\n\n /** Requests the failed page holding row `index` again (the Retry button, or Enter on a failed row). */\n retry(index: number): void {\n const cache = this.#cache;\n const page = cache?.pageOf(index);\n if (!cache || page === undefined || !cache.isFailed(page)) return;\n cache.retry(page);\n this.#range = undefined;\n this.#host.requestUpdate();\n }\n\n /** Load errors since the last call, to fire as `argus-load-error` after the update. */\n takeErrors(): LoadErrorDetail[] {\n const errors = this.#errors;\n this.#errors = [];\n return errors;\n }\n\n #reset(carry: { rowCount: number | undefined; totalKnown: boolean } | undefined): void {\n clearTimeout(this.#timer);\n this.#timer = undefined;\n this.#abortAll();\n this.#range = undefined;\n this.#errors = [];\n const { source, getRowId } = this.#config;\n this.#cache =\n source && carry\n ? new PageCache<T>({\n pageSize: source.pageSize ?? DEFAULT_PAGE_SIZE,\n getRowId,\n rowCount: carry.rowCount,\n totalKnown: carry.totalKnown,\n })\n : undefined;\n }\n\n #abortAll(): void {\n for (const [page, controller] of this.#requests) {\n controller.abort();\n this.#cache?.cancel(page);\n }\n this.#requests.clear();\n }\n\n #load(): void {\n const cache = this.#cache;\n const range = this.#range;\n if (!cache || !range) return;\n // Keep a page of margin, so a small scroll back doesn't abort a page about to land.\n const margin = cache.pageSize;\n for (const page of cache.inFlightOutside(range.start - margin, range.end + margin)) {\n this.#requests.get(page)?.abort();\n this.#requests.delete(page);\n cache.cancel(page);\n }\n cache.evictOutside(range.start, range.end);\n for (const page of cache.missingPages(range.start, range.end)) this.#fetch(cache, page);\n }\n\n #fetch(cache: PageCache<T>, page: number): void {\n const source = this.#config.source;\n if (!source) return;\n const { start, end } = cache.begin(page);\n const controller = new AbortController();\n this.#requests.set(page, controller);\n const current = () => !controller.signal.aborted && cache === this.#cache;\n let pending: Promise<unknown>;\n try {\n pending = Promise.resolve(\n source.getRows({ start, end, sorting: this.#config.sorting, signal: controller.signal }),\n );\n } catch (error) {\n pending = Promise.reject(error instanceof Error ? error : new Error(String(error)));\n }\n pending\n .then((response) => {\n if (!current()) return;\n const { rows, total } = (response ?? {}) as { rows?: unknown; total?: unknown };\n if (!Array.isArray(rows)) {\n throw new TypeError('argus-table: getRows() must resolve to { rows: [], total? }.');\n }\n this.#requests.delete(page);\n cache.resolve(page, rows as T[], typeof total === 'number' ? total : undefined);\n this.#host.requestUpdate();\n })\n .catch((error: unknown) => {\n if (!current()) return;\n this.#requests.delete(page);\n cache.fail(page);\n this.#errors.push({ error, start, end });\n this.#host.requestUpdate();\n });\n }\n}\n"],"mappings":";;;;;;;AA2BA,IAAa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ller.ts"],"sourcesContent":["import type { ReactiveController, ReactiveControllerHost } from 'lit';\nimport {\n PageCache,\n type ColumnFilterState,\n type DataSource,\n type LoadErrorDetail,\n type RowState,\n type SortState,\n} from '@argus-table/core';\n\n/** Rows per request when the data source sets no `pageSize`. */\nexport const DEFAULT_PAGE_SIZE = 100;\n\n/** Quiet time after the last range change before pages load, so fast scrolling loads only where it stops. */\nexport const LOAD_DEBOUNCE_MS = 50;\n\nexport interface DataConfig<T> {\n source: DataSource<T> | undefined;\n sorting: SortState;\n filters: ColumnFilterState;\n quickFilter: string;\n getRowId: ((row: T, index: number) => string) | undefined;\n}\n\n/**\n * Loads `dataSource` pages for the rendered rows (infinite loading). It owns the\n * page cache: a new source, sort order, filter or row id function starts a fresh one, and\n * answers for an old cache are dropped. Requests wait until the range has been\n * quiet for `LOAD_DEBOUNCE_MS`; pages that scrolled away are aborted.\n */\nexport class DataController<T> implements ReactiveController {\n readonly #host: ReactiveControllerHost;\n #config: DataConfig<T> = {\n source: undefined,\n sorting: [],\n filters: {},\n quickFilter: '',\n getRowId: undefined,\n };\n #cache: PageCache<T> | undefined;\n readonly #requests = new Map<number, AbortController>();\n #range: { start: number; end: number } | undefined;\n #timer: ReturnType<typeof setTimeout> | undefined;\n #errors: LoadErrorDetail[] = [];\n\n constructor(host: ReactiveControllerHost) {\n this.#host = host;\n host.addController(this);\n }\n\n hostDisconnected(): void {\n clearTimeout(this.#timer);\n this.#timer = undefined;\n this.#abortAll();\n }\n\n hostConnected(): void {\n // Requests aborted on disconnect load again on the next range request.\n this.#range = undefined;\n }\n\n /** The page cache, while a data source is set: the model reads rows from it. */\n get rows(): PageCache<T> | undefined {\n return this.#cache;\n }\n\n /**\n * Takes the source, sort order, filters and row id function. Any change starts a\n * fresh cache; a sort or row id change keeps the row count (the rows are the same),\n * a new source or filter doesn't (the rows aren't).\n */\n configure(next: DataConfig<T>): void {\n const prev = this.#config;\n this.#config = next;\n if (!next.source) {\n this.#reset(undefined);\n return;\n }\n if (\n next.source !== prev.source ||\n !this.#cache ||\n next.filters !== prev.filters ||\n next.quickFilter !== prev.quickFilter\n ) {\n this.#reset({ rowCount: undefined, totalKnown: false });\n } else if (next.sorting !== prev.sorting || next.getRowId !== prev.getRowId) {\n this.#reset({ rowCount: this.#cache.rowCount, totalKnown: this.#cache.totalKnown });\n }\n }\n\n /** Drops every loaded page and loads the rendered ones again. The row count stays until pages answer. */\n refresh(): void {\n if (!this.#cache) return;\n this.#reset({ rowCount: this.#cache.rowCount, totalKnown: false });\n this.#host.requestUpdate();\n }\n\n stateAt(index: number): RowState {\n return this.#cache?.stateAt(index) ?? 'loaded';\n }\n\n /**\n * The rendered rows, `start` to `end` (exclusive). Loads what's missing once the\n * range has been quiet for a moment. Call after every update.\n */\n request(start: number, end: number): void {\n const cache = this.#cache;\n if (!cache) return;\n const prev = this.#range;\n const moved = prev?.start !== start || prev.end !== end;\n this.#range = { start, end };\n if (moved) {\n clearTimeout(this.#timer);\n } else if (this.#timer !== undefined || cache.missingPages(start, end).length === 0) {\n return;\n }\n this.#timer = setTimeout(() => {\n this.#timer = undefined;\n this.#load();\n }, LOAD_DEBOUNCE_MS);\n }\n\n /** Requests the failed page holding row `index` again (the Retry button, or Enter on a failed row). */\n retry(index: number): void {\n const cache = this.#cache;\n const page = cache?.pageOf(index);\n if (!cache || page === undefined || !cache.isFailed(page)) return;\n cache.retry(page);\n this.#range = undefined;\n this.#host.requestUpdate();\n }\n\n /** Load errors since the last call, to fire as `argus-load-error` after the update. */\n takeErrors(): LoadErrorDetail[] {\n const errors = this.#errors;\n this.#errors = [];\n return errors;\n }\n\n #reset(carry: { rowCount: number | undefined; totalKnown: boolean } | undefined): void {\n clearTimeout(this.#timer);\n this.#timer = undefined;\n this.#abortAll();\n this.#range = undefined;\n this.#errors = [];\n const { source, getRowId } = this.#config;\n this.#cache =\n source && carry\n ? new PageCache<T>({\n pageSize: source.pageSize ?? DEFAULT_PAGE_SIZE,\n getRowId,\n rowCount: carry.rowCount,\n totalKnown: carry.totalKnown,\n })\n : undefined;\n }\n\n #abortAll(): void {\n for (const [page, controller] of this.#requests) {\n controller.abort();\n this.#cache?.cancel(page);\n }\n this.#requests.clear();\n }\n\n #load(): void {\n const cache = this.#cache;\n const range = this.#range;\n if (!cache || !range) return;\n // Keep a page of margin, so a small scroll back doesn't abort a page about to land.\n const margin = cache.pageSize;\n for (const page of cache.inFlightOutside(range.start - margin, range.end + margin)) {\n this.#requests.get(page)?.abort();\n this.#requests.delete(page);\n cache.cancel(page);\n }\n cache.evictOutside(range.start, range.end);\n for (const page of cache.missingPages(range.start, range.end)) this.#fetch(cache, page);\n }\n\n #fetch(cache: PageCache<T>, page: number): void {\n const source = this.#config.source;\n if (!source) return;\n const { start, end } = cache.begin(page);\n const controller = new AbortController();\n this.#requests.set(page, controller);\n const current = () => !controller.signal.aborted && cache === this.#cache;\n let pending: Promise<unknown>;\n try {\n pending = Promise.resolve(\n source.getRows({\n start,\n end,\n sorting: this.#config.sorting,\n filters: this.#config.filters,\n quickFilter: this.#config.quickFilter,\n signal: controller.signal,\n }),\n );\n } catch (error) {\n pending = Promise.reject(error instanceof Error ? error : new Error(String(error)));\n }\n pending\n .then((response) => {\n if (!current()) return;\n const { rows, total } = (response ?? {}) as { rows?: unknown; total?: unknown };\n if (!Array.isArray(rows)) {\n throw new TypeError('argus-table: getRows() must resolve to { rows: [], total? }.');\n }\n this.#requests.delete(page);\n cache.resolve(page, rows as T[], typeof total === 'number' ? total : undefined);\n this.#host.requestUpdate();\n })\n .catch((error: unknown) => {\n if (!current()) return;\n this.#requests.delete(page);\n cache.fail(page);\n this.#errors.push({ error, start, end });\n this.#host.requestUpdate();\n });\n }\n}\n"],"mappings":";;;;;;;AA8BA,IAAa,iBAAb,MAA6D;CAC3D;CACA,UAAyB;EACvB,QAAQ,KAAA;EACR,SAAS,CAAC;EACV,SAAS,CAAC;EACV,aAAa;EACb,UAAU,KAAA;CACZ;CACA;CACA,4BAAqB,IAAI,IAA6B;CACtD;C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connects them while the table is connected (in
|
|
4
|
+
* array order, cleaning up in reverse), chains their column transforms, and
|
|
5
|
+
* offers keys to them before the table handles them. A hook that throws is
|
|
6
|
+
* reported and skipped, so a broken plugin can't break the update.
|
|
7
|
+
*/
|
|
8
|
+
var PluginController = class {
|
|
9
|
+
#host;
|
|
10
|
+
#api;
|
|
11
|
+
#plugins = [];
|
|
12
|
+
/** Connected plugins and their cleanups. */
|
|
13
|
+
#connected = /* @__PURE__ */ new Map();
|
|
14
|
+
/** Plugins whose `connect` threw: off until `plugins` changes. */
|
|
15
|
+
#failed = /* @__PURE__ */ new Set();
|
|
16
|
+
#version = 0;
|
|
17
|
+
#memo;
|
|
18
|
+
#groupsMemo;
|
|
19
|
+
constructor(host, api) {
|
|
20
|
+
this.#host = host;
|
|
21
|
+
this.#api = api;
|
|
22
|
+
host.addController(this);
|
|
23
|
+
}
|
|
24
|
+
/** Takes a new plugin list; connects and cleans up to match it if the host is connected. */
|
|
25
|
+
set(plugins) {
|
|
26
|
+
if (plugins === this.#plugins) return;
|
|
27
|
+
this.#plugins = plugins;
|
|
28
|
+
this.#failed.clear();
|
|
29
|
+
if (this.#host.isConnected) this.#sync();
|
|
30
|
+
}
|
|
31
|
+
hostConnected() {
|
|
32
|
+
this.#sync();
|
|
33
|
+
}
|
|
34
|
+
hostDisconnected() {
|
|
35
|
+
for (const plugin of [...this.#connected.keys()].reverse()) this.#disconnect(plugin);
|
|
36
|
+
}
|
|
37
|
+
/** Tells the plugins, in order, which properties changed; before the transforms. */
|
|
38
|
+
willUpdate(changed) {
|
|
39
|
+
for (const plugin of this.#plugins) {
|
|
40
|
+
if (!plugin.willUpdate || this.#failed.has(plugin)) continue;
|
|
41
|
+
this.#guard(plugin, "willUpdate", () => {
|
|
42
|
+
plugin.willUpdate?.(changed, this.#api);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/** The plugins' `columns` transforms applied in order; the same array while nothing changed. */
|
|
47
|
+
transform(input) {
|
|
48
|
+
const memo = this.#run("columns", input, this.#memo, (plugin, defs) => plugin.columns?.(defs, this.#api));
|
|
49
|
+
this.#memo = memo;
|
|
50
|
+
return memo.output;
|
|
51
|
+
}
|
|
52
|
+
/** The plugins' `columnGroups` transforms applied in order; the same array while nothing changed. */
|
|
53
|
+
transformGroups(input) {
|
|
54
|
+
const memo = this.#run("columnGroups", input, this.#groupsMemo, (plugin, groups) => plugin.columnGroups?.(groups, this.#api));
|
|
55
|
+
this.#groupsMemo = memo;
|
|
56
|
+
return memo.output;
|
|
57
|
+
}
|
|
58
|
+
#run(hook, input, memo, apply) {
|
|
59
|
+
if (memo?.input === input && memo.plugins === this.#plugins && memo.version === this.#version) return memo;
|
|
60
|
+
let output = input;
|
|
61
|
+
for (const plugin of this.#plugins) {
|
|
62
|
+
if (!plugin[hook] || this.#failed.has(plugin)) continue;
|
|
63
|
+
const before = output;
|
|
64
|
+
const result = this.#guard(plugin, hook, () => apply(plugin, before));
|
|
65
|
+
if (result.ok && result.value) output = result.value;
|
|
66
|
+
}
|
|
67
|
+
if (memo && sameItems(memo.output, output)) output = memo.output;
|
|
68
|
+
return {
|
|
69
|
+
input,
|
|
70
|
+
plugins: this.#plugins,
|
|
71
|
+
version: this.#version,
|
|
72
|
+
output
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
/** Runs the transforms again on the next `transform()`. */
|
|
76
|
+
invalidate() {
|
|
77
|
+
this.#version++;
|
|
78
|
+
}
|
|
79
|
+
/** Offers a key to the plugins in order; `true` once one claims it. */
|
|
80
|
+
keydown(event, target) {
|
|
81
|
+
for (const plugin of this.#plugins) {
|
|
82
|
+
if (!plugin.keydown || this.#failed.has(plugin)) continue;
|
|
83
|
+
const result = this.#guard(plugin, "keydown", () => plugin.keydown?.(event, target, this.#api));
|
|
84
|
+
if (result.ok && result.value === true) return true;
|
|
85
|
+
}
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
#sync() {
|
|
89
|
+
const wanted = new Set(this.#plugins);
|
|
90
|
+
for (const plugin of [...this.#connected.keys()].reverse()) if (!wanted.has(plugin)) this.#disconnect(plugin);
|
|
91
|
+
for (const plugin of this.#plugins) {
|
|
92
|
+
if (this.#connected.has(plugin) || this.#failed.has(plugin)) continue;
|
|
93
|
+
const result = this.#guard(plugin, "connect", () => plugin.connect?.(this.#api));
|
|
94
|
+
if (result.ok) this.#connected.set(plugin, result.value);
|
|
95
|
+
else this.#failed.add(plugin);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
#disconnect(plugin) {
|
|
99
|
+
const cleanup = this.#connected.get(plugin);
|
|
100
|
+
this.#connected.delete(plugin);
|
|
101
|
+
if (cleanup) this.#guard(plugin, "cleanup", cleanup);
|
|
102
|
+
}
|
|
103
|
+
#guard(plugin, hook, run) {
|
|
104
|
+
try {
|
|
105
|
+
return {
|
|
106
|
+
ok: true,
|
|
107
|
+
value: run()
|
|
108
|
+
};
|
|
109
|
+
} catch (error) {
|
|
110
|
+
console.error(`argus-table: plugin "${plugin.name}" threw in ${hook}`, error);
|
|
111
|
+
return { ok: false };
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
/** Whether two lists hold the same items in the same order. */
|
|
116
|
+
function sameItems(a, b) {
|
|
117
|
+
return a.length === b.length && a.every((item, i) => item === b[i]);
|
|
118
|
+
}
|
|
119
|
+
export { PluginController, sameItems };
|
|
120
|
+
|
|
121
|
+
//# sourceMappingURL=plugins.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugins.js","names":[],"sources":["../../src/controllers/plugins.ts"],"sourcesContent":["import type { ReactiveController, ReactiveControllerHost } from 'lit';\nimport type { ArgusPlugin, CellTarget, PluginHost } from '../plugins.js';\nimport type { ColumnDef, ColumnGroup } from '../types.js';\n\ntype Hook = 'connect' | 'cleanup' | 'willUpdate' | 'columns' | 'columnGroups' | 'keydown';\n\ninterface Memo<V> {\n input: readonly V[];\n plugins: readonly unknown[];\n version: number;\n output: readonly V[];\n}\n\n/**\n * Runs the table's plugins: connects them while the table is connected (in\n * array order, cleaning up in reverse), chains their column transforms, and\n * offers keys to them before the table handles them. A hook that throws is\n * reported and skipped, so a broken plugin can't break the update.\n */\nexport class PluginController<T> implements ReactiveController {\n readonly #host: ReactiveControllerHost & HTMLElement;\n readonly #api: PluginHost<T>;\n #plugins: readonly ArgusPlugin<T>[] = [];\n /** Connected plugins and their cleanups. */\n readonly #connected = new Map<ArgusPlugin<T>, (() => void) | undefined>();\n /** Plugins whose `connect` threw: off until `plugins` changes. */\n readonly #failed = new Set<ArgusPlugin<T>>();\n #version = 0;\n #memo: Memo<ColumnDef<T, unknown>> | undefined;\n #groupsMemo: Memo<ColumnGroup<unknown>> | undefined;\n\n constructor(host: ReactiveControllerHost & HTMLElement, api: PluginHost<T>) {\n this.#host = host;\n this.#api = api;\n host.addController(this);\n }\n\n /** Takes a new plugin list; connects and cleans up to match it if the host is connected. */\n set(plugins: readonly ArgusPlugin<T>[]): void {\n if (plugins === this.#plugins) return;\n this.#plugins = plugins;\n this.#failed.clear();\n if (this.#host.isConnected) this.#sync();\n }\n\n hostConnected(): void {\n this.#sync();\n }\n\n hostDisconnected(): void {\n for (const plugin of [...this.#connected.keys()].reverse()) this.#disconnect(plugin);\n }\n\n /** Tells the plugins, in order, which properties changed; before the transforms. */\n willUpdate(changed: ReadonlySet<string>): void {\n for (const plugin of this.#plugins) {\n if (!plugin.willUpdate || this.#failed.has(plugin)) continue;\n this.#guard(plugin, 'willUpdate', () => {\n plugin.willUpdate?.(changed, this.#api);\n });\n }\n }\n\n /** The plugins' `columns` transforms applied in order; the same array while nothing changed. */\n transform(input: readonly ColumnDef<T>[]): readonly ColumnDef<T>[] {\n const memo = this.#run('columns', input, this.#memo, (plugin, defs) =>\n plugin.columns?.(defs, this.#api),\n );\n this.#memo = memo;\n // Plugins see content as `unknown`; what they return renders through the\n // `content()` directive, which hands anything else to the `contentRenderer`.\n return memo.output as readonly ColumnDef<T>[];\n }\n\n /** The plugins' `columnGroups` transforms applied in order; the same array while nothing changed. */\n transformGroups(input: readonly ColumnGroup[]): readonly ColumnGroup[] {\n const memo = this.#run('columnGroups', input, this.#groupsMemo, (plugin, groups) =>\n plugin.columnGroups?.(groups, this.#api),\n );\n this.#groupsMemo = memo;\n return memo.output as readonly ColumnGroup[];\n }\n\n #run<V>(\n hook: 'columns' | 'columnGroups',\n input: readonly V[],\n memo: Memo<V> | undefined,\n apply: (plugin: ArgusPlugin<T>, items: readonly V[]) => readonly V[] | undefined,\n ): Memo<V> {\n if (memo?.input === input && memo.plugins === this.#plugins && memo.version === this.#version) {\n return memo;\n }\n let output = input;\n for (const plugin of this.#plugins) {\n if (!plugin[hook] || this.#failed.has(plugin)) continue;\n const before = output;\n const result = this.#guard(plugin, hook, () => apply(plugin, before));\n if (result.ok && result.value) output = result.value;\n }\n // Plugins may return a fresh array each time: keep the old one when its items are the same.\n if (memo && sameItems(memo.output, output)) output = memo.output;\n return { input, plugins: this.#plugins, version: this.#version, output };\n }\n\n /** Runs the transforms again on the next `transform()`. */\n invalidate(): void {\n this.#version++;\n }\n\n /** Offers a key to the plugins in order; `true` once one claims it. */\n keydown(event: KeyboardEvent, target: CellTarget): boolean {\n for (const plugin of this.#plugins) {\n if (!plugin.keydown || this.#failed.has(plugin)) continue;\n const result = this.#guard(plugin, 'keydown', () =>\n plugin.keydown?.(event, target, this.#api),\n );\n if (result.ok && result.value === true) return true;\n }\n return false;\n }\n\n #sync(): void {\n const wanted = new Set(this.#plugins);\n for (const plugin of [...this.#connected.keys()].reverse()) {\n if (!wanted.has(plugin)) this.#disconnect(plugin);\n }\n for (const plugin of this.#plugins) {\n if (this.#connected.has(plugin) || this.#failed.has(plugin)) continue;\n const result = this.#guard(plugin, 'connect', () => plugin.connect?.(this.#api));\n if (result.ok) this.#connected.set(plugin, result.value);\n else this.#failed.add(plugin);\n }\n }\n\n #disconnect(plugin: ArgusPlugin<T>): void {\n const cleanup = this.#connected.get(plugin);\n this.#connected.delete(plugin);\n if (cleanup) this.#guard(plugin, 'cleanup', cleanup);\n }\n\n #guard<R>(\n plugin: ArgusPlugin<T>,\n hook: Hook,\n run: () => R,\n ): { ok: true; value: R } | { ok: false } {\n try {\n return { ok: true, value: run() };\n } catch (error) {\n console.error(`argus-table: plugin \"${plugin.name}\" threw in ${hook}`, error);\n return { ok: false };\n }\n }\n}\n\n/** Whether two lists hold the same items in the same order. */\nexport function sameItems<V>(a: readonly V[], b: readonly V[]): boolean {\n return a.length === b.length && a.every((item, i) => item === b[i]);\n}\n"],"mappings":";;;;;;;AAmBA,IAAa,mBAAb,MAA+D;CAC7D;CACA;CACA,WAAsC,CAAC;;CAEvC,6BAAsB,IAAI,IAA8C;;CAExE,0BAAmB,IAAI,IAAoB;CAC3C,WAAW;CACX;CACA;CAEA,YAAY,MAA4C,KAAoB;EAC1E,KAAK,QAAQ;EACb,KAAK,OAAO;EACZ,KAAK,cAAc,IAAI;CACzB;;CAGA,IAAI,SAA0C;EAC5C,IAAI,YAAY,KAAK,UAAU;EAC/B,KAAK,WAAW;EAChB,KAAK,QAAQ,MAAM;EACnB,IAAI,KAAK,MAAM,aAAa,KAAK,MAAM;CACzC;CAEA,gBAAsB;EACpB,KAAK,MAAM;CACb;CAEA,mBAAyB;EACvB,KAAK,MAAM,UAAU,CAAC,GAAG,KAAK,WAAW,KAAK,CAAC,CAAC,CAAC,QAAQ,GAAG,KAAK,YAAY,MAAM;CACrF;;CAGA,WAAW,SAAoC;EAC7C,KAAK,MAAM,UAAU,KAAK,UAAU;GAClC,IAAI,CAAC,OAAO,cAAc,KAAK,QAAQ,IAAI,MAAM,GAAG;GACpD,KAAK,OAAO,QAAQ,oBAAoB;IACtC,OAAO,aAAa,SAAS,KAAK,IAAI;GACxC,CAAC;EACH;CACF;;CAGA,UAAU,OAAyD;EACjE,MAAM,OAAO,KAAK,KAAK,WAAW,OAAO,KAAK,QAAQ,QAAQ,SAC5D,OAAO,UAAU,MAAM,KAAK,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AM;EAElD,KAAK,MAAM,UAAU,KAAK,UAAU;GAClC,IAAI,KAAK,WAAW,IAAI,MAAM,KAAK,KAAK,QAAQ,IAAI,MAAM,GAAG;GAC7D,MAAM,SAAS,KAAK,OAAO,QAAQ,iBAAiB,OAAO,UAAU,KAAK,IAAI,CAAC;GAC/E,IAAI,OAAO,IAAI,KAAK,WAAW,IAAI,QAAQ,OAAO,KAAK;QAClD,KAAK,QAAQ,IAAI,MAAM;EAC9B;CACF;CAEA,YAAY,QAA8B;EACxC,MAAM,UAAU,KAAK,WAAW,IAAI,MAAM;EAC1C,KAAK,WAAW,OAAO,MAAM;EAC7B,IAAI,SAAS,KAAK,OAAO,QAAQ,WAAW,OAAO;CACrD;CAEA,OACE,QACA,MACA,KACwC;EACxC,IAAI;GACF,OAAO;IAAE,IAAI;IAAM,OAAO,IAAI;GAAE;EAClC,SAAS,OAAO;GACd,QAAQ,MAAM,wBAAwB,OAAO,KAAK,aAAa,QAAQ,KAAK;GAC5E,OAAO,EAAE,IAAI,MAAM;EACrB;CACF;AACF;;AAGA,SAAgB,UAAa,GAAiB,GAA0B;CACtE,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,OAAO,MAAM,MAAM,SAAS,EAAE,EAAE;AACpE"}
|
|
@@ -1,27 +1,30 @@
|
|
|
1
|
+
import "../interactive.js";
|
|
1
2
|
// src/controllers/reorder-drag.ts
|
|
2
3
|
/**
|
|
3
4
|
* The drop target for a pointer at `x`: the gap between headers nearest to it,
|
|
4
5
|
* decided by each header's midpoint. `undefined` where the column would stay
|
|
5
6
|
* put. `direction` is 1 in LTR and -1 in RTL, where the group runs right to left.
|
|
7
|
+
* The slots needn't be next to each other in the order: with
|
|
8
|
+
* `virtualizeColumns`, headers out of view aren't rendered.
|
|
6
9
|
*/
|
|
7
10
|
function dropTarget(slots, draggedId, x, direction) {
|
|
8
|
-
const
|
|
9
|
-
const first = slots[0];
|
|
11
|
+
const dragged = slots.find((s) => s.id === draggedId);
|
|
10
12
|
const last = slots.at(-1);
|
|
11
|
-
if (
|
|
12
|
-
|
|
13
|
-
if (
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
if (!dragged || !last) return void 0;
|
|
14
|
+
const at = slots.find((s) => (x - (s.rect.left + s.rect.right) / 2) * direction < 0);
|
|
15
|
+
if (!at) {
|
|
16
|
+
const to = last.index >= dragged.index ? last.index : last.index + 1;
|
|
17
|
+
return to === dragged.index ? void 0 : {
|
|
18
|
+
to,
|
|
19
|
+
id: last.id,
|
|
20
|
+
edge: "end"
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
const to = at.index > dragged.index ? at.index - 1 : at.index;
|
|
24
|
+
return to === dragged.index ? void 0 : {
|
|
18
25
|
to,
|
|
19
|
-
|
|
26
|
+
id: at.id,
|
|
20
27
|
edge: "start"
|
|
21
|
-
} : {
|
|
22
|
-
to,
|
|
23
|
-
columnId: last.id,
|
|
24
|
-
edge: "end"
|
|
25
28
|
};
|
|
26
29
|
}
|
|
27
30
|
/** Movement before a press becomes a drag, so a click still sorts. */
|
|
@@ -29,7 +32,6 @@ var THRESHOLD = 4;
|
|
|
29
32
|
/** Width of the band at the scroll area's edges that scrolls, and the top speed there. */
|
|
30
33
|
var EDGE = 40;
|
|
31
34
|
var MAX_SPEED = 16;
|
|
32
|
-
var INTERACTIVE = "button,input,select,textarea,a[href],label,[contenteditable]";
|
|
33
35
|
/**
|
|
34
36
|
* Whether a press on a header may start a reorder drag: the primary button of a
|
|
35
37
|
* mouse or pen (a touch pans the table instead), not on a resize handle, and not
|
|
@@ -41,7 +43,7 @@ function canStartReorder(down, cell) {
|
|
|
41
43
|
if (target === cell) return true;
|
|
42
44
|
if (!(target instanceof Element)) continue;
|
|
43
45
|
if (target instanceof HTMLElement && target.dataset.resizeCol !== void 0) return false;
|
|
44
|
-
if (target.matches(
|
|
46
|
+
if (target.matches("button,input,select,textarea,a[href],label,[contenteditable],[popover],dialog")) return false;
|
|
45
47
|
}
|
|
46
48
|
return false;
|
|
47
49
|
}
|
|
@@ -60,7 +62,7 @@ function startReorderDrag(cell, down, options) {
|
|
|
60
62
|
let dragging = false;
|
|
61
63
|
let frame = 0;
|
|
62
64
|
let target;
|
|
63
|
-
const same = (a, b) => a?.to === b?.to && a?.
|
|
65
|
+
const same = (a, b) => a?.to === b?.to && a?.id === b?.id && a?.edge === b?.edge;
|
|
64
66
|
const tick = () => {
|
|
65
67
|
frame = 0;
|
|
66
68
|
if (!dragging) return;
|