@fusion.dev/helix-headless 0.239.0 → 0.240.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/api.json +1 -1
- package/custom-elements.json +1 -1
- package/dist/column-manager/index.d.ts +1 -0
- package/dist/column-manager/index.js +1 -0
- package/dist/column-manager/root/column-manager-root.d.ts +137 -0
- package/dist/column-manager/root/column-manager-root.js +253 -0
- package/dist/data-table/binding.d.ts +85 -0
- package/dist/data-table/binding.js +58 -0
- package/dist/data-table/edit.d.ts +47 -0
- package/dist/data-table/edit.js +60 -0
- package/dist/data-table/events/before-cell-commit.d.ts +16 -0
- package/dist/data-table/events/before-cell-commit.js +11 -0
- package/dist/data-table/events/before-cell-edit.d.ts +13 -0
- package/dist/data-table/events/before-cell-edit.js +11 -0
- package/dist/data-table/events/before-export.d.ts +15 -0
- package/dist/data-table/events/before-export.js +11 -0
- package/dist/data-table/events/before-view-change.d.ts +16 -0
- package/dist/data-table/events/before-view-change.js +11 -0
- package/dist/data-table/events/cell-commit.d.ts +12 -0
- package/dist/data-table/events/cell-commit.js +11 -0
- package/dist/data-table/events/cell-edit.d.ts +11 -0
- package/dist/data-table/events/cell-edit.js +11 -0
- package/dist/data-table/events/details.d.ts +47 -0
- package/dist/data-table/events/export.d.ts +11 -0
- package/dist/data-table/events/export.js +11 -0
- package/dist/data-table/events/index.d.ts +18 -2
- package/dist/data-table/events/index.js +17 -1
- package/dist/data-table/events/view-change.d.ts +12 -0
- package/dist/data-table/events/view-change.js +11 -0
- package/dist/data-table/export.d.ts +43 -0
- package/dist/data-table/export.js +26 -0
- package/dist/data-table/index.d.ts +2 -0
- package/dist/data-table/index.js +2 -0
- package/dist/data-table/root/data-table-root.d.ts +406 -26
- package/dist/data-table/root/data-table-root.js +959 -30
- package/dist/data-table/view.d.ts +124 -0
- package/dist/data-table/view.js +249 -0
- package/dist/data-table/xlsx/index.d.ts +27 -0
- package/dist/data-table/xlsx/index.js +119 -0
- package/dist/date-input/root/date-input-root.d.ts +7 -0
- package/dist/date-input/root/date-input-root.js +9 -1
- package/dist/element-events.generated.js +9 -0
- package/dist/filter-input/root/filter-input-root.d.ts +31 -0
- package/dist/filter-input/root/filter-input-root.js +94 -12
- package/dist/filter-input/table.d.ts +64 -0
- package/dist/filter-input/table.js +76 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +5 -0
- package/dist/input/root/input-root.d.ts +7 -0
- package/dist/input/root/input-root.js +9 -1
- package/dist/number-input/root/number-input-root.d.ts +7 -0
- package/dist/number-input/root/number-input-root.js +9 -1
- package/dist/quick-filters/events/before-view-save.d.ts +14 -0
- package/dist/quick-filters/events/before-view-save.js +11 -0
- package/dist/quick-filters/events/details.d.ts +10 -0
- package/dist/quick-filters/events/details.js +1 -0
- package/dist/quick-filters/events/index.d.ts +16 -0
- package/dist/quick-filters/events/index.js +9 -0
- package/dist/quick-filters/events/view-save.d.ts +11 -0
- package/dist/quick-filters/events/view-save.js +11 -0
- package/dist/quick-filters/filter/quick-filter.d.ts +48 -0
- package/dist/quick-filters/filter/quick-filter.js +33 -0
- package/dist/quick-filters/index.d.ts +3 -0
- package/dist/quick-filters/index.js +3 -0
- package/dist/quick-filters/root/quick-filters-root.d.ts +118 -0
- package/dist/quick-filters/root/quick-filters-root.js +183 -0
- package/dist/selection-bar/index.d.ts +1 -0
- package/dist/selection-bar/index.js +1 -0
- package/dist/selection-bar/root/selection-bar-root.d.ts +65 -0
- package/dist/selection-bar/root/selection-bar-root.js +44 -0
- package/dist/table/column/table-column.d.ts +82 -0
- package/dist/table/column/table-column.js +54 -0
- package/dist/table/column-type.d.ts +7 -0
- package/dist/table/column-type.js +1 -0
- package/dist/table-export/index.d.ts +1 -0
- package/dist/table-export/index.js +1 -0
- package/dist/table-export/root/table-export-root.d.ts +132 -0
- package/dist/table-export/root/table-export-root.js +233 -0
- package/dist/view-panel/index.d.ts +1 -0
- package/dist/view-panel/index.js +1 -0
- package/dist/view-panel/root/view-panel-root.d.ts +132 -0
- package/dist/view-panel/root/view-panel-root.js +209 -0
- package/examples.json +1 -1
- package/lint.json +1 -1
- package/package.json +5 -5
- package/types/jsx.d.ts +1231 -9
- package/types/svelte.d.ts +6 -0
- package/types/vue.d.ts +605 -6
- package/types/words.d.ts +305 -5
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { __decorate } from "tslib";
|
|
2
|
+
import { customElement, HelixElement, numberConverter } from '@fusion.dev/helix-core';
|
|
3
|
+
import { html } from 'lit';
|
|
4
|
+
import { property } from 'lit/decorators.js';
|
|
5
|
+
import { readPartialView } from '../../data-table/view.js';
|
|
6
|
+
let HelixHeadlessQuickFilter = class HelixHeadlessQuickFilter extends HelixElement {
|
|
7
|
+
constructor() {
|
|
8
|
+
super(...arguments);
|
|
9
|
+
this.view = '';
|
|
10
|
+
this.isQuickFilter = true;
|
|
11
|
+
}
|
|
12
|
+
get parts() {
|
|
13
|
+
try {
|
|
14
|
+
return readPartialView(JSON.parse(this.view));
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
return {};
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
render() {
|
|
21
|
+
return html `<slot></slot>`;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
__decorate([
|
|
25
|
+
property({ converter: numberConverter('count', undefined) })
|
|
26
|
+
], HelixHeadlessQuickFilter.prototype, "count", void 0);
|
|
27
|
+
__decorate([
|
|
28
|
+
property()
|
|
29
|
+
], HelixHeadlessQuickFilter.prototype, "view", void 0);
|
|
30
|
+
HelixHeadlessQuickFilter = __decorate([
|
|
31
|
+
customElement('helix-headless-quick-filter')
|
|
32
|
+
], HelixHeadlessQuickFilter);
|
|
33
|
+
export { HelixHeadlessQuickFilter };
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { HelixElement, ToolbarController } from '@fusion.dev/helix-core';
|
|
2
|
+
import { type TemplateResult } from 'lit';
|
|
3
|
+
import { TableBinding, type ToolTable } from '../../data-table/binding.js';
|
|
4
|
+
import { type PartialView } from '../../data-table/view.js';
|
|
5
|
+
/** A preset the row draws: one written as a child, or one kept in browser storage. */
|
|
6
|
+
interface Preset {
|
|
7
|
+
count?: number | undefined;
|
|
8
|
+
label: string;
|
|
9
|
+
saved: boolean;
|
|
10
|
+
view: PartialView;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* @summary A row of presets for a Data Table, each a partial view with a count, and a button that saves the view.
|
|
14
|
+
*
|
|
15
|
+
* @description
|
|
16
|
+
* Set `for` to the id of a `DataTable`, and write each preset as a
|
|
17
|
+
* `QuickFilter` child. A preset is a partial view: the parts of the table's
|
|
18
|
+
* view it sets, such as its filters or its sort. Pressing one asks the table
|
|
19
|
+
* for those parts with `requestView`, and the preset the view holds now is
|
|
20
|
+
* pressed.
|
|
21
|
+
*
|
|
22
|
+
* ```html
|
|
23
|
+
* <helix-quick-filters for="invoices">
|
|
24
|
+
* <helix-quick-filter view='{"filters":[]}'>All</helix-quick-filter>
|
|
25
|
+
* <helix-quick-filter view='{"filters":[{"field":"status","operator":"any","values":["Overdue"]}]}'>Overdue</helix-quick-filter>
|
|
26
|
+
* </helix-quick-filters>
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* Each button shows how many rows the preset would show, counted from the
|
|
30
|
+
* rows the table holds. A table in `server` mode holds one page, so give each
|
|
31
|
+
* preset its `count`.
|
|
32
|
+
*
|
|
33
|
+
* **Save view.** The last button saves the table's whole view. It fires
|
|
34
|
+
* `helix-before-view-save` with the view and a name, which you can cancel to
|
|
35
|
+
* keep the view in your own store, and then `helix-view-save`. With
|
|
36
|
+
* `view-key`, the view is also kept in this browser's storage under that key
|
|
37
|
+
* and drawn after your presets, and a saved preset can be removed. Without
|
|
38
|
+
* it, nothing is kept: keep the view from the event.
|
|
39
|
+
*
|
|
40
|
+
* The buttons are one tab stop, and the arrow keys, Home, and End move among
|
|
41
|
+
* them, as in a toolbar.
|
|
42
|
+
*
|
|
43
|
+
* @since 0.238.0
|
|
44
|
+
* @status experimental
|
|
45
|
+
* @category data
|
|
46
|
+
* @aliases Saved views, Presets, View tabs
|
|
47
|
+
* @documentation https://fusion.dev/helix/components/quick-filters
|
|
48
|
+
*
|
|
49
|
+
* @slot - The presets, as `QuickFilter` elements.
|
|
50
|
+
*
|
|
51
|
+
* @event {HelixBeforeViewSaveEvent} helix-before-view-save - Save view was pressed, with the view and the name it is saved under. Cancelable: cancel it to keep the view yourself.
|
|
52
|
+
* @event {HelixViewSaveEvent} helix-view-save - Fired after a view is saved, with the view and its name.
|
|
53
|
+
*
|
|
54
|
+
* @csspart count - How many rows a preset shows, after its name.
|
|
55
|
+
* @csspart list - The row of buttons.
|
|
56
|
+
* @csspart name - A preset's name, inside its button.
|
|
57
|
+
* @csspart preset - One preset's button.
|
|
58
|
+
* @csspart preset-pressed - Added to `preset` while the view holds it.
|
|
59
|
+
* @csspart preset-saved - Added to `preset` for a view kept in browser storage.
|
|
60
|
+
* @csspart remove - The button after a saved preset that removes it.
|
|
61
|
+
* @csspart save - The button that saves the view.
|
|
62
|
+
*/
|
|
63
|
+
export declare class HelixHeadlessQuickFilters extends HelixElement {
|
|
64
|
+
/**
|
|
65
|
+
* The key this family's words are registered under, its styled tag:
|
|
66
|
+
* `registerWords('de', { 'helix-quick-filters': { saveLabel: 'Ansicht speichern' } })`.
|
|
67
|
+
*/
|
|
68
|
+
static words: string;
|
|
69
|
+
/** The name the element gives itself where `label` is empty. */
|
|
70
|
+
fallbackLabel: string;
|
|
71
|
+
/** The id of the `DataTable` the presets set the view of, in the same document or shadow root. */
|
|
72
|
+
for: string;
|
|
73
|
+
/**
|
|
74
|
+
* The name of the list, which a screen reader announces before its items.
|
|
75
|
+
*
|
|
76
|
+
* Empty by default, which leaves the name to `fallbackLabel`.
|
|
77
|
+
*/
|
|
78
|
+
label: string;
|
|
79
|
+
/** The name of the button that removes a saved view. `{name}` is the view's name. */
|
|
80
|
+
removeLabel: string;
|
|
81
|
+
/** The name a saved view is given. `{count}` is how many views are saved, with this one. */
|
|
82
|
+
savedLabel: string;
|
|
83
|
+
/** The words on the button that saves the view. Empty draws no button. */
|
|
84
|
+
saveLabel: string;
|
|
85
|
+
/**
|
|
86
|
+
* Keeps saved views in this browser's storage under this key, and draws them
|
|
87
|
+
* after the presets you write. Left unset, Save view only fires its events.
|
|
88
|
+
*/
|
|
89
|
+
viewKey: string;
|
|
90
|
+
/** The views kept under `view-key`, read once the key is known. */
|
|
91
|
+
private saved;
|
|
92
|
+
protected readonly binding: TableBinding;
|
|
93
|
+
protected readonly keys: ToolbarController;
|
|
94
|
+
/** The bound table, once it is in the tree. */
|
|
95
|
+
get table(): ToolTable | null;
|
|
96
|
+
/** The presets written as children, then the views kept in storage. */
|
|
97
|
+
private get presets();
|
|
98
|
+
private get storageName();
|
|
99
|
+
private readSaved;
|
|
100
|
+
private writeSaved;
|
|
101
|
+
/** Sets the parts of the view one preset names. */
|
|
102
|
+
choose(view: PartialView): boolean;
|
|
103
|
+
/** Saves the table's whole view, as Save view does. Returns whether it was saved. */
|
|
104
|
+
saveView(label?: string): boolean;
|
|
105
|
+
/** Removes a view kept in storage, by its place among the saved ones. */
|
|
106
|
+
removeSaved(index: number): void;
|
|
107
|
+
protected willUpdate(changed: Map<PropertyKey, unknown>): void;
|
|
108
|
+
protected firstUpdated(changed: Map<PropertyKey, unknown>): void;
|
|
109
|
+
private readonly handleSlotChange;
|
|
110
|
+
protected renderPreset(table: ToolTable | null, preset: Preset, savedAt: number): TemplateResult;
|
|
111
|
+
protected render(): TemplateResult;
|
|
112
|
+
}
|
|
113
|
+
declare global {
|
|
114
|
+
interface HTMLElementTagNameMap {
|
|
115
|
+
'helix-headless-quick-filters': HelixHeadlessQuickFilters;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
export {};
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import { __decorate } from "tslib";
|
|
2
|
+
import { customElement, formatWords, HelixElement, ToolbarController, words, } from '@fusion.dev/helix-core';
|
|
3
|
+
import { html, nothing } from 'lit';
|
|
4
|
+
import { property, state } from 'lit/decorators.js';
|
|
5
|
+
import { TableBinding } from '../../data-table/binding.js';
|
|
6
|
+
import { holdsView, readView } from '../../data-table/view.js';
|
|
7
|
+
import { HelixBeforeViewSaveEvent, HelixViewSaveEvent } from '../events/index.js';
|
|
8
|
+
const storage = () => {
|
|
9
|
+
try {
|
|
10
|
+
return globalThis.localStorage;
|
|
11
|
+
}
|
|
12
|
+
catch {
|
|
13
|
+
return undefined;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
let HelixHeadlessQuickFilters = class HelixHeadlessQuickFilters extends HelixElement {
|
|
17
|
+
constructor() {
|
|
18
|
+
super(...arguments);
|
|
19
|
+
this.fallbackLabel = 'Quick filters';
|
|
20
|
+
this.for = '';
|
|
21
|
+
this.label = '';
|
|
22
|
+
this.removeLabel = 'Remove {name}';
|
|
23
|
+
this.savedLabel = 'View {count}';
|
|
24
|
+
this.saveLabel = 'Save view';
|
|
25
|
+
this.viewKey = '';
|
|
26
|
+
this.saved = [];
|
|
27
|
+
this.binding = new TableBinding(this);
|
|
28
|
+
this.keys = new ToolbarController(this, {
|
|
29
|
+
arrows: () => 'horizontal',
|
|
30
|
+
members: () => [
|
|
31
|
+
...(this.renderRoot.querySelectorAll?.('[part~="preset"], [part="save"]') ?? []),
|
|
32
|
+
],
|
|
33
|
+
own: true,
|
|
34
|
+
watch: () => this.renderRoot,
|
|
35
|
+
words: (button) => button.textContent?.trim() ?? '',
|
|
36
|
+
});
|
|
37
|
+
this.handleSlotChange = () => {
|
|
38
|
+
this.requestUpdate();
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
static { this.words = 'helix-quick-filters'; }
|
|
42
|
+
get table() {
|
|
43
|
+
return this.binding.table;
|
|
44
|
+
}
|
|
45
|
+
get presets() {
|
|
46
|
+
const written = this.knownChildren
|
|
47
|
+
.filter((child) => child.isQuickFilter === true)
|
|
48
|
+
.map((child) => ({
|
|
49
|
+
count: child.count,
|
|
50
|
+
label: child.textContent?.trim() ?? '',
|
|
51
|
+
saved: false,
|
|
52
|
+
view: child.parts,
|
|
53
|
+
}));
|
|
54
|
+
return [...written, ...this.saved.map((one) => ({ ...one, saved: true }))];
|
|
55
|
+
}
|
|
56
|
+
get storageName() {
|
|
57
|
+
return `helix-views:${this.viewKey}`;
|
|
58
|
+
}
|
|
59
|
+
readSaved() {
|
|
60
|
+
if (!this.viewKey) {
|
|
61
|
+
this.saved = [];
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
try {
|
|
65
|
+
const kept = JSON.parse(storage()?.getItem(this.storageName) ?? '[]');
|
|
66
|
+
this.saved = Array.isArray(kept)
|
|
67
|
+
? kept.flatMap((one) => one && typeof one.label === 'string'
|
|
68
|
+
? [{ label: one.label, view: readView(one.view) }]
|
|
69
|
+
: [])
|
|
70
|
+
: [];
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
this.saved = [];
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
writeSaved() {
|
|
77
|
+
try {
|
|
78
|
+
storage()?.setItem(this.storageName, JSON.stringify(this.saved));
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
choose(view) {
|
|
84
|
+
return this.table?.requestView(view) ?? false;
|
|
85
|
+
}
|
|
86
|
+
saveView(label = formatWords(this, 'savedLabel', { count: this.saved.length + 1 })) {
|
|
87
|
+
const table = this.table;
|
|
88
|
+
if (!table) {
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
const view = table.view;
|
|
92
|
+
const detail = { label, value: JSON.stringify(view), view };
|
|
93
|
+
if (!this.dispatchEvent(new HelixBeforeViewSaveEvent(detail))) {
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
if (this.viewKey) {
|
|
97
|
+
this.saved = [...this.saved, { label, view }];
|
|
98
|
+
this.writeSaved();
|
|
99
|
+
}
|
|
100
|
+
this.dispatchEvent(new HelixViewSaveEvent(detail));
|
|
101
|
+
return true;
|
|
102
|
+
}
|
|
103
|
+
removeSaved(index) {
|
|
104
|
+
this.saved = this.saved.filter((_, at) => at !== index);
|
|
105
|
+
this.writeSaved();
|
|
106
|
+
}
|
|
107
|
+
willUpdate(changed) {
|
|
108
|
+
super.willUpdate(changed);
|
|
109
|
+
if (changed.has('viewKey') && typeof window !== 'undefined') {
|
|
110
|
+
this.readSaved();
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
firstUpdated(changed) {
|
|
114
|
+
super.firstUpdated(changed);
|
|
115
|
+
this.finishHydration();
|
|
116
|
+
}
|
|
117
|
+
renderPreset(table, preset, savedAt) {
|
|
118
|
+
const pressed = table ? holdsView(table.view, preset.view) : false;
|
|
119
|
+
const count = preset.count ?? table?.countView(preset.view);
|
|
120
|
+
return html `<button
|
|
121
|
+
part="preset${pressed ? ' preset-pressed' : ''}${preset.saved ? ' preset-saved' : ''}"
|
|
122
|
+
type="button"
|
|
123
|
+
aria-pressed=${pressed ? 'true' : 'false'}
|
|
124
|
+
@click=${() => this.choose(preset.view)}
|
|
125
|
+
><span part="name">${preset.label}</span>${count === undefined ? nothing : html ` <span part="count">${count}</span>`}</button
|
|
126
|
+
>${preset.saved
|
|
127
|
+
? html `<button
|
|
128
|
+
part="remove"
|
|
129
|
+
type="button"
|
|
130
|
+
tabindex="-1"
|
|
131
|
+
aria-label=${formatWords(this, 'removeLabel', { name: preset.label })}
|
|
132
|
+
@click=${() => this.removeSaved(savedAt)}
|
|
133
|
+
>×</button>`
|
|
134
|
+
: nothing}`;
|
|
135
|
+
}
|
|
136
|
+
render() {
|
|
137
|
+
const table = this.table;
|
|
138
|
+
let savedAt = -1;
|
|
139
|
+
return html `<div part="list" role="toolbar" aria-label=${this.label || this.fallbackLabel}>
|
|
140
|
+
${this.presets.map((preset) => {
|
|
141
|
+
if (preset.saved) {
|
|
142
|
+
savedAt += 1;
|
|
143
|
+
}
|
|
144
|
+
return this.renderPreset(table, preset, savedAt);
|
|
145
|
+
})}${this.saveLabel
|
|
146
|
+
? html `<button part="save" type="button" @click=${() => this.saveView()}>${this.saveLabel}</button>`
|
|
147
|
+
: nothing}
|
|
148
|
+
</div>
|
|
149
|
+
<slot @slotchange=${this.handleSlotChange} hidden></slot>`;
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
__decorate([
|
|
153
|
+
words,
|
|
154
|
+
property({ attribute: 'fallback-label' })
|
|
155
|
+
], HelixHeadlessQuickFilters.prototype, "fallbackLabel", void 0);
|
|
156
|
+
__decorate([
|
|
157
|
+
property()
|
|
158
|
+
], HelixHeadlessQuickFilters.prototype, "for", void 0);
|
|
159
|
+
__decorate([
|
|
160
|
+
property()
|
|
161
|
+
], HelixHeadlessQuickFilters.prototype, "label", void 0);
|
|
162
|
+
__decorate([
|
|
163
|
+
words,
|
|
164
|
+
property({ attribute: 'remove-label' })
|
|
165
|
+
], HelixHeadlessQuickFilters.prototype, "removeLabel", void 0);
|
|
166
|
+
__decorate([
|
|
167
|
+
words,
|
|
168
|
+
property({ attribute: 'saved-label' })
|
|
169
|
+
], HelixHeadlessQuickFilters.prototype, "savedLabel", void 0);
|
|
170
|
+
__decorate([
|
|
171
|
+
words,
|
|
172
|
+
property({ attribute: 'save-label' })
|
|
173
|
+
], HelixHeadlessQuickFilters.prototype, "saveLabel", void 0);
|
|
174
|
+
__decorate([
|
|
175
|
+
property({ attribute: 'view-key' })
|
|
176
|
+
], HelixHeadlessQuickFilters.prototype, "viewKey", void 0);
|
|
177
|
+
__decorate([
|
|
178
|
+
state()
|
|
179
|
+
], HelixHeadlessQuickFilters.prototype, "saved", void 0);
|
|
180
|
+
HelixHeadlessQuickFilters = __decorate([
|
|
181
|
+
customElement('helix-headless-quick-filters')
|
|
182
|
+
], HelixHeadlessQuickFilters);
|
|
183
|
+
export { HelixHeadlessQuickFilters };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './root/selection-bar-root.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './root/selection-bar-root.js';
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { HelixElement } from '@fusion.dev/helix-core';
|
|
2
|
+
import { type TemplateResult } from 'lit';
|
|
3
|
+
import { TableBinding, type ToolTable } from '../../data-table/binding.js';
|
|
4
|
+
/**
|
|
5
|
+
* @summary A bar that says how many of a Data Table's rows are selected, with what you can do to them and a way to clear them.
|
|
6
|
+
*
|
|
7
|
+
* @description
|
|
8
|
+
* Put it in a `DataTable`'s `selection` slot, and it takes the toolbar's
|
|
9
|
+
* place while rows are selected. Slot your actions into it, such as Archive
|
|
10
|
+
* and Export, and Clear unselects every row.
|
|
11
|
+
*
|
|
12
|
+
* ```html
|
|
13
|
+
* <helix-data-table selectable row-key="id">
|
|
14
|
+
* <helix-selection-bar slot="selection">
|
|
15
|
+
* <helix-button>Archive</helix-button>
|
|
16
|
+
* </helix-selection-bar>
|
|
17
|
+
* </helix-data-table>
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* Written inside the table, it finds the table. Written anywhere else, set
|
|
21
|
+
* `for` to the table's id. Clear asks the table with `helix-before-select`,
|
|
22
|
+
* as a reader's own choice does.
|
|
23
|
+
*
|
|
24
|
+
* @since 0.238.0
|
|
25
|
+
* @status experimental
|
|
26
|
+
* @category data
|
|
27
|
+
* @aliases Bulk actions, Action bar
|
|
28
|
+
* @documentation https://fusion.dev/helix/components/selection-bar
|
|
29
|
+
*
|
|
30
|
+
* @slot - What you can do to the selected rows, such as buttons.
|
|
31
|
+
*
|
|
32
|
+
* @csspart actions - The region that holds the slotted actions.
|
|
33
|
+
* @csspart clear - The button that clears the selection.
|
|
34
|
+
* @csspart count - Says how many rows are selected.
|
|
35
|
+
*/
|
|
36
|
+
export declare class HelixHeadlessSelectionBar extends HelixElement {
|
|
37
|
+
/**
|
|
38
|
+
* The key this family's words are registered under, its styled tag:
|
|
39
|
+
* `registerWords('de', { 'helix-selection-bar': { clearLabel: 'Auswahl aufheben' } })`.
|
|
40
|
+
*/
|
|
41
|
+
static words: string;
|
|
42
|
+
/** The words on the button that clears the selection. */
|
|
43
|
+
clearLabel: string;
|
|
44
|
+
/** What the bar says. `{count}` is how many rows are selected. */
|
|
45
|
+
countLabel: string;
|
|
46
|
+
/**
|
|
47
|
+
* The id of the `DataTable` whose selection the bar shows, in the same
|
|
48
|
+
* document or shadow root. Left empty, the bar takes the table it is written
|
|
49
|
+
* in.
|
|
50
|
+
*/
|
|
51
|
+
for: string;
|
|
52
|
+
protected readonly binding: TableBinding;
|
|
53
|
+
/** The bound table, once it is in the tree. */
|
|
54
|
+
get table(): ToolTable | null;
|
|
55
|
+
/** How many rows are selected. */
|
|
56
|
+
get count(): number;
|
|
57
|
+
/** Unselects every row, as Clear does. Returns whether the selection changed. */
|
|
58
|
+
clear(): boolean;
|
|
59
|
+
protected render(): TemplateResult;
|
|
60
|
+
}
|
|
61
|
+
declare global {
|
|
62
|
+
interface HTMLElementTagNameMap {
|
|
63
|
+
'helix-headless-selection-bar': HelixHeadlessSelectionBar;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { __decorate } from "tslib";
|
|
2
|
+
import { customElement, formatWords, HelixElement, words } from '@fusion.dev/helix-core';
|
|
3
|
+
import { html } from 'lit';
|
|
4
|
+
import { property } from 'lit/decorators.js';
|
|
5
|
+
import { TableBinding } from '../../data-table/binding.js';
|
|
6
|
+
let HelixHeadlessSelectionBar = class HelixHeadlessSelectionBar extends HelixElement {
|
|
7
|
+
constructor() {
|
|
8
|
+
super(...arguments);
|
|
9
|
+
this.clearLabel = 'Clear';
|
|
10
|
+
this.countLabel = '{count} selected';
|
|
11
|
+
this.for = '';
|
|
12
|
+
this.binding = new TableBinding(this);
|
|
13
|
+
}
|
|
14
|
+
static { this.words = 'helix-selection-bar'; }
|
|
15
|
+
get table() {
|
|
16
|
+
return this.binding.table;
|
|
17
|
+
}
|
|
18
|
+
get count() {
|
|
19
|
+
return this.table?.selected.split(',').filter(Boolean).length ?? 0;
|
|
20
|
+
}
|
|
21
|
+
clear() {
|
|
22
|
+
return this.table?.selectRows([]) ?? false;
|
|
23
|
+
}
|
|
24
|
+
render() {
|
|
25
|
+
return html `<span part="count">${formatWords(this, 'countLabel', { count: this.count })}</span>
|
|
26
|
+
<div part="actions"><slot></slot></div>
|
|
27
|
+
<button part="clear" type="button" @click=${() => this.clear()}>${this.clearLabel}</button>`;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
__decorate([
|
|
31
|
+
words,
|
|
32
|
+
property({ attribute: 'clear-label' })
|
|
33
|
+
], HelixHeadlessSelectionBar.prototype, "clearLabel", void 0);
|
|
34
|
+
__decorate([
|
|
35
|
+
words,
|
|
36
|
+
property({ attribute: 'count-label' })
|
|
37
|
+
], HelixHeadlessSelectionBar.prototype, "countLabel", void 0);
|
|
38
|
+
__decorate([
|
|
39
|
+
property()
|
|
40
|
+
], HelixHeadlessSelectionBar.prototype, "for", void 0);
|
|
41
|
+
HelixHeadlessSelectionBar = __decorate([
|
|
42
|
+
customElement('helix-headless-selection-bar')
|
|
43
|
+
], HelixHeadlessSelectionBar);
|
|
44
|
+
export { HelixHeadlessSelectionBar };
|
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
import { HelixElement } from '@fusion.dev/helix-core';
|
|
2
2
|
import { type PropertyValues, type TemplateResult } from 'lit';
|
|
3
|
+
import type { ColumnType } from '../column-type.js';
|
|
4
|
+
/** What a column's `editor` is given to draw a field for an edited cell. */
|
|
5
|
+
export interface CellEditorContext {
|
|
6
|
+
/** Puts the old value back and closes the cell. */
|
|
7
|
+
cancel: () => void;
|
|
8
|
+
/** Saves a new value, as Enter does on the table's own field. */
|
|
9
|
+
commit: (value: unknown) => void;
|
|
10
|
+
/** The row. */
|
|
11
|
+
row: Readonly<Record<string, unknown>>;
|
|
12
|
+
/** The value the cell holds now. */
|
|
13
|
+
value: unknown;
|
|
14
|
+
}
|
|
15
|
+
/** Draws the field for an edited cell: anything a Lit template can render. */
|
|
16
|
+
export type CellEditor = (context: CellEditorContext) => unknown;
|
|
3
17
|
/**
|
|
4
18
|
* How a column is read out of a row, once the row is data rather than markup.
|
|
5
19
|
*
|
|
@@ -86,7 +100,11 @@ export { edgeOf } from '../edge.js';
|
|
|
86
100
|
* @csspart sort-mark - The two chevrons on a sortable heading. To remove them, set `display: none` on this part.
|
|
87
101
|
* @csspart sort-up - The upper chevron of `sort-mark`, which shows an ascending sort.
|
|
88
102
|
*
|
|
103
|
+
* @cssproperty --table-column-pin-offset - How far a pinned column's heading stays from its end of the row, in pixels: the width of the pinned columns before it. The column writes it on `column` while a `DataTable` pins it.
|
|
104
|
+
*
|
|
89
105
|
* @cssstate has-menu - While the heading draws its menu button.
|
|
106
|
+
* @cssstate pinned-end - While a `DataTable` pins the column to the end of the row.
|
|
107
|
+
* @cssstate pinned-start - While a `DataTable` pins the column to the start of the row.
|
|
90
108
|
* @cssstate sorted-ascending - While the table is sorted by this column, smallest first.
|
|
91
109
|
* @cssstate sorted-descending - While the table is sorted by this column, largest first.
|
|
92
110
|
*/
|
|
@@ -117,6 +135,26 @@ export declare class HelixHeadlessTableColumn extends HelixElement {
|
|
|
117
135
|
* correct default: the raw value is what an API sorted by.
|
|
118
136
|
*/
|
|
119
137
|
compare: CellReader | undefined;
|
|
138
|
+
/**
|
|
139
|
+
* Lets a reader edit the column's cells, in a `DataTable`.
|
|
140
|
+
*
|
|
141
|
+
* Enter, F2, a double click, or typing opens a cell in the field the
|
|
142
|
+
* column's `type` picks: a text field, a number field, a date field, or a
|
|
143
|
+
* select of an enum column's values. A boolean toggles in place. Enter saves
|
|
144
|
+
* and moves down, Tab saves and moves to the next cell, leaving the cell
|
|
145
|
+
* saves, and Escape puts the old value back. `required`, `min`, `max`,
|
|
146
|
+
* `pattern` and `validate` check the value first. Set `rowEditable` to
|
|
147
|
+
* decide row by row.
|
|
148
|
+
*/
|
|
149
|
+
editable: boolean;
|
|
150
|
+
/**
|
|
151
|
+
* A function that draws your own field for an edited cell, in place of the
|
|
152
|
+
* one the column's `type` picks. It is given the row, the value, and
|
|
153
|
+
* `commit` and `cancel`: call `commit` with the new value to save it, and
|
|
154
|
+
* `cancel` to put the old one back. Enter, Tab and Escape on your field
|
|
155
|
+
* work as they do on the table's own.
|
|
156
|
+
*/
|
|
157
|
+
editor: CellEditor | undefined;
|
|
120
158
|
/**
|
|
121
159
|
* The key this column reads out of a row.
|
|
122
160
|
*
|
|
@@ -133,6 +171,14 @@ export declare class HelixHeadlessTableColumn extends HelixElement {
|
|
|
133
171
|
* such a column is never sortable however it is marked.
|
|
134
172
|
*/
|
|
135
173
|
field: string;
|
|
174
|
+
/**
|
|
175
|
+
* Offers the column as a filter, in a `DataTable` bound to a `FilterInput`.
|
|
176
|
+
* The field lists the column with the comparisons its `type` offers, and an
|
|
177
|
+
* enum column lists its values with how many rows hold each.
|
|
178
|
+
*/
|
|
179
|
+
filterable: boolean;
|
|
180
|
+
/** The largest value an edited cell may hold: a number, or a date as `YYYY-MM-DD`. */
|
|
181
|
+
max: string;
|
|
136
182
|
/**
|
|
137
183
|
* Draws a button in the heading that opens a menu of what you can do with the
|
|
138
184
|
* column, in a `DataTable`.
|
|
@@ -147,6 +193,8 @@ export declare class HelixHeadlessTableColumn extends HelixElement {
|
|
|
147
193
|
* `{named}` is `no` for a column without one.
|
|
148
194
|
*/
|
|
149
195
|
menuLabel: string;
|
|
196
|
+
/** The smallest value an edited cell may hold: a number, or a date as `YYYY-MM-DD`. */
|
|
197
|
+
min: string;
|
|
150
198
|
/**
|
|
151
199
|
* The narrowest a `DataTable` can be with this column showing, as a length
|
|
152
200
|
* in `px`, `rem` or `em`, such as `40rem`. While the table is narrower, it
|
|
@@ -175,6 +223,10 @@ export declare class HelixHeadlessTableColumn extends HelixElement {
|
|
|
175
223
|
* language hears its own rather than English around its own headings.
|
|
176
224
|
*/
|
|
177
225
|
moveLabel: string;
|
|
226
|
+
/** A pattern an edited text cell matches whole, as an input's `pattern` is matched. */
|
|
227
|
+
pattern: string;
|
|
228
|
+
/** Whether an edited cell may be left empty. */
|
|
229
|
+
required: boolean;
|
|
178
230
|
/**
|
|
179
231
|
* Whether the column can be resized.
|
|
180
232
|
*
|
|
@@ -189,6 +241,12 @@ export declare class HelixHeadlessTableColumn extends HelixElement {
|
|
|
189
241
|
* the heading text, and `{named}` is `no` for a column without one.
|
|
190
242
|
*/
|
|
191
243
|
resizeLabel: string;
|
|
244
|
+
/**
|
|
245
|
+
* A function that decides whether a row's cell in this column can be
|
|
246
|
+
* edited, for a column that is `editable`. Given the row, it returns `true`
|
|
247
|
+
* or `false`. A property only, being a function.
|
|
248
|
+
*/
|
|
249
|
+
rowEditable: ((row: Readonly<Record<string, unknown>>) => boolean) | undefined;
|
|
192
250
|
/**
|
|
193
251
|
* Makes this column's cells the headers of their rows, in `DataTable`.
|
|
194
252
|
*
|
|
@@ -199,6 +257,12 @@ export declare class HelixHeadlessTableColumn extends HelixElement {
|
|
|
199
257
|
* a cell is a row header through its own `header` attribute.
|
|
200
258
|
*/
|
|
201
259
|
rowHeader: boolean;
|
|
260
|
+
/**
|
|
261
|
+
* Searches the column's values, in a `DataTable`. While no column sets it,
|
|
262
|
+
* the search reads every column with a `field`. Once one does, it reads only
|
|
263
|
+
* the columns that set it, so a search for a name does not match an id.
|
|
264
|
+
*/
|
|
265
|
+
searchable: boolean;
|
|
202
266
|
/**
|
|
203
267
|
* Whether the table can be sorted by this column.
|
|
204
268
|
*
|
|
@@ -244,6 +308,24 @@ export declare class HelixHeadlessTableColumn extends HelixElement {
|
|
|
244
308
|
* state instead. No default, so an unset column writes nothing onto its host.
|
|
245
309
|
*/
|
|
246
310
|
textAlign?: 'center' | 'end' | 'start';
|
|
311
|
+
/**
|
|
312
|
+
* What the column holds: `text`, `number`, `date`, `enum` or `boolean`.
|
|
313
|
+
*
|
|
314
|
+
* In a `DataTable` the type picks the comparisons the column's filter
|
|
315
|
+
* offers. Text is contains, is, is not and is empty. Numbers compare as
|
|
316
|
+
* numbers, with between. Dates compare by the day, with before, after and
|
|
317
|
+
* between. An enum is any of or none of its values, and the table counts how
|
|
318
|
+
* many rows hold each value. A boolean is yes or no. Left unset, the column
|
|
319
|
+
* holds text.
|
|
320
|
+
*/
|
|
321
|
+
type?: ColumnType;
|
|
322
|
+
/**
|
|
323
|
+
* A function that checks an edited cell's value, after `required`, `min`,
|
|
324
|
+
* `max` and `pattern`. Given the value and the row, it returns a message to
|
|
325
|
+
* refuse the value with, or nothing to accept it, or a promise of either. A
|
|
326
|
+
* property only, being a function.
|
|
327
|
+
*/
|
|
328
|
+
validate: ((value: unknown, row: Readonly<Record<string, unknown>>) => string | undefined | PromiseLike<string | undefined>) | undefined;
|
|
247
329
|
/**
|
|
248
330
|
* Where the content of this column's cells sits from top to bottom, when a
|
|
249
331
|
* row is taller than it: `start`, `center` or `end`.
|