@loadbare/widgets 0.11.1 → 0.13.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/dist/lb-table.browser.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference lib="dom" />
|
|
2
|
-
import { ATTR_COLUMN, ATTR_FILTER, ATTR_GROUP,
|
|
2
|
+
import { ATTR_COLUMN, ATTR_FILTER, ATTR_GROUP, ATTR_QUERY, ATTR_QUERY_ORDER, ATTR_QUERY_UNPLACED_COUNT, ATTR_ROW_REQUESTED, ATTR_SHOW, COMMAND_PLACE, FILTERS_QUERY, LB_EVENT_NAME, LIVE_ROW, ORDER_DESCENDING, REQUEST_ROW_INSERT, REQUEST_ROW_UPDATE, REQUESTED_CREATED, REQUESTED_MOVED, SORT_COLUMN_ORDER, SORT_QUERY, } from "@loadbare/app/constants";
|
|
3
3
|
/**
|
|
4
4
|
* A table that owns its own scaffolding.
|
|
5
5
|
*
|
|
@@ -33,7 +33,7 @@ import { ATTR_COLUMN, ATTR_FILTER, ATTR_GROUP, ATTR_ORDER, ATTR_QUERY, ATTR_QUER
|
|
|
33
33
|
* anywhere else `*=` contains
|
|
34
34
|
*
|
|
35
35
|
* The choice replaces whatever that column held, so a control naming the
|
|
36
|
-
* same column of `lb-
|
|
36
|
+
* same column of `lb-filters` shows it and clears it. The selection is
|
|
37
37
|
* removed once it is used.
|
|
38
38
|
*/
|
|
39
39
|
/**
|
|
@@ -41,18 +41,17 @@ import { ATTR_COLUMN, ATTR_FILTER, ATTR_GROUP, ATTR_ORDER, ATTR_QUERY, ATTR_QUER
|
|
|
41
41
|
* direction, and `aria-sort`. A heading's column is the one `lb-column` in
|
|
42
42
|
* the cell at the same position in the row template, a branch `lb-show`
|
|
43
43
|
* holds in a template included; a cell with none, or with several, gives its
|
|
44
|
-
* heading no column. Only the order's leading term is
|
|
45
|
-
*
|
|
44
|
+
* heading no column. Only the order's leading term is shown. A grouped table
|
|
45
|
+
* shows none of this.
|
|
46
46
|
*
|
|
47
|
-
* While rows stand out of
|
|
48
|
-
* click on its heading places them again with `--lb-
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
* names. A table with no `lb-order` has nowhere to write one.
|
|
47
|
+
* While rows stand out of place the triangle carries `data-unplaced`, and a
|
|
48
|
+
* click on its heading places them again with `--lb-place`. Otherwise a
|
|
49
|
+
* click on the sorted heading reverses the order and a click on another
|
|
50
|
+
* heading sorts by its column, ascending: either way the table writes the
|
|
51
|
+
* order to its query's row of `lb-sort`.
|
|
53
52
|
*/
|
|
54
53
|
const SORT = "data-sort";
|
|
55
|
-
const
|
|
54
|
+
const UNPLACED = "data-unplaced";
|
|
56
55
|
const SORTABLE = "data-sortable";
|
|
57
56
|
/**
|
|
58
57
|
* The ghost row's `<tbody>`, a blank row for entering a new one, between the
|
|
@@ -145,15 +144,14 @@ class LbTable extends HTMLElement {
|
|
|
145
144
|
descending,
|
|
146
145
|
};
|
|
147
146
|
}
|
|
148
|
-
/** Whether rows stand where the order would not
|
|
149
|
-
|
|
150
|
-
const count = this.getAttribute(
|
|
147
|
+
/** Whether rows stand where the order or the filter would not leave them. */
|
|
148
|
+
unplaced() {
|
|
149
|
+
const count = this.getAttribute(ATTR_QUERY_UNPLACED_COUNT);
|
|
151
150
|
return count !== null && count !== "0";
|
|
152
151
|
}
|
|
153
152
|
/** The triangle on the sorted heading, and every heading a click sorts. */
|
|
154
153
|
showOrder() {
|
|
155
154
|
const term = this.leading();
|
|
156
|
-
const writable = this.hasAttribute(ATTR_ORDER);
|
|
157
155
|
for (const [th, column] of this.columns()) {
|
|
158
156
|
const sorted = column === term?.column;
|
|
159
157
|
let mark = th.querySelector(`:scope > [${SORT}]`);
|
|
@@ -165,17 +163,17 @@ class LbTable extends HTMLElement {
|
|
|
165
163
|
th.append(mark);
|
|
166
164
|
}
|
|
167
165
|
mark.textContent = term.descending ? "▼" : "▲";
|
|
168
|
-
mark.toggleAttribute(
|
|
166
|
+
mark.toggleAttribute(UNPLACED, this.unplaced());
|
|
169
167
|
th.setAttribute("aria-sort", term.descending ? "descending" : "ascending");
|
|
170
168
|
}
|
|
171
169
|
else {
|
|
172
170
|
mark?.remove();
|
|
173
171
|
th.removeAttribute("aria-sort");
|
|
174
172
|
}
|
|
175
|
-
th.toggleAttribute(SORTABLE,
|
|
173
|
+
th.toggleAttribute(SORTABLE, true);
|
|
176
174
|
}
|
|
177
175
|
}
|
|
178
|
-
/** A click on a heading:
|
|
176
|
+
/** A click on a heading: place the rows, reverse, or sort by its column. */
|
|
179
177
|
sortFromHeading(e) {
|
|
180
178
|
const th = e.target.closest("th");
|
|
181
179
|
const column = th && this.columns().get(th);
|
|
@@ -183,20 +181,20 @@ class LbTable extends HTMLElement {
|
|
|
183
181
|
return;
|
|
184
182
|
const term = this.leading();
|
|
185
183
|
const sorted = column === term?.column;
|
|
186
|
-
if (sorted && this.
|
|
184
|
+
if (sorted && this.unplaced()) {
|
|
187
185
|
const command = new Event("command");
|
|
188
|
-
Object.defineProperty(command, "command", { value:
|
|
186
|
+
Object.defineProperty(command, "command", { value: COMMAND_PLACE });
|
|
189
187
|
this.dispatchEvent(command);
|
|
190
188
|
return;
|
|
191
189
|
}
|
|
192
|
-
const choice = this.getAttribute(ATTR_ORDER);
|
|
193
|
-
if (!choice)
|
|
194
|
-
return;
|
|
195
190
|
const descending = sorted && !term.descending;
|
|
196
191
|
const detail = {
|
|
197
192
|
name: REQUEST_ROW_UPDATE,
|
|
198
|
-
query:
|
|
199
|
-
|
|
193
|
+
query: SORT_QUERY,
|
|
194
|
+
key: this.getAttribute(ATTR_QUERY),
|
|
195
|
+
values: {
|
|
196
|
+
[SORT_COLUMN_ORDER]: (descending ? ORDER_DESCENDING : "") + column,
|
|
197
|
+
},
|
|
200
198
|
};
|
|
201
199
|
this.dispatchEvent(new CustomEvent(LB_EVENT_NAME, { bubbles: true, detail }));
|
|
202
200
|
}
|
|
@@ -230,7 +228,8 @@ class LbTable extends HTMLElement {
|
|
|
230
228
|
selection.removeAllRanges();
|
|
231
229
|
const detail = {
|
|
232
230
|
name: REQUEST_ROW_UPDATE,
|
|
233
|
-
query:
|
|
231
|
+
query: FILTERS_QUERY,
|
|
232
|
+
key: this.getAttribute(ATTR_QUERY),
|
|
234
233
|
values: { [column]: term },
|
|
235
234
|
};
|
|
236
235
|
this.dispatchEvent(new CustomEvent(LB_EVENT_NAME, { bubbles: true, detail }));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lb-table.browser.js","sourceRoot":"","sources":["../widgets/lb-table.browser.ts"],"names":[],"mappings":"AAAA,2BAA2B;AAE3B,OAAO,EACL,WAAW,EACX,WAAW,EACX,UAAU,EACV,UAAU,EACV,UAAU,EACV,gBAAgB,EAChB,yBAAyB,EACzB,kBAAkB,EAClB,SAAS,EACT,aAAa,EACb,YAAY,EACZ,aAAa,EACb,QAAQ,EACR,gBAAgB,EAChB,kBAAkB,EAClB,kBAAkB,EAClB,iBAAiB,EACjB,eAAe,GAChB,MAAM,yBAAyB,CAAC;AAOjC;;;;;;;;;;;;;;;;;;;GAmBG;AAEH;;;;;;;;;;;;;;;GAeG;AAEH;;;;;;;;;;;;;;GAcG;AACH,MAAM,IAAI,GAAG,WAAW,CAAC;AACzB,MAAM,QAAQ,GAAG,eAAe,CAAC;AACjC,MAAM,QAAQ,GAAG,eAAe,CAAC;AAEjC;;;;;;;;;;;;GAYG;AACH,MAAM,KAAK,GAAG,YAAY,CAAC;AAE3B,iFAAiF;AACjF,IAAI,UAAU,GAAG,CAAC,CAAC;AAEnB,MAAM,OAAQ,SAAQ,WAAW;IAC/B;QACE,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,gBAAgB,CAAC,SAAS,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,iBAAiB,EAAE,CAAC,CAAC;QACjE,IAAI,CAAC,gBAAgB,CAAC,OAAO,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,IA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R_QUERY_ORDER,\n ATTR_QUERY_UNSORTED_COUNT,\n ATTR_ROW_REQUESTED,\n ATTR_SHOW,\n CHOICES_QUERY,\n COMMAND_SORT,\n LB_EVENT_NAME,\n LIVE_ROW,\n ORDER_DESCENDING,\n REQUEST_ROW_INSERT,\n REQUEST_ROW_UPDATE,\n REQUESTED_CREATED,\n REQUESTED_MOVED,\n} from \"@loadbare/app/constants\";\nimport type {\n HubLifecycle,\n HubRequest,\n HubRequestDone,\n} from \"@loadbare/app/types\";\n\n/**\n * A table that owns its own scaffolding.\n *\n * A plain `<table lb-query>` with a row template inside it needs no widget at\n * all. This one supplies the table, and the developer writes what only the\n * page knows: the heading row and the row template. That division is forced\n * rather than chosen — a `<thead>` written inside a custom element is not\n * inside a table, so the parser drops the tag and keeps the text. A\n * `<template>` survives anywhere, so the heading row arrives wrapped and\n * expansion unwraps it into the `lb-exp-template` destination beside the slot.\n *\n * Placement and groups are the hub's, by the query's order and the page's\n * group templates. What this widget adds at run time is the ghost row,\n * scrolling to the row the page's own request created or moved, filtering\n * by selected text, and the order shown on the heading.\n *\n * The `foot` destination needs no code here. A `<tfoot>` is a place on the\n * page, not a row the hub delivers, so what lands in it is an aggregate or a\n * `row` query of its own, named on its `<tr>`.\n */\n\n/**\n * Text selected in a cell filters the table by that cell's column. When a\n * selection finishes inside one element of a live row whose `lb-column` the\n * table's `lb-filter` names, the table makes the choice of that name, and the\n * hub hides the rows it does not pass. Where the selection lies in the\n * element's text says how:\n *\n * the whole text `=` equals\n * from its start `^=` begins with\n * up to its end `$=` ends with\n * anywhere else `*=` contains\n *\n * The choice replaces whatever that column held, so a control naming the\n * same column of `lb-choices` shows it and clears it. The selection is\n * removed once it is used.\n */\n\n/**\n * The heading of the column the rows are sorted by carries a triangle for the\n * direction, and `aria-sort`. A heading's column is the one `lb-column` in\n * the cell at the same position in the row template, a branch `lb-show`\n * holds in a template included; a cell with none, or with several, gives its\n * heading no column. Only the order's leading term is\n * shown. A grouped table shows none of this.\n *\n * While rows stand out of order the triangle carries `data-unsorted`, and a\n * click on its heading places them again with `--lb-sort`. Otherwise, on a\n * table with `lb-order`, a click on the sorted heading reverses the order and\n * a click on another heading sorts by its column, ascending: either way the\n * table writes the user's order to the column of `lb-choices` that `lb-order`\n * names. A table with no `lb-order` has nowhere to write one.\n */\nconst SORT = \"data-sort\";\nconst UNSORTED = \"data-unsorted\";\nconst SORTABLE = \"data-sortable\";\n\n/**\n * The ghost row's `<tbody>`, a blank row for entering a new one, between the\n * rows and the footer. The page writes it as the `ghost` template, so it\n * ships in the document like the heading and the footer, and the hub lands\n * on whatever in it names a query. It is not a live row: the hub never\n * reconciles it and never counts it.\n *\n * A `<form>` cannot wrap a `<tr>`, so the widget makes one outside the table\n * and joins the row's controls and buttons to it with the HTML `form`\n * attribute. Sending is the page's: a button in the row carrying\n * `lb-row-insert` submits that form, and the hub gathers what the form owns.\n * The hub resets the form once the insert succeeds.\n */\nconst GHOST = \"data-ghost\";\n\n/** Ghost row forms need ids for the `form` attribute; any unique one will do. */\nlet ghostForms = 0;\n\nclass LbTable extends HTMLElement implements HubLifecycle {\n constructor() {\n super();\n this.addEventListener(\"mouseup\", () => this.filterBySelection());\n this.addEventListener(\"click\", (e) => this.sortFromHeading(e));\n }\n\n /** Each heading's column, by position in the row template; none when grouped. */\n private headings?: Map<Element, string>;\n\n lbAttached(): void {\n const ghost = this.querySelector(`tbody[${GHOST}]`);\n if (!ghost?.firstElementChild) return;\n\n const form = document.createElement(\"form\");\n form.id = `ghost-row-${++ghostForms}`;\n form.hidden = true;\n this.append(form);\n for (const el of ghost.querySelectorAll(`[${ATTR_COLUMN}], button`)) {\n el.setAttribute(\"form\", form.id);\n }\n }\n\n /** The row this page's request created or moved, brought into view. */\n lbRowsLanded(): void {\n this.showOrder();\n this.querySelector(\n `[${ATTR_ROW_REQUESTED}=\"${REQUESTED_CREATED}\"], ` +\n `[${ATTR_ROW_REQUESTED}=\"${REQUESTED_MOVED}\"]`,\n )?.scrollIntoView({ block: \"nearest\" });\n }\n\n /**\n * A ghost row is for entering the next row, so once one is saved the\n * cursor goes back to the start of it. The hub calls this after the\n * response items have landed, so nothing it places afterwards takes the\n * focus away again. A refused insert leaves the cursor where the user left\n * it.\n */\n lbRequestDone({ request, error }: HubRequestDone, origin: Element): void {\n if (error || request.name !== REQUEST_ROW_INSERT) return;\n const row = origin.closest(`[${GHOST}]`);\n if (row) firstControl(row)?.focus();\n }\n\n /** The headings a column can be read for, and their columns. */\n private columns(): Map<Element, string> {\n if (this.headings) return this.headings;\n this.headings = new Map();\n const body = this.querySelector(`tbody:not([${GHOST}])`);\n const template = body?.querySelector(\":scope > template\");\n const head = this.querySelector(\"thead tr\");\n if (!(template instanceof HTMLTemplateElement) || !head) {\n return this.headings;\n }\n if (template.hasAttribute(ATTR_GROUP)) return this.headings;\n const cells = template.content.querySelector(\"tr\")?.children ?? [];\n [...head.children].forEach((th, i) => {\n const cell = cells[i];\n if (!cell) return;\n const named = new Set(columnsIn(cell));\n if (named.size === 1) this.headings!.set(th, [...named][0]!);\n });\n return this.headings;\n }\n\n /** The order's leading term, from what the hub stamped. */\n private leading(): { column: string; descending: boolean } | undefined {\n const term = (this.getAttribute(ATTR_QUERY_ORDER) ?? \"\").split(\",\")[0];\n if (!term) return undefined;\n const descending = term.startsWith(ORDER_DESCENDING);\n return {\n column: descending ? term.slice(ORDER_DESCENDING.length) : term,\n descending,\n };\n }\n\n /** Whether rows stand where the order would not put them. */\n private unsorted(): boolean {\n const count = this.getAttribute(ATTR_QUERY_UNSORTED_COUNT);\n return count !== null && count !== \"0\";\n }\n\n /** The triangle on the sorted heading, and every heading a click sorts. */\n private showOrder(): void {\n const term = this.leading();\n const writable = this.hasAttribute(ATTR_ORDER);\n for (const [th, column] of this.columns()) {\n const sorted = column === term?.column;\n let mark = th.querySelector(`:scope > [${SORT}]`);\n if (sorted) {\n if (!mark) {\n mark = document.createElement(\"span\");\n mark.setAttribute(SORT, \"\");\n mark.setAttribute(\"aria-hidden\", \"true\");\n th.append(mark);\n }\n mark.textContent = term.descending ? \"▼\" : \"▲\";\n mark.toggleAttribute(UNSORTED, this.unsorted());\n th.setAttribute(\"aria-sort\", term.descending ? \"descending\" : \"ascending\");\n } else {\n mark?.remove();\n th.removeAttribute(\"aria-sort\");\n }\n th.toggleAttribute(SORTABLE, writable || (sorted && this.unsorted()));\n }\n }\n\n /** A click on a heading: re-sort, reverse, or sort by its column. */\n private sortFromHeading(e: Event): void {\n const th = (e.target as Element).closest(\"th\");\n const column = th && this.columns().get(th);\n if (!column) return;\n const term = this.leading();\n const sorted = column === term?.column;\n if (sorted && this.unsorted()) {\n const command = new Event(\"command\");\n Object.defineProperty(command, \"command\", { value: COMMAND_SORT });\n this.dispatchEvent(command);\n return;\n }\n const choice = this.getAttribute(ATTR_ORDER);\n if (!choice) return;\n const descending = sorted && !term.descending;\n const detail: HubRequest = {\n name: REQUEST_ROW_UPDATE,\n query: CHOICES_QUERY,\n values: { [choice]: (descending ? ORDER_DESCENDING : \"\") + column },\n };\n this.dispatchEvent(\n new CustomEvent(LB_EVENT_NAME, { bubbles: true, detail }),\n );\n }\n\n /** The columns of this table's rows a choice may filter. */\n private filtered(): string[] {\n return (this.getAttribute(ATTR_FILTER) ?? \"\")\n .split(\",\")\n .map((column) => column.trim())\n .filter(Boolean);\n }\n\n /** A finished selection in one filtered cell, made a choice. */\n private filterBySelection(): void {\n const selection = getSelection();\n if (!selection || selection.isCollapsed || selection.rangeCount === 0) {\n return;\n }\n const range = selection.getRangeAt(0);\n const start = range.startContainer;\n const el = (\n start instanceof Element ? start : start.parentElement\n )?.closest(`[${ATTR_COLUMN}]`);\n if (!el || !el.contains(range.endContainer)) return;\n const row = el.closest(LIVE_ROW);\n if (!row || row.closest(\"lb-table\") !== this) return;\n const column = el.getAttribute(ATTR_COLUMN)!;\n if (!this.filtered().includes(column)) return;\n\n const term = termFor(\n selection.toString().trim(),\n (el.textContent ?? \"\").trim(),\n );\n if (term === null) return;\n selection.removeAllRanges();\n const detail: HubRequest = {\n name: REQUEST_ROW_UPDATE,\n query: CHOICES_QUERY,\n values: { [column]: term },\n };\n this.dispatchEvent(\n new CustomEvent(LB_EVENT_NAME, { bubbles: true, detail }),\n );\n }\n}\n\n/**\n * The columns an element and everything in it show, read as the hub reads a\n * row: into a branch an `lb-show` holds in a template, but not into another\n * template, nor past an element naming a query of its own.\n */\nfunction columnsIn(el: Element): string[] {\n const own = el.getAttribute(ATTR_COLUMN);\n const out = own ? [own] : [];\n if (el.hasAttribute(ATTR_QUERY)) return out;\n const children =\n el instanceof HTMLTemplateElement\n ? el.hasAttribute(ATTR_SHOW)\n ? [...el.content.children]\n : []\n : [...el.children];\n for (const child of children) out.push(...columnsIn(child));\n return out;\n}\n\n/** A filter's term for text selected from a cell's whole text. */\nfunction termFor(selected: string, whole: string): string | null {\n if (selected === \"\") return null;\n if (selected === whole) return `=${selected}`;\n if (whole.startsWith(selected)) return `^=${selected}`;\n if (whole.endsWith(selected)) return `$=${selected}`;\n return `*=${selected}`;\n}\n\n/**\n * The first control in a row the user can type into or choose from. A\n * control a widget wraps is found inside it, since the wrapper takes no focus.\n */\nfunction firstControl(row: Element): HTMLElement | undefined {\n return [\n ...row.querySelectorAll<HTMLElement>(\n 'input:not([type=\"hidden\"]), select, textarea',\n ),\n ].find((el) => !el.matches(\":disabled\") && el.checkVisibility?.() !== false);\n}\n\ncustomElements.define(\"lb-table\", LbTable);\n"]}
|
|
1
|
+
{"version":3,"file":"lb-table.browser.js","sourceRoot":"","sources":["../widgets/lb-table.browser.ts"],"names":[],"mappings":"AAAA,2BAA2B;AAE3B,OAAO,EACL,WAAW,EACX,WAAW,EACX,UAAU,EACV,UAAU,EACV,gBAAgB,EAChB,yBAAyB,EACzB,kBAAkB,EAClB,SAAS,EACT,aAAa,EACb,aAAa,EACb,aAAa,EACb,QAAQ,EACR,gBAAgB,EAChB,kBAAkB,EAClB,kBAAkB,EAClB,iBAAiB,EACjB,eAAe,EACf,iBAAiB,EACjB,UAA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AACzB,CAAC;AAED;;;GAGG;AACH,SAAS,YAAY,CAAC,GAAY;IAChC,OAAO;QACL,GAAG,GAAG,CAAC,gBAAgB,CACrB,8CAA8C,CAC/C;KACF,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC,eAAe,EAAE,EAAE,KAAK,KAAK,CAAC,CAAC;AAC/E,CAAC;AAED,cAAc,CAAC,MAAM,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC","sourcesContent":["/// <reference lib=\"dom\" />\n\nimport {\n ATTR_COLUMN,\n ATTR_FILTER,\n ATTR_GROUP,\n ATTR_QUERY,\n ATTR_QUERY_ORDER,\n ATTR_QUERY_UNPLACED_COUNT,\n ATTR_ROW_REQUESTED,\n ATTR_SHOW,\n COMMAND_PLACE,\n FILTERS_QUERY,\n LB_EVENT_NAME,\n LIVE_ROW,\n ORDER_DESCENDING,\n REQUEST_ROW_INSERT,\n REQUEST_ROW_UPDATE,\n REQUESTED_CREATED,\n REQUESTED_MOVED,\n SORT_COLUMN_ORDER,\n SORT_QUERY,\n} from \"@loadbare/app/constants\";\nimport type {\n HubLifecycle,\n HubRequest,\n HubRequestDone,\n} from \"@loadbare/app/types\";\n\n/**\n * A table that owns its own scaffolding.\n *\n * A plain `<table lb-query>` with a row template inside it needs no widget at\n * all. This one supplies the table, and the developer writes what only the\n * page knows: the heading row and the row template. That division is forced\n * rather than chosen — a `<thead>` written inside a custom element is not\n * inside a table, so the parser drops the tag and keeps the text. A\n * `<template>` survives anywhere, so the heading row arrives wrapped and\n * expansion unwraps it into the `lb-exp-template` destination beside the slot.\n *\n * Placement and groups are the hub's, by the query's order and the page's\n * group templates. What this widget adds at run time is the ghost row,\n * scrolling to the row the page's own request created or moved, filtering\n * by selected text, and the order shown on the heading.\n *\n * The `foot` destination needs no code here. A `<tfoot>` is a place on the\n * page, not a row the hub delivers, so what lands in it is an aggregate or a\n * `row` query of its own, named on its `<tr>`.\n */\n\n/**\n * Text selected in a cell filters the table by that cell's column. When a\n * selection finishes inside one element of a live row whose `lb-column` the\n * table's `lb-filter` names, the table makes the choice of that name, and the\n * hub hides the rows it does not pass. Where the selection lies in the\n * element's text says how:\n *\n * the whole text `=` equals\n * from its start `^=` begins with\n * up to its end `$=` ends with\n * anywhere else `*=` contains\n *\n * The choice replaces whatever that column held, so a control naming the\n * same column of `lb-filters` shows it and clears it. The selection is\n * removed once it is used.\n */\n\n/**\n * The heading of the column the rows are sorted by carries a triangle for the\n * direction, and `aria-sort`. A heading's column is the one `lb-column` in\n * the cell at the same position in the row template, a branch `lb-show`\n * holds in a template included; a cell with none, or with several, gives its\n * heading no column. Only the order's leading term is shown. A grouped table\n * shows none of this.\n *\n * While rows stand out of place the triangle carries `data-unplaced`, and a\n * click on its heading places them again with `--lb-place`. Otherwise a\n * click on the sorted heading reverses the order and a click on another\n * heading sorts by its column, ascending: either way the table writes the\n * order to its query's row of `lb-sort`.\n */\nconst SORT = \"data-sort\";\nconst UNPLACED = \"data-unplaced\";\nconst SORTABLE = \"data-sortable\";\n\n/**\n * The ghost row's `<tbody>`, a blank row for entering a new one, between the\n * rows and the footer. The page writes it as the `ghost` template, so it\n * ships in the document like the heading and the footer, and the hub lands\n * on whatever in it names a query. It is not a live row: the hub never\n * reconciles it and never counts it.\n *\n * A `<form>` cannot wrap a `<tr>`, so the widget makes one outside the table\n * and joins the row's controls and buttons to it with the HTML `form`\n * attribute. Sending is the page's: a button in the row carrying\n * `lb-row-insert` submits that form, and the hub gathers what the form owns.\n * The hub resets the form once the insert succeeds.\n */\nconst GHOST = \"data-ghost\";\n\n/** Ghost row forms need ids for the `form` attribute; any unique one will do. */\nlet ghostForms = 0;\n\nclass LbTable extends HTMLElement implements HubLifecycle {\n constructor() {\n super();\n this.addEventListener(\"mouseup\", () => this.filterBySelection());\n this.addEventListener(\"click\", (e) => this.sortFromHeading(e));\n }\n\n /** Each heading's column, by position in the row template; none when grouped. */\n private headings?: Map<Element, string>;\n\n lbAttached(): void {\n const ghost = this.querySelector(`tbody[${GHOST}]`);\n if (!ghost?.firstElementChild) return;\n\n const form = document.createElement(\"form\");\n form.id = `ghost-row-${++ghostForms}`;\n form.hidden = true;\n this.append(form);\n for (const el of ghost.querySelectorAll(`[${ATTR_COLUMN}], button`)) {\n el.setAttribute(\"form\", form.id);\n }\n }\n\n /** The row this page's request created or moved, brought into view. */\n lbRowsLanded(): void {\n this.showOrder();\n this.querySelector(\n `[${ATTR_ROW_REQUESTED}=\"${REQUESTED_CREATED}\"], ` +\n `[${ATTR_ROW_REQUESTED}=\"${REQUESTED_MOVED}\"]`,\n )?.scrollIntoView({ block: \"nearest\" });\n }\n\n /**\n * A ghost row is for entering the next row, so once one is saved the\n * cursor goes back to the start of it. The hub calls this after the\n * response items have landed, so nothing it places afterwards takes the\n * focus away again. A refused insert leaves the cursor where the user left\n * it.\n */\n lbRequestDone({ request, error }: HubRequestDone, origin: Element): void {\n if (error || request.name !== REQUEST_ROW_INSERT) return;\n const row = origin.closest(`[${GHOST}]`);\n if (row) firstControl(row)?.focus();\n }\n\n /** The headings a column can be read for, and their columns. */\n private columns(): Map<Element, string> {\n if (this.headings) return this.headings;\n this.headings = new Map();\n const body = this.querySelector(`tbody:not([${GHOST}])`);\n const template = body?.querySelector(\":scope > template\");\n const head = this.querySelector(\"thead tr\");\n if (!(template instanceof HTMLTemplateElement) || !head) {\n return this.headings;\n }\n if (template.hasAttribute(ATTR_GROUP)) return this.headings;\n const cells = template.content.querySelector(\"tr\")?.children ?? [];\n [...head.children].forEach((th, i) => {\n const cell = cells[i];\n if (!cell) return;\n const named = new Set(columnsIn(cell));\n if (named.size === 1) this.headings!.set(th, [...named][0]!);\n });\n return this.headings;\n }\n\n /** The order's leading term, from what the hub stamped. */\n private leading(): { column: string; descending: boolean } | undefined {\n const term = (this.getAttribute(ATTR_QUERY_ORDER) ?? \"\").split(\",\")[0];\n if (!term) return undefined;\n const descending = term.startsWith(ORDER_DESCENDING);\n return {\n column: descending ? term.slice(ORDER_DESCENDING.length) : term,\n descending,\n };\n }\n\n /** Whether rows stand where the order or the filter would not leave them. */\n private unplaced(): boolean {\n const count = this.getAttribute(ATTR_QUERY_UNPLACED_COUNT);\n return count !== null && count !== \"0\";\n }\n\n /** The triangle on the sorted heading, and every heading a click sorts. */\n private showOrder(): void {\n const term = this.leading();\n for (const [th, column] of this.columns()) {\n const sorted = column === term?.column;\n let mark = th.querySelector(`:scope > [${SORT}]`);\n if (sorted) {\n if (!mark) {\n mark = document.createElement(\"span\");\n mark.setAttribute(SORT, \"\");\n mark.setAttribute(\"aria-hidden\", \"true\");\n th.append(mark);\n }\n mark.textContent = term.descending ? \"▼\" : \"▲\";\n mark.toggleAttribute(UNPLACED, this.unplaced());\n th.setAttribute(\"aria-sort\", term.descending ? \"descending\" : \"ascending\");\n } else {\n mark?.remove();\n th.removeAttribute(\"aria-sort\");\n }\n th.toggleAttribute(SORTABLE, true);\n }\n }\n\n /** A click on a heading: place the rows, reverse, or sort by its column. */\n private sortFromHeading(e: Event): void {\n const th = (e.target as Element).closest(\"th\");\n const column = th && this.columns().get(th);\n if (!column) return;\n const term = this.leading();\n const sorted = column === term?.column;\n if (sorted && this.unplaced()) {\n const command = new Event(\"command\");\n Object.defineProperty(command, \"command\", { value: COMMAND_PLACE });\n this.dispatchEvent(command);\n return;\n }\n const descending = sorted && !term.descending;\n const detail: HubRequest = {\n name: REQUEST_ROW_UPDATE,\n query: SORT_QUERY,\n key: this.getAttribute(ATTR_QUERY)!,\n values: {\n [SORT_COLUMN_ORDER]: (descending ? ORDER_DESCENDING : \"\") + column,\n },\n };\n this.dispatchEvent(\n new CustomEvent(LB_EVENT_NAME, { bubbles: true, detail }),\n );\n }\n\n /** The columns of this table's rows a choice may filter. */\n private filtered(): string[] {\n return (this.getAttribute(ATTR_FILTER) ?? \"\")\n .split(\",\")\n .map((column) => column.trim())\n .filter(Boolean);\n }\n\n /** A finished selection in one filtered cell, made a choice. */\n private filterBySelection(): void {\n const selection = getSelection();\n if (!selection || selection.isCollapsed || selection.rangeCount === 0) {\n return;\n }\n const range = selection.getRangeAt(0);\n const start = range.startContainer;\n const el = (\n start instanceof Element ? start : start.parentElement\n )?.closest(`[${ATTR_COLUMN}]`);\n if (!el || !el.contains(range.endContainer)) return;\n const row = el.closest(LIVE_ROW);\n if (!row || row.closest(\"lb-table\") !== this) return;\n const column = el.getAttribute(ATTR_COLUMN)!;\n if (!this.filtered().includes(column)) return;\n\n const term = termFor(\n selection.toString().trim(),\n (el.textContent ?? \"\").trim(),\n );\n if (term === null) return;\n selection.removeAllRanges();\n const detail: HubRequest = {\n name: REQUEST_ROW_UPDATE,\n query: FILTERS_QUERY,\n key: this.getAttribute(ATTR_QUERY)!,\n values: { [column]: term },\n };\n this.dispatchEvent(\n new CustomEvent(LB_EVENT_NAME, { bubbles: true, detail }),\n );\n }\n}\n\n/**\n * The columns an element and everything in it show, read as the hub reads a\n * row: into a branch an `lb-show` holds in a template, but not into another\n * template, nor past an element naming a query of its own.\n */\nfunction columnsIn(el: Element): string[] {\n const own = el.getAttribute(ATTR_COLUMN);\n const out = own ? [own] : [];\n if (el.hasAttribute(ATTR_QUERY)) return out;\n const children =\n el instanceof HTMLTemplateElement\n ? el.hasAttribute(ATTR_SHOW)\n ? [...el.content.children]\n : []\n : [...el.children];\n for (const child of children) out.push(...columnsIn(child));\n return out;\n}\n\n/** A filter's term for text selected from a cell's whole text. */\nfunction termFor(selected: string, whole: string): string | null {\n if (selected === \"\") return null;\n if (selected === whole) return `=${selected}`;\n if (whole.startsWith(selected)) return `^=${selected}`;\n if (whole.endsWith(selected)) return `$=${selected}`;\n return `*=${selected}`;\n}\n\n/**\n * The first control in a row the user can type into or choose from. A\n * control a widget wraps is found inside it, since the wrapper takes no focus.\n */\nfunction firstControl(row: Element): HTMLElement | undefined {\n return [\n ...row.querySelectorAll<HTMLElement>(\n 'input:not([type=\"hidden\"]), select, textarea',\n ),\n ].find((el) => !el.matches(\":disabled\") && el.checkVisibility?.() !== false);\n}\n\ncustomElements.define(\"lb-table\", LbTable);\n"]}
|
package/dist/lb-table.css
CHANGED
|
@@ -15,11 +15,11 @@ lb-table th > [data-sort] {
|
|
|
15
15
|
line-height: 1.3;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
lb-table th > [data-sort][data-
|
|
18
|
+
lb-table th > [data-sort][data-unplaced] {
|
|
19
19
|
color: #b58900;
|
|
20
20
|
border-color: currentColor;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
lb-table tr[lb-row-
|
|
23
|
+
lb-table tr[lb-row-unplaced] > :first-child {
|
|
24
24
|
box-shadow: inset 3px 0 0 #b58900;
|
|
25
25
|
}
|
package/docs/lb-table.md
CHANGED
|
@@ -23,7 +23,7 @@ Provide `exp-caption`.
|
|
|
23
23
|
</template>
|
|
24
24
|
</template>
|
|
25
25
|
<template lb-exp-template="foot">
|
|
26
|
-
<tr><td>Total</td><td lb-sum="amount"></td></tr>
|
|
26
|
+
<tr><td>Total</td><td lb-aggregate="sum" lb-column="amount"></td></tr>
|
|
27
27
|
</template>
|
|
28
28
|
</lb-table>
|
|
29
29
|
```
|
|
@@ -50,23 +50,25 @@ improvements through iterative use.
|
|
|
50
50
|
| `lb-group` | a template holding the row template | a group, one per run of the order's leading term |
|
|
51
51
|
| `lb-order` | the element itself | the choice holding the user's order |
|
|
52
52
|
| `lb-filter` | the element itself | the columns the user's choices filter |
|
|
53
|
+
| `lb-manual` | the element itself | `order`, `filter` or both: what an answer leaves where it stands |
|
|
53
54
|
| `lb-column` | elements inside the row template | the column each element shows |
|
|
54
55
|
|
|
55
56
|
The server declares the query's key and its order.
|
|
56
57
|
|
|
57
58
|
## Order and groups
|
|
58
59
|
|
|
59
|
-
The hub places the rows by the query's order and builds its groups.
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
60
|
+
The hub places the rows by the query's order and builds its groups. A
|
|
61
|
+
table edited in its rows or its ghost row usually carries
|
|
62
|
+
`lb-manual="order"`, so an edited row stays where it stands and a new one
|
|
63
|
+
goes last until the user asks for the order; a button with `commandfor`
|
|
64
|
+
naming the table's `id` and `command="--lb-place"` does that.
|
|
63
65
|
The rows land in the table's one `<tbody>`, and a `<tbody>` cannot hold another,
|
|
64
66
|
so a group here is a heading row with its rows after it. For a `<tbody>` per
|
|
65
67
|
group, write a plain `<table lb-query>` whose group template is the
|
|
66
68
|
`<tbody>`.
|
|
67
69
|
|
|
68
|
-
`lb-order` and `lb-
|
|
69
|
-
`lb-query`: the user's order replaces the query's, and a row the user's
|
|
70
|
+
`lb-order`, `lb-filter` and `lb-manual` work on `lb-table` as on any
|
|
71
|
+
element carrying `lb-query`: the user's order replaces the query's, and a row the user's
|
|
70
72
|
filter does not pass is hidden.
|
|
71
73
|
|
|
72
74
|
## The order on the heading
|
|
@@ -78,25 +80,25 @@ is shown. A heading's column is the `lb-column` in the cell
|
|
|
78
80
|
at the same position in the row template, on the cell or inside it. A cell
|
|
79
81
|
naming no column, or several, gives its heading none.
|
|
80
82
|
|
|
81
|
-
While rows stand out of
|
|
82
|
-
click on its heading places them again, as `--lb-
|
|
83
|
+
While rows stand out of place, the triangle carries `data-unplaced`, and a
|
|
84
|
+
click on its heading places them again, as `--lb-place` does, keeping the
|
|
83
85
|
direction.
|
|
84
86
|
|
|
85
87
|
With `lb-order` on the table, a click on the sorted heading reverses the
|
|
86
88
|
order, and a click on another heading sorts by its column, ascending. The
|
|
87
89
|
widget writes the order to the column of `lb-choices` that `lb-order`
|
|
88
90
|
names. Without `lb-order` there is nowhere to write one, and only the
|
|
89
|
-
|
|
91
|
+
placing answers a click. There is no click back to the server's order.
|
|
90
92
|
|
|
91
93
|
A heading that takes a click carries `data-sortable`.
|
|
92
94
|
|
|
93
95
|
None of this shows on a grouped table, nor when the order's leading column
|
|
94
|
-
has no heading. There, a button with `commandfor` and `--lb-
|
|
95
|
-
|
|
96
|
+
has no heading. There, a button with `commandfor` and `--lb-place` places
|
|
97
|
+
the rows.
|
|
96
98
|
|
|
97
99
|
The package ships `lb-table.css`: the triangle turns amber and circled
|
|
98
|
-
while rows stand out of
|
|
99
|
-
`lb-row-
|
|
100
|
+
while rows stand out of place, and the first cell of a row carrying
|
|
101
|
+
`lb-row-unplaced` is marked on its leading edge. The application's own
|
|
100
102
|
stylesheet comes after it and overrides any of it.
|
|
101
103
|
|
|
102
104
|
## Filtering by selection
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loadbare/widgets",
|
|
3
3
|
"description": "The basic widget set for @loadbare/app: input, select, options, picker, table, unknown-page, confirm, form, insert-dialog, master, checkbox, number, date, tel, mailto",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.13.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
7
7
|
"dist",
|
|
@@ -23,7 +23,7 @@ Provide `exp-caption`.
|
|
|
23
23
|
</template>
|
|
24
24
|
</template>
|
|
25
25
|
<template lb-exp-template="foot">
|
|
26
|
-
<tr><td>Total</td><td lb-sum="amount"></td></tr>
|
|
26
|
+
<tr><td>Total</td><td lb-aggregate="sum" lb-column="amount"></td></tr>
|
|
27
27
|
</template>
|
|
28
28
|
</lb-table>
|
|
29
29
|
```
|
|
@@ -50,23 +50,25 @@ improvements through iterative use.
|
|
|
50
50
|
| `lb-group` | a template holding the row template | a group, one per run of the order's leading term |
|
|
51
51
|
| `lb-order` | the element itself | the choice holding the user's order |
|
|
52
52
|
| `lb-filter` | the element itself | the columns the user's choices filter |
|
|
53
|
+
| `lb-manual` | the element itself | `order`, `filter` or both: what an answer leaves where it stands |
|
|
53
54
|
| `lb-column` | elements inside the row template | the column each element shows |
|
|
54
55
|
|
|
55
56
|
The server declares the query's key and its order.
|
|
56
57
|
|
|
57
58
|
## Order and groups
|
|
58
59
|
|
|
59
|
-
The hub places the rows by the query's order and builds its groups.
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
60
|
+
The hub places the rows by the query's order and builds its groups. A
|
|
61
|
+
table edited in its rows or its ghost row usually carries
|
|
62
|
+
`lb-manual="order"`, so an edited row stays where it stands and a new one
|
|
63
|
+
goes last until the user asks for the order; a button with `commandfor`
|
|
64
|
+
naming the table's `id` and `command="--lb-place"` does that.
|
|
63
65
|
The rows land in the table's one `<tbody>`, and a `<tbody>` cannot hold another,
|
|
64
66
|
so a group here is a heading row with its rows after it. For a `<tbody>` per
|
|
65
67
|
group, write a plain `<table lb-query>` whose group template is the
|
|
66
68
|
`<tbody>`.
|
|
67
69
|
|
|
68
|
-
`lb-order` and `lb-
|
|
69
|
-
`lb-query`: the user's order replaces the query's, and a row the user's
|
|
70
|
+
`lb-order`, `lb-filter` and `lb-manual` work on `lb-table` as on any
|
|
71
|
+
element carrying `lb-query`: the user's order replaces the query's, and a row the user's
|
|
70
72
|
filter does not pass is hidden.
|
|
71
73
|
|
|
72
74
|
## The order on the heading
|
|
@@ -78,25 +80,25 @@ is shown. A heading's column is the `lb-column` in the cell
|
|
|
78
80
|
at the same position in the row template, on the cell or inside it. A cell
|
|
79
81
|
naming no column, or several, gives its heading none.
|
|
80
82
|
|
|
81
|
-
While rows stand out of
|
|
82
|
-
click on its heading places them again, as `--lb-
|
|
83
|
+
While rows stand out of place, the triangle carries `data-unplaced`, and a
|
|
84
|
+
click on its heading places them again, as `--lb-place` does, keeping the
|
|
83
85
|
direction.
|
|
84
86
|
|
|
85
87
|
With `lb-order` on the table, a click on the sorted heading reverses the
|
|
86
88
|
order, and a click on another heading sorts by its column, ascending. The
|
|
87
89
|
widget writes the order to the column of `lb-choices` that `lb-order`
|
|
88
90
|
names. Without `lb-order` there is nowhere to write one, and only the
|
|
89
|
-
|
|
91
|
+
placing answers a click. There is no click back to the server's order.
|
|
90
92
|
|
|
91
93
|
A heading that takes a click carries `data-sortable`.
|
|
92
94
|
|
|
93
95
|
None of this shows on a grouped table, nor when the order's leading column
|
|
94
|
-
has no heading. There, a button with `commandfor` and `--lb-
|
|
95
|
-
|
|
96
|
+
has no heading. There, a button with `commandfor` and `--lb-place` places
|
|
97
|
+
the rows.
|
|
96
98
|
|
|
97
99
|
The package ships `lb-table.css`: the triangle turns amber and circled
|
|
98
|
-
while rows stand out of
|
|
99
|
-
`lb-row-
|
|
100
|
+
while rows stand out of place, and the first cell of a row carrying
|
|
101
|
+
`lb-row-unplaced` is marked on its leading edge. The application's own
|
|
100
102
|
stylesheet comes after it and overrides any of it.
|
|
101
103
|
|
|
102
104
|
## Filtering by selection
|