@prismora/elements 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +21 -2
- package/components.json +15600 -0
- package/custom-elements.json +56320 -0
- package/dist/base.d.ts +42 -0
- package/dist/base.js +62 -0
- package/dist/catalog.d.ts +33 -0
- package/dist/catalog.js +803 -0
- package/dist/components/accordion.d.ts +31 -0
- package/dist/components/accordion.js +63 -0
- package/dist/components/alert.d.ts +27 -0
- package/dist/components/alert.js +40 -0
- package/dist/components/avatar-group.d.ts +23 -0
- package/dist/components/avatar-group.js +43 -0
- package/dist/components/avatar.d.ts +24 -0
- package/dist/components/avatar.js +43 -0
- package/dist/components/back-to-top.d.ts +32 -0
- package/dist/components/back-to-top.js +50 -0
- package/dist/components/badge.d.ts +17 -0
- package/dist/components/badge.js +20 -0
- package/dist/components/banner.d.ts +34 -0
- package/dist/components/banner.js +54 -0
- package/dist/components/breadcrumb.d.ts +42 -0
- package/dist/components/breadcrumb.js +63 -0
- package/dist/components/button-group.d.ts +14 -0
- package/dist/components/button-group.js +28 -0
- package/dist/components/button.d.ts +59 -0
- package/dist/components/button.js +162 -0
- package/dist/components/calendar.d.ts +48 -0
- package/dist/components/calendar.js +296 -0
- package/dist/components/card.d.ts +23 -0
- package/dist/components/card.js +44 -0
- package/dist/components/carousel.d.ts +41 -0
- package/dist/components/carousel.js +156 -0
- package/dist/components/cascader.d.ts +70 -0
- package/dist/components/cascader.js +220 -0
- package/dist/components/chart.d.ts +59 -0
- package/dist/components/chart.js +267 -0
- package/dist/components/chat.d.ts +98 -0
- package/dist/components/chat.js +134 -0
- package/dist/components/checkbox-group.d.ts +48 -0
- package/dist/components/checkbox-group.js +111 -0
- package/dist/components/checkbox.d.ts +23 -0
- package/dist/components/checkbox.js +70 -0
- package/dist/components/code-block.d.ts +46 -0
- package/dist/components/code-block.js +86 -0
- package/dist/components/color-picker.d.ts +46 -0
- package/dist/components/color-picker.js +292 -0
- package/dist/components/combobox.d.ts +89 -0
- package/dist/components/combobox.js +384 -0
- package/dist/components/command.d.ts +96 -0
- package/dist/components/command.js +289 -0
- package/dist/components/context-menu.d.ts +23 -0
- package/dist/components/context-menu.js +110 -0
- package/dist/components/copy-button.d.ts +33 -0
- package/dist/components/copy-button.js +62 -0
- package/dist/components/countdown.d.ts +36 -0
- package/dist/components/countdown.js +56 -0
- package/dist/components/data-table.d.ts +180 -0
- package/dist/components/data-table.js +1060 -0
- package/dist/components/date-picker.d.ts +47 -0
- package/dist/components/date-picker.js +267 -0
- package/dist/components/description-list.d.ts +38 -0
- package/dist/components/description-list.js +41 -0
- package/dist/components/dialog.d.ts +47 -0
- package/dist/components/dialog.js +189 -0
- package/dist/components/divider.d.ts +16 -0
- package/dist/components/divider.js +23 -0
- package/dist/components/drawer.d.ts +19 -0
- package/dist/components/drawer.js +27 -0
- package/dist/components/editor.d.ts +50 -0
- package/dist/components/editor.js +474 -0
- package/dist/components/empty-state.d.ts +24 -0
- package/dist/components/empty-state.js +27 -0
- package/dist/components/file-upload.d.ts +56 -0
- package/dist/components/file-upload.js +176 -0
- package/dist/components/form-control.d.ts +69 -0
- package/dist/components/form-control.js +134 -0
- package/dist/components/form.d.ts +38 -0
- package/dist/components/form.js +161 -0
- package/dist/components/format-number.d.ts +37 -0
- package/dist/components/format-number.js +86 -0
- package/dist/components/icon.d.ts +34 -0
- package/dist/components/icon.js +47 -0
- package/dist/components/image.d.ts +44 -0
- package/dist/components/image.js +53 -0
- package/dist/components/indicator.d.ts +41 -0
- package/dist/components/indicator.js +65 -0
- package/dist/components/inline-edit.d.ts +45 -0
- package/dist/components/inline-edit.js +129 -0
- package/dist/components/input.d.ts +55 -0
- package/dist/components/input.js +186 -0
- package/dist/components/kbd.d.ts +15 -0
- package/dist/components/kbd.js +18 -0
- package/dist/components/list.d.ts +68 -0
- package/dist/components/list.js +180 -0
- package/dist/components/menu.d.ts +22 -0
- package/dist/components/menu.js +182 -0
- package/dist/components/menubar.d.ts +20 -0
- package/dist/components/menubar.js +120 -0
- package/dist/components/meter.d.ts +38 -0
- package/dist/components/meter.js +48 -0
- package/dist/components/nav.d.ts +91 -0
- package/dist/components/nav.js +228 -0
- package/dist/components/number-input.d.ts +26 -0
- package/dist/components/number-input.js +70 -0
- package/dist/components/pagination.d.ts +44 -0
- package/dist/components/pagination.js +94 -0
- package/dist/components/pin-input.d.ts +25 -0
- package/dist/components/pin-input.js +128 -0
- package/dist/components/popover.d.ts +23 -0
- package/dist/components/popover.js +140 -0
- package/dist/components/progress.d.ts +26 -0
- package/dist/components/progress.js +66 -0
- package/dist/components/pull-refresh.d.ts +41 -0
- package/dist/components/pull-refresh.js +101 -0
- package/dist/components/qr-code.d.ts +33 -0
- package/dist/components/qr-code.js +54 -0
- package/dist/components/radio-group.d.ts +37 -0
- package/dist/components/radio-group.js +82 -0
- package/dist/components/range-slider.d.ts +46 -0
- package/dist/components/range-slider.js +95 -0
- package/dist/components/rating.d.ts +38 -0
- package/dist/components/rating.js +80 -0
- package/dist/components/relative-time.d.ts +31 -0
- package/dist/components/relative-time.js +51 -0
- package/dist/components/scheduler.d.ts +84 -0
- package/dist/components/scheduler.js +187 -0
- package/dist/components/segmented.d.ts +58 -0
- package/dist/components/segmented.js +129 -0
- package/dist/components/select.d.ts +62 -0
- package/dist/components/select.js +140 -0
- package/dist/components/share-button.d.ts +37 -0
- package/dist/components/share-button.js +60 -0
- package/dist/components/signature.d.ts +54 -0
- package/dist/components/signature.js +152 -0
- package/dist/components/skeleton.d.ts +21 -0
- package/dist/components/skeleton.js +26 -0
- package/dist/components/slider.d.ts +31 -0
- package/dist/components/slider.js +80 -0
- package/dist/components/sortable.d.ts +22 -0
- package/dist/components/sortable.js +196 -0
- package/dist/components/sparkline.d.ts +28 -0
- package/dist/components/sparkline.js +46 -0
- package/dist/components/spinner.d.ts +16 -0
- package/dist/components/spinner.js +22 -0
- package/dist/components/splitter.d.ts +28 -0
- package/dist/components/splitter.js +89 -0
- package/dist/components/stat.d.ts +28 -0
- package/dist/components/stat.js +33 -0
- package/dist/components/steps.d.ts +53 -0
- package/dist/components/steps.js +91 -0
- package/dist/components/switch.d.ts +12 -0
- package/dist/components/switch.js +18 -0
- package/dist/components/table.d.ts +58 -0
- package/dist/components/table.js +96 -0
- package/dist/components/tabs.d.ts +62 -0
- package/dist/components/tabs.js +310 -0
- package/dist/components/tag.d.ts +32 -0
- package/dist/components/tag.js +58 -0
- package/dist/components/textarea.d.ts +25 -0
- package/dist/components/textarea.js +56 -0
- package/dist/components/theme-switch.d.ts +51 -0
- package/dist/components/theme-switch.js +85 -0
- package/dist/components/time-picker.d.ts +39 -0
- package/dist/components/time-picker.js +257 -0
- package/dist/components/timeline.d.ts +38 -0
- package/dist/components/timeline.js +56 -0
- package/dist/components/toaster.d.ts +25 -0
- package/dist/components/toaster.js +44 -0
- package/dist/components/toggle-group.d.ts +70 -0
- package/dist/components/toggle-group.js +172 -0
- package/dist/components/toolbar.d.ts +23 -0
- package/dist/components/toolbar.js +81 -0
- package/dist/components/tooltip.d.ts +18 -0
- package/dist/components/tooltip.js +92 -0
- package/dist/components/tour.d.ts +41 -0
- package/dist/components/tour.js +197 -0
- package/dist/components/transfer.d.ts +57 -0
- package/dist/components/transfer.js +161 -0
- package/dist/components/tree-select.d.ts +66 -0
- package/dist/components/tree-select.js +282 -0
- package/dist/components/tree.d.ts +129 -0
- package/dist/components/tree.js +427 -0
- package/dist/components/virtual-list.d.ts +41 -0
- package/dist/components/virtual-list.js +77 -0
- package/dist/confirm.d.ts +21 -0
- package/dist/confirm.js +69 -0
- package/dist/count.d.ts +5 -0
- package/dist/count.js +12 -0
- package/dist/data-table/icons.d.ts +8 -0
- package/dist/data-table/icons.js +10 -0
- package/dist/data-table/logic.d.ts +33 -0
- package/dist/data-table/logic.js +141 -0
- package/dist/data-table/strings.d.ts +37 -0
- package/dist/data-table/strings.js +36 -0
- package/dist/data-table/types.d.ts +76 -0
- package/dist/data-table/types.js +1 -0
- package/dist/define.d.ts +2 -0
- package/dist/define.js +2 -0
- package/dist/field-validity.d.ts +42 -0
- package/dist/field-validity.js +58 -0
- package/dist/floating.d.ts +13 -0
- package/dist/floating.js +65 -0
- package/dist/highlight.d.ts +11 -0
- package/dist/highlight.js +103 -0
- package/dist/id.d.ts +2 -0
- package/dist/id.js +3 -0
- package/dist/index.d.ts +102 -0
- package/dist/index.js +102 -0
- package/dist/manifest.d.ts +51 -0
- package/dist/manifest.js +11 -0
- package/dist/named-icon.d.ts +8 -0
- package/dist/named-icon.js +8 -0
- package/dist/patterns/account.d.ts +6 -0
- package/dist/patterns/account.js +137 -0
- package/dist/patterns/app.d.ts +7 -0
- package/dist/patterns/app.js +351 -0
- package/dist/patterns/commerce.d.ts +4 -0
- package/dist/patterns/commerce.js +200 -0
- package/dist/patterns/flows.d.ts +3 -0
- package/dist/patterns/flows.js +100 -0
- package/dist/patterns/index.d.ts +9 -0
- package/dist/patterns/index.js +29 -0
- package/dist/patterns/marketing.d.ts +4 -0
- package/dist/patterns/marketing.js +173 -0
- package/dist/patterns/more.d.ts +15 -0
- package/dist/patterns/more.js +581 -0
- package/dist/patterns/shell.d.ts +9 -0
- package/dist/patterns/shell.js +48 -0
- package/dist/patterns/types.d.ts +19 -0
- package/dist/patterns/types.js +1 -0
- package/dist/position.d.ts +2 -0
- package/dist/position.js +33 -0
- package/dist/prismora.standalone.js +5222 -0
- package/dist/prismora.standalone.js.map +199 -0
- package/dist/qr.d.ts +14 -0
- package/dist/qr.js +258 -0
- package/dist/register.d.ts +8 -0
- package/dist/register.js +21 -0
- package/dist/registry.d.ts +203 -0
- package/dist/registry.js +203 -0
- package/dist/remote.d.ts +58 -0
- package/dist/remote.js +130 -0
- package/dist/sheet.d.ts +34 -0
- package/dist/sheet.js +153 -0
- package/dist/styles/accordion.d.ts +2 -0
- package/dist/styles/accordion.js +3 -0
- package/dist/styles/alert.d.ts +2 -0
- package/dist/styles/alert.js +3 -0
- package/dist/styles/avatar.d.ts +2 -0
- package/dist/styles/avatar.js +3 -0
- package/dist/styles/badge.d.ts +2 -0
- package/dist/styles/badge.js +3 -0
- package/dist/styles/banner.d.ts +2 -0
- package/dist/styles/banner.js +3 -0
- package/dist/styles/breadcrumb.d.ts +2 -0
- package/dist/styles/breadcrumb.js +3 -0
- package/dist/styles/button.d.ts +2 -0
- package/dist/styles/button.js +3 -0
- package/dist/styles/calendar.d.ts +2 -0
- package/dist/styles/calendar.js +3 -0
- package/dist/styles/card.d.ts +2 -0
- package/dist/styles/card.js +3 -0
- package/dist/styles/carousel.d.ts +2 -0
- package/dist/styles/carousel.js +3 -0
- package/dist/styles/chart.d.ts +2 -0
- package/dist/styles/chart.js +3 -0
- package/dist/styles/chat.d.ts +2 -0
- package/dist/styles/chat.js +3 -0
- package/dist/styles/checkbox.d.ts +2 -0
- package/dist/styles/checkbox.js +3 -0
- package/dist/styles/color-picker.d.ts +2 -0
- package/dist/styles/color-picker.js +3 -0
- package/dist/styles/combobox.d.ts +2 -0
- package/dist/styles/combobox.js +3 -0
- package/dist/styles/command.d.ts +2 -0
- package/dist/styles/command.js +3 -0
- package/dist/styles/data-table.d.ts +2 -0
- package/dist/styles/data-table.js +3 -0
- package/dist/styles/description-list.d.ts +2 -0
- package/dist/styles/description-list.js +3 -0
- package/dist/styles/dialog.d.ts +2 -0
- package/dist/styles/dialog.js +3 -0
- package/dist/styles/drawer.d.ts +2 -0
- package/dist/styles/drawer.js +3 -0
- package/dist/styles/editor.d.ts +2 -0
- package/dist/styles/editor.js +3 -0
- package/dist/styles/empty-state.d.ts +2 -0
- package/dist/styles/empty-state.js +3 -0
- package/dist/styles/extras.d.ts +2 -0
- package/dist/styles/extras.js +3 -0
- package/dist/styles/field.d.ts +2 -0
- package/dist/styles/field.js +3 -0
- package/dist/styles/file-upload.d.ts +2 -0
- package/dist/styles/file-upload.js +3 -0
- package/dist/styles/foundation.d.ts +2 -0
- package/dist/styles/foundation.js +3 -0
- package/dist/styles/helpers.d.ts +2 -0
- package/dist/styles/helpers.js +3 -0
- package/dist/styles/icon.d.ts +2 -0
- package/dist/styles/icon.js +3 -0
- package/dist/styles/image.d.ts +2 -0
- package/dist/styles/image.js +3 -0
- package/dist/styles/indicator.d.ts +2 -0
- package/dist/styles/indicator.js +3 -0
- package/dist/styles/input.d.ts +2 -0
- package/dist/styles/input.js +3 -0
- package/dist/styles/kbd.d.ts +2 -0
- package/dist/styles/kbd.js +3 -0
- package/dist/styles/list.d.ts +2 -0
- package/dist/styles/list.js +3 -0
- package/dist/styles/listbox.d.ts +2 -0
- package/dist/styles/listbox.js +3 -0
- package/dist/styles/meter.d.ts +2 -0
- package/dist/styles/meter.js +3 -0
- package/dist/styles/nav.d.ts +2 -0
- package/dist/styles/nav.js +3 -0
- package/dist/styles/number-input.d.ts +2 -0
- package/dist/styles/number-input.js +3 -0
- package/dist/styles/overlay.d.ts +2 -0
- package/dist/styles/overlay.js +3 -0
- package/dist/styles/pagination.d.ts +2 -0
- package/dist/styles/pagination.js +3 -0
- package/dist/styles/pickers.d.ts +2 -0
- package/dist/styles/pickers.js +3 -0
- package/dist/styles/pin-input.d.ts +2 -0
- package/dist/styles/pin-input.js +3 -0
- package/dist/styles/popover.d.ts +2 -0
- package/dist/styles/popover.js +3 -0
- package/dist/styles/progress.d.ts +2 -0
- package/dist/styles/progress.js +3 -0
- package/dist/styles/pull-refresh.d.ts +2 -0
- package/dist/styles/pull-refresh.js +3 -0
- package/dist/styles/range-slider.d.ts +2 -0
- package/dist/styles/range-slider.js +3 -0
- package/dist/styles/rating.d.ts +2 -0
- package/dist/styles/rating.js +3 -0
- package/dist/styles/scheduler.d.ts +2 -0
- package/dist/styles/scheduler.js +3 -0
- package/dist/styles/segmented.d.ts +2 -0
- package/dist/styles/segmented.js +3 -0
- package/dist/styles/select.d.ts +2 -0
- package/dist/styles/select.js +3 -0
- package/dist/styles/separator.d.ts +2 -0
- package/dist/styles/separator.js +3 -0
- package/dist/styles/sheet.d.ts +2 -0
- package/dist/styles/sheet.js +3 -0
- package/dist/styles/skeleton.d.ts +2 -0
- package/dist/styles/skeleton.js +3 -0
- package/dist/styles/slider.d.ts +2 -0
- package/dist/styles/slider.js +3 -0
- package/dist/styles/sortable.d.ts +2 -0
- package/dist/styles/sortable.js +3 -0
- package/dist/styles/spinner.d.ts +2 -0
- package/dist/styles/spinner.js +3 -0
- package/dist/styles/splitter.d.ts +2 -0
- package/dist/styles/splitter.js +3 -0
- package/dist/styles/stat.d.ts +2 -0
- package/dist/styles/stat.js +3 -0
- package/dist/styles/steps.d.ts +2 -0
- package/dist/styles/steps.js +3 -0
- package/dist/styles/surface.d.ts +2 -0
- package/dist/styles/surface.js +3 -0
- package/dist/styles/switch.d.ts +2 -0
- package/dist/styles/switch.js +3 -0
- package/dist/styles/table.d.ts +2 -0
- package/dist/styles/table.js +3 -0
- package/dist/styles/tabs.d.ts +2 -0
- package/dist/styles/tabs.js +3 -0
- package/dist/styles/tag.d.ts +2 -0
- package/dist/styles/tag.js +3 -0
- package/dist/styles/time-picker.d.ts +2 -0
- package/dist/styles/time-picker.js +3 -0
- package/dist/styles/timeline.d.ts +2 -0
- package/dist/styles/timeline.js +3 -0
- package/dist/styles/toast.d.ts +2 -0
- package/dist/styles/toast.js +3 -0
- package/dist/styles/toggle.d.ts +2 -0
- package/dist/styles/toggle.js +3 -0
- package/dist/styles/toolbar.d.ts +2 -0
- package/dist/styles/toolbar.js +3 -0
- package/dist/styles/tooltip.d.ts +2 -0
- package/dist/styles/tooltip.js +3 -0
- package/dist/styles/tree.d.ts +2 -0
- package/dist/styles/tree.js +3 -0
- package/dist/table-core.d.ts +75 -0
- package/dist/table-core.js +205 -0
- package/dist/toast.d.ts +42 -0
- package/dist/toast.js +206 -0
- package/dist/top-layer.d.ts +4 -0
- package/dist/top-layer.js +33 -0
- package/package.json +101 -4
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { css, html, nothing } from 'lit';
|
|
2
|
+
import { PmElement, defineElement } from '../base.js';
|
|
3
|
+
import { FieldValidity } from '../field-validity.js';
|
|
4
|
+
import buttonCss from '../styles/button.js';
|
|
5
|
+
import fieldCss from '../styles/field.js';
|
|
6
|
+
import inputCss from '../styles/input.js';
|
|
7
|
+
import listboxCss from '../styles/listbox.js';
|
|
8
|
+
import pickersCss from '../styles/pickers.js';
|
|
9
|
+
/**
|
|
10
|
+
* Transfer list: move items between "available" and "selected" (assign permissions, pick table columns).
|
|
11
|
+
*
|
|
12
|
+
* Tick items and use the arrow buttons, or double-click an item to move it. In each list: Up and Down move, Space
|
|
13
|
+
* ticks, Enter moves the ticked items across, Ctrl+A ticks all. Form-associated: submits one entry per selected item.
|
|
14
|
+
* @tag pm-transfer
|
|
15
|
+
* @fires pm-change - The selection changed. detail: { value }
|
|
16
|
+
* @example <pm-transfer label="Columns" name="columns" options='[{"value":"name","label":"Name"},{"value":"email","label":"Email"}]' value='["name"]'></pm-transfer>
|
|
17
|
+
*/
|
|
18
|
+
export class PmTransfer extends PmElement {
|
|
19
|
+
static { this.componentName = 'transfer'; }
|
|
20
|
+
static { this.formAssociated = true; }
|
|
21
|
+
static { this.styles = [...PmElement.styles, fieldCss, inputCss, buttonCss, listboxCss, pickersCss, css `:host { display: block; } :host([hidden]) { display: none; }`]; }
|
|
22
|
+
static { this.properties = {
|
|
23
|
+
options: { type: Array }, value: { type: Array }, name: { reflect: true }, label: {}, hint: {}, error: {},
|
|
24
|
+
required: { type: Boolean, reflect: true }, disabled: { type: Boolean, reflect: true }, searchable: { type: Boolean },
|
|
25
|
+
sourceLabel: { attribute: 'source-label' }, targetLabel: { attribute: 'target-label' }, height: {},
|
|
26
|
+
_ticked: { state: true }, _active: { state: true }, _query: { state: true },
|
|
27
|
+
}; }
|
|
28
|
+
#internals = this.attachInternals();
|
|
29
|
+
#field = new FieldValidity(this, this.#internals, {
|
|
30
|
+
hint: () => this.hint, error: () => this.error, missing: () => this.required && !this.value.length && !this.disabled,
|
|
31
|
+
missingMessage: 'Please select at least one item.', anchor: () => this.renderRoot.querySelector('.pm-listbox'),
|
|
32
|
+
});
|
|
33
|
+
#default = [];
|
|
34
|
+
constructor() {
|
|
35
|
+
super();
|
|
36
|
+
this.options = [];
|
|
37
|
+
this.value = [];
|
|
38
|
+
this.label = 'Items';
|
|
39
|
+
this.required = false;
|
|
40
|
+
this.disabled = false;
|
|
41
|
+
this.searchable = false;
|
|
42
|
+
this.sourceLabel = 'Available';
|
|
43
|
+
this.targetLabel = 'Selected';
|
|
44
|
+
this._ticked = { source: [], target: [] };
|
|
45
|
+
this._active = { source: 0, target: 0 };
|
|
46
|
+
this._query = { source: '', target: '' };
|
|
47
|
+
}
|
|
48
|
+
connectedCallback() { super.connectedCallback(); this.#default = [...this.value]; }
|
|
49
|
+
formResetCallback() { this.value = [...this.#default]; this._ticked = { source: [], target: [] }; this.#field.reset(); }
|
|
50
|
+
formDisabledCallback(d) { this.disabled = d; }
|
|
51
|
+
updated() {
|
|
52
|
+
const data = new FormData();
|
|
53
|
+
if (this.name)
|
|
54
|
+
for (const v of this.value)
|
|
55
|
+
data.append(this.name, v);
|
|
56
|
+
this.#internals.setFormValue(this.name && this.value.length ? data : null);
|
|
57
|
+
}
|
|
58
|
+
#list(side) {
|
|
59
|
+
const chosen = new Set(this.value);
|
|
60
|
+
const all = side === 'target'
|
|
61
|
+
? this.value.map((v) => this.options.find((o) => o.value === v)).filter((o) => !!o)
|
|
62
|
+
: this.options.filter((o) => !chosen.has(o.value));
|
|
63
|
+
const q = this._query[side].trim().toLowerCase();
|
|
64
|
+
return q ? all.filter((o) => o.label.toLowerCase().includes(q)) : all;
|
|
65
|
+
}
|
|
66
|
+
/** Move values to the selected list (`to = 'target'`) or back (`'source'`). */
|
|
67
|
+
move(values, to) {
|
|
68
|
+
if (this.disabled || !values.length)
|
|
69
|
+
return;
|
|
70
|
+
const movable = values.filter((v) => !this.options.find((o) => o.value === v)?.disabled);
|
|
71
|
+
const next = to === 'target' ? [...this.value, ...movable.filter((v) => !this.value.includes(v))] : this.value.filter((v) => !movable.includes(v));
|
|
72
|
+
if (next.length === this.value.length && next.every((v, i) => v === this.value[i]))
|
|
73
|
+
return;
|
|
74
|
+
this.value = next;
|
|
75
|
+
this._ticked = { source: [], target: [] };
|
|
76
|
+
this.#field.touch();
|
|
77
|
+
this.emit('pm-change', { value: [...next] });
|
|
78
|
+
}
|
|
79
|
+
#tick(side, v, on) {
|
|
80
|
+
const has = this._ticked[side].includes(v);
|
|
81
|
+
const want = on ?? !has;
|
|
82
|
+
this._ticked = { ...this._ticked, [side]: want ? [...new Set([...this._ticked[side], v])] : this._ticked[side].filter((x) => x !== v) };
|
|
83
|
+
}
|
|
84
|
+
#onKey(side, e) {
|
|
85
|
+
const list = this.#list(side);
|
|
86
|
+
const i = Math.min(this._active[side], list.length - 1);
|
|
87
|
+
const go = (n) => {
|
|
88
|
+
e.preventDefault();
|
|
89
|
+
this._active = { ...this._active, [side]: Math.max(0, Math.min(list.length - 1, n)) };
|
|
90
|
+
this.updateComplete.then(() => this.renderRoot.querySelector(`[data-side="${side}"] [data-active]`)?.scrollIntoView({ block: 'nearest' }));
|
|
91
|
+
};
|
|
92
|
+
if (e.key === 'ArrowDown')
|
|
93
|
+
go(i + 1);
|
|
94
|
+
else if (e.key === 'ArrowUp')
|
|
95
|
+
go(i - 1);
|
|
96
|
+
else if (e.key === 'Home')
|
|
97
|
+
go(0);
|
|
98
|
+
else if (e.key === 'End')
|
|
99
|
+
go(list.length - 1);
|
|
100
|
+
else if (e.key === ' ') {
|
|
101
|
+
e.preventDefault();
|
|
102
|
+
const o = list[i];
|
|
103
|
+
if (o && !o.disabled)
|
|
104
|
+
this.#tick(side, o.value);
|
|
105
|
+
}
|
|
106
|
+
else if (e.key === 'a' && (e.ctrlKey || e.metaKey)) {
|
|
107
|
+
e.preventDefault();
|
|
108
|
+
this._ticked = { ...this._ticked, [side]: list.filter((o) => !o.disabled).map((o) => o.value) };
|
|
109
|
+
}
|
|
110
|
+
else if (e.key === 'Enter') {
|
|
111
|
+
e.preventDefault();
|
|
112
|
+
const ticked = this._ticked[side];
|
|
113
|
+
this.move(ticked.length ? ticked : list[i] ? [list[i].value] : [], side === 'source' ? 'target' : 'source');
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
#pane(side) {
|
|
117
|
+
const list = this.#list(side);
|
|
118
|
+
const ticked = this._ticked[side];
|
|
119
|
+
const active = Math.min(this._active[side], list.length - 1);
|
|
120
|
+
const title = side === 'source' ? this.sourceLabel : this.targetLabel;
|
|
121
|
+
const id = `lb-${side}`;
|
|
122
|
+
return html `<div class="pm-transfer-pane" part="pane" data-side=${side}>
|
|
123
|
+
<div class="pm-transfer-head"><span id="${id}-t">${title}</span><span class="pm-transfer-count">${ticked.length ? `${ticked.length} of ` : ''}${list.length}</span></div>
|
|
124
|
+
${this.searchable ? html `<div class="pm-transfer-search"><input class="pm-input" data-size="sm" type="search" aria-label="Filter ${title}" placeholder="Filter…" .value=${this._query[side]}
|
|
125
|
+
?disabled=${this.disabled} @input=${(e) => { this._query = { ...this._query, [side]: e.target.value }; }} /></div>` : nothing}
|
|
126
|
+
<ul class="pm-listbox" role=${list.length ? 'listbox' : 'group'} id=${id} tabindex=${this.disabled ? -1 : 0} aria-multiselectable=${list.length ? 'true' : nothing} aria-labelledby="l ${id}-t"
|
|
127
|
+
aria-describedby=${side === 'target' ? this.#field.describedBy ?? nothing : nothing}
|
|
128
|
+
aria-activedescendant=${list.length ? `${id}-${active}` : nothing} @keydown=${(e) => this.#onKey(side, e)}>
|
|
129
|
+
${list.map((o, i) => html `<li class="pm-option" role="option" id="${id}-${i}" aria-selected=${String(ticked.includes(o.value))} aria-disabled=${o.disabled ? 'true' : nothing}
|
|
130
|
+
?data-active=${i === active}
|
|
131
|
+
@click=${() => { if (this.disabled || o.disabled)
|
|
132
|
+
return; this._active = { ...this._active, [side]: i }; this.#tick(side, o.value); }}
|
|
133
|
+
@dblclick=${() => { if (!o.disabled)
|
|
134
|
+
this.move([o.value], side === 'source' ? 'target' : 'source'); }}>
|
|
135
|
+
<span class="pm-option-check" aria-hidden="true">✓</span><span class="pm-option-label">${o.label}</span></li>`)}
|
|
136
|
+
${list.length ? nothing : html `<li class="pm-listbox-empty" role="presentation">${this._query[side] ? 'No matches' : side === 'target' ? 'Nothing selected' : 'Nothing left'}</li>`}
|
|
137
|
+
</ul>
|
|
138
|
+
</div>`;
|
|
139
|
+
}
|
|
140
|
+
render() {
|
|
141
|
+
const source = this.#list('source').filter((o) => !o.disabled).map((o) => o.value);
|
|
142
|
+
const target = this.#list('target').map((o) => o.value);
|
|
143
|
+
const btn = (label, glyph, values, to) => html `<button type="button" class="pm-button" data-variant="outline" data-tone="neutral" data-size="sm" data-icon
|
|
144
|
+
aria-label=${label} title=${label} ?disabled=${this.disabled || !values.length} @click=${() => this.move(values, to)}><span aria-hidden="true">${glyph}</span></button>`;
|
|
145
|
+
return html `<div class="pm-field" part="field">
|
|
146
|
+
<span class="pm-label" id="l" part="label" ?data-required=${this.required}>${this.label}</span>
|
|
147
|
+
<div class="pm-transfer-wrap"><div class="pm-transfer" part="base" role="group" aria-labelledby="l" ?data-invalid=${this.#field.invalid} style=${this.height ? `--_height: ${this.height}` : nothing}>
|
|
148
|
+
${this.#pane('source')}
|
|
149
|
+
<div class="pm-transfer-actions">
|
|
150
|
+
${btn(`Add all to ${this.targetLabel}`, '»', source, 'target')}
|
|
151
|
+
${btn(`Add ticked to ${this.targetLabel}`, '›', this._ticked.source, 'target')}
|
|
152
|
+
${btn(`Remove ticked from ${this.targetLabel}`, '‹', this._ticked.target, 'source')}
|
|
153
|
+
${btn(`Remove all from ${this.targetLabel}`, '«', target, 'source')}
|
|
154
|
+
</div>
|
|
155
|
+
${this.#pane('target')}
|
|
156
|
+
</div></div>
|
|
157
|
+
${this.#field.messages()}
|
|
158
|
+
</div>`;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
defineElement('pm-transfer', PmTransfer);
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { type PropertyDeclarations, type PropertyValues } from 'lit';
|
|
2
|
+
import { PmElement } from '../base.js';
|
|
3
|
+
export interface TreeOption {
|
|
4
|
+
value: string;
|
|
5
|
+
label: string;
|
|
6
|
+
disabled?: boolean;
|
|
7
|
+
children?: TreeOption[];
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Tree select: choose from a hierarchy shown as an expandable tree in a dropdown (folders, departments, categories).
|
|
11
|
+
*
|
|
12
|
+
* Single choice by default; `multiple` adds tick boxes, and ticking a parent ticks everything under it. Up and
|
|
13
|
+
* Down move, Right opens a branch, Left closes it, Enter or Space chooses, typing in the search box filters.
|
|
14
|
+
* Form-associated: submits the value (one entry per ticked item when `multiple`).
|
|
15
|
+
* @tag pm-tree-select
|
|
16
|
+
* @fires pm-change - The selection changed. detail: { value } (a string, or an array of strings when `multiple`)
|
|
17
|
+
* @example <pm-tree-select label="Folder" name="folder" options='[{"value":"docs","label":"Documents","children":[{"value":"inv","label":"Invoices"}]}]'></pm-tree-select>
|
|
18
|
+
*/
|
|
19
|
+
export declare class PmTreeSelect extends PmElement {
|
|
20
|
+
#private;
|
|
21
|
+
static componentName: string;
|
|
22
|
+
static formAssociated: boolean;
|
|
23
|
+
static shadowRootOptions: {
|
|
24
|
+
delegatesFocus: boolean;
|
|
25
|
+
clonable?: boolean;
|
|
26
|
+
customElementRegistry?: CustomElementRegistry;
|
|
27
|
+
mode: ShadowRootMode;
|
|
28
|
+
serializable?: boolean;
|
|
29
|
+
slotAssignment?: SlotAssignmentMode;
|
|
30
|
+
};
|
|
31
|
+
static styles: import("lit").CSSResult[];
|
|
32
|
+
static properties: PropertyDeclarations;
|
|
33
|
+
/** Nested options: `{ value, label, children? }`. Values must be unique across all levels. */
|
|
34
|
+
options: TreeOption[];
|
|
35
|
+
/** The chosen value (single choice). */
|
|
36
|
+
value: string;
|
|
37
|
+
/** The ticked values (with `multiple`): the items without children. */
|
|
38
|
+
values: string[];
|
|
39
|
+
/** Allow several choices, with tick boxes. */
|
|
40
|
+
multiple: boolean;
|
|
41
|
+
name?: string;
|
|
42
|
+
label: string;
|
|
43
|
+
placeholder: string;
|
|
44
|
+
/** Help text under the field. */
|
|
45
|
+
hint?: string;
|
|
46
|
+
/** Custom error message. Setting it marks the field invalid. */
|
|
47
|
+
error?: string;
|
|
48
|
+
size?: 'sm' | 'md' | 'lg';
|
|
49
|
+
required: boolean;
|
|
50
|
+
disabled: boolean;
|
|
51
|
+
/** Show a search box that filters the tree. */
|
|
52
|
+
searchable: boolean;
|
|
53
|
+
/** Start with every branch open. */
|
|
54
|
+
expandAll: boolean;
|
|
55
|
+
_open: boolean;
|
|
56
|
+
_expanded: string[];
|
|
57
|
+
_active: string;
|
|
58
|
+
_query: string;
|
|
59
|
+
constructor();
|
|
60
|
+
connectedCallback(): void;
|
|
61
|
+
disconnectedCallback(): void;
|
|
62
|
+
formResetCallback(): void;
|
|
63
|
+
formDisabledCallback(d: boolean): void;
|
|
64
|
+
protected updated(changed: PropertyValues<this>): void;
|
|
65
|
+
render(): import("lit").TemplateResult<1>;
|
|
66
|
+
}
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
import { css, html, nothing } from 'lit';
|
|
2
|
+
import { PmElement, defineElement } from '../base.js';
|
|
3
|
+
import { FieldValidity } from '../field-validity.js';
|
|
4
|
+
import { attachBelow, hidePopup, showPopup } from '../floating.js';
|
|
5
|
+
import fieldCss from '../styles/field.js';
|
|
6
|
+
import inputCss from '../styles/input.js';
|
|
7
|
+
import listboxCss from '../styles/listbox.js';
|
|
8
|
+
import pickersCss from '../styles/pickers.js';
|
|
9
|
+
import sheetCss from '../styles/sheet.js';
|
|
10
|
+
const leaves = (o) => (o.children?.length ? o.children.flatMap(leaves) : o.disabled ? [] : [o.value]);
|
|
11
|
+
/**
|
|
12
|
+
* Tree select: choose from a hierarchy shown as an expandable tree in a dropdown (folders, departments, categories).
|
|
13
|
+
*
|
|
14
|
+
* Single choice by default; `multiple` adds tick boxes, and ticking a parent ticks everything under it. Up and
|
|
15
|
+
* Down move, Right opens a branch, Left closes it, Enter or Space chooses, typing in the search box filters.
|
|
16
|
+
* Form-associated: submits the value (one entry per ticked item when `multiple`).
|
|
17
|
+
* @tag pm-tree-select
|
|
18
|
+
* @fires pm-change - The selection changed. detail: { value } (a string, or an array of strings when `multiple`)
|
|
19
|
+
* @example <pm-tree-select label="Folder" name="folder" options='[{"value":"docs","label":"Documents","children":[{"value":"inv","label":"Invoices"}]}]'></pm-tree-select>
|
|
20
|
+
*/
|
|
21
|
+
export class PmTreeSelect extends PmElement {
|
|
22
|
+
static { this.componentName = 'tree-select'; }
|
|
23
|
+
static { this.formAssociated = true; }
|
|
24
|
+
static { this.shadowRootOptions = { ...PmElement.shadowRootOptions, delegatesFocus: true }; }
|
|
25
|
+
static { this.styles = [...PmElement.styles, fieldCss, inputCss, listboxCss, sheetCss, pickersCss, css `:host { display: block; } :host([hidden]) { display: none; }`]; }
|
|
26
|
+
static { this.properties = {
|
|
27
|
+
options: { type: Array }, value: {}, values: { type: Array }, multiple: { type: Boolean, reflect: true }, name: { reflect: true }, label: {}, placeholder: {},
|
|
28
|
+
hint: {}, error: {}, size: { reflect: true }, required: { type: Boolean, reflect: true }, disabled: { type: Boolean, reflect: true },
|
|
29
|
+
searchable: { type: Boolean }, expandAll: { type: Boolean, attribute: 'expand-all' },
|
|
30
|
+
_open: { state: true }, _expanded: { state: true }, _active: { state: true }, _query: { state: true },
|
|
31
|
+
}; }
|
|
32
|
+
#internals = this.attachInternals();
|
|
33
|
+
#field = new FieldValidity(this, this.#internals, {
|
|
34
|
+
hint: () => this.hint, error: () => this.error, missing: () => this.required && !this.disabled && (this.multiple ? !this.values.length : !this.value),
|
|
35
|
+
missingMessage: 'Please choose an option.', anchor: () => this.renderRoot.querySelector('button'),
|
|
36
|
+
});
|
|
37
|
+
#default = { value: '', values: [] };
|
|
38
|
+
#detach;
|
|
39
|
+
constructor() {
|
|
40
|
+
super();
|
|
41
|
+
this.options = [];
|
|
42
|
+
this.value = '';
|
|
43
|
+
this.values = [];
|
|
44
|
+
this.multiple = false;
|
|
45
|
+
this.label = 'Choose';
|
|
46
|
+
this.placeholder = 'Select…';
|
|
47
|
+
this.required = false;
|
|
48
|
+
this.disabled = false;
|
|
49
|
+
this.searchable = false;
|
|
50
|
+
this.expandAll = false;
|
|
51
|
+
this._open = false;
|
|
52
|
+
this._expanded = [];
|
|
53
|
+
this._active = '';
|
|
54
|
+
this._query = '';
|
|
55
|
+
}
|
|
56
|
+
connectedCallback() {
|
|
57
|
+
super.connectedCallback();
|
|
58
|
+
this.#default = { value: this.value, values: [...this.values] };
|
|
59
|
+
this.addEventListener('focusout', this.#onFocusOut);
|
|
60
|
+
}
|
|
61
|
+
disconnectedCallback() { super.disconnectedCallback(); this.removeEventListener('focusout', this.#onFocusOut); this.#detach?.(); this.#detach = undefined; }
|
|
62
|
+
formResetCallback() { this.value = this.#default.value; this.values = [...this.#default.values]; this.#field.reset(); }
|
|
63
|
+
formDisabledCallback(d) { this.disabled = d; }
|
|
64
|
+
#onFocusOut = () => { queueMicrotask(() => { if (!this.matches(':focus-within'))
|
|
65
|
+
this.#close(); }); };
|
|
66
|
+
#all(list = this.options, depth = 0, parent) {
|
|
67
|
+
return list.flatMap((option) => [{ option, depth, parent }, ...this.#all(option.children ?? [], depth + 1, option)]);
|
|
68
|
+
}
|
|
69
|
+
/** Rows on screen: open branches only, or every match (with its parents) while searching. */
|
|
70
|
+
#rows() {
|
|
71
|
+
const q = this._query.trim().toLowerCase();
|
|
72
|
+
if (q) {
|
|
73
|
+
const keep = new Set();
|
|
74
|
+
const visit = (o, trail) => {
|
|
75
|
+
const self = o.label.toLowerCase().includes(q);
|
|
76
|
+
const below = (o.children ?? []).map((c) => visit(c, [...trail, o.value])).some(Boolean);
|
|
77
|
+
if (self || below) {
|
|
78
|
+
keep.add(o.value);
|
|
79
|
+
for (const t of trail)
|
|
80
|
+
keep.add(t);
|
|
81
|
+
}
|
|
82
|
+
return self || below;
|
|
83
|
+
};
|
|
84
|
+
for (const o of this.options)
|
|
85
|
+
visit(o, []);
|
|
86
|
+
return this.#all().filter((r) => keep.has(r.option.value));
|
|
87
|
+
}
|
|
88
|
+
const walk = (list, depth, parent) => list.flatMap((option) => [{ option, depth, parent }, ...(option.children?.length && this._expanded.includes(option.value) ? walk(option.children, depth + 1, option) : [])]);
|
|
89
|
+
return walk(this.options, 0);
|
|
90
|
+
}
|
|
91
|
+
#open() {
|
|
92
|
+
if (this._open || this.disabled)
|
|
93
|
+
return;
|
|
94
|
+
if (this.expandAll && !this._expanded.length)
|
|
95
|
+
this._expanded = this.#all().filter((r) => r.option.children?.length).map((r) => r.option.value);
|
|
96
|
+
// Open the branches that lead to the current choice, so it is visible.
|
|
97
|
+
const chosen = this.multiple ? this.values : this.value ? [this.value] : [];
|
|
98
|
+
const parents = this.#all().filter((r) => r.option.children?.length && leaves(r.option).some((v) => chosen.includes(v)) || (!this.multiple && this.#contains(r.option, this.value))).map((r) => r.option.value);
|
|
99
|
+
this._expanded = [...new Set([...this._expanded, ...parents])];
|
|
100
|
+
this._open = true;
|
|
101
|
+
this._active = (!this.multiple && this.value) || this.#rows().find((r) => !r.option.disabled)?.option.value || '';
|
|
102
|
+
if (this.searchable)
|
|
103
|
+
this.updateComplete.then(() => this.renderRoot.querySelector('.pm-tree-search input')?.focus());
|
|
104
|
+
}
|
|
105
|
+
#contains(o, value) { return !!value && (o.children ?? []).some((c) => c.value === value || this.#contains(c, value)); }
|
|
106
|
+
#close(focus = false) {
|
|
107
|
+
if (!this._open)
|
|
108
|
+
return;
|
|
109
|
+
this._open = false;
|
|
110
|
+
this._query = '';
|
|
111
|
+
if (focus)
|
|
112
|
+
this.renderRoot.querySelector('button')?.focus();
|
|
113
|
+
}
|
|
114
|
+
#toggleBranch(v, open) {
|
|
115
|
+
const has = this._expanded.includes(v);
|
|
116
|
+
if ((open ?? !has) === has)
|
|
117
|
+
return;
|
|
118
|
+
this._expanded = has ? this._expanded.filter((x) => x !== v) : [...this._expanded, v];
|
|
119
|
+
}
|
|
120
|
+
/** aria-checked of a row: true, false, or mixed when only part of a branch is ticked. */
|
|
121
|
+
#checked(o) {
|
|
122
|
+
const own = leaves(o);
|
|
123
|
+
const n = own.filter((v) => this.values.includes(v)).length;
|
|
124
|
+
return n === 0 ? 'false' : n === own.length ? 'true' : 'mixed';
|
|
125
|
+
}
|
|
126
|
+
#choose(o) {
|
|
127
|
+
if (o.disabled)
|
|
128
|
+
return;
|
|
129
|
+
if (this.multiple) {
|
|
130
|
+
const own = leaves(o);
|
|
131
|
+
if (!own.length)
|
|
132
|
+
return;
|
|
133
|
+
const all = own.every((v) => this.values.includes(v));
|
|
134
|
+
this.values = all ? this.values.filter((v) => !own.includes(v)) : [...new Set([...this.values, ...own])];
|
|
135
|
+
this.#field.touch();
|
|
136
|
+
this.emit('pm-change', { value: [...this.values] });
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
if (o.children?.length) {
|
|
140
|
+
this.#toggleBranch(o.value);
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
this.value = o.value;
|
|
144
|
+
this.#field.touch();
|
|
145
|
+
this.emit('pm-change', { value: o.value });
|
|
146
|
+
this.#close(true);
|
|
147
|
+
}
|
|
148
|
+
#onKey = (e) => {
|
|
149
|
+
if (!this._open) {
|
|
150
|
+
if (e.key === 'ArrowDown' || e.key === 'ArrowUp') {
|
|
151
|
+
e.preventDefault();
|
|
152
|
+
this.#open();
|
|
153
|
+
}
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
const rows = this.#rows();
|
|
157
|
+
const i = rows.findIndex((r) => r.option.value === this._active);
|
|
158
|
+
const cur = rows[i];
|
|
159
|
+
const rtl = getComputedStyle(this).direction === 'rtl';
|
|
160
|
+
const forward = rtl ? 'ArrowLeft' : 'ArrowRight';
|
|
161
|
+
const back = rtl ? 'ArrowRight' : 'ArrowLeft';
|
|
162
|
+
const inSearch = e.target.localName === 'input';
|
|
163
|
+
const step = (dir) => { for (let k = i + dir; k >= 0 && k < rows.length; k += dir)
|
|
164
|
+
if (!rows[k].option.disabled) {
|
|
165
|
+
this._active = rows[k].option.value;
|
|
166
|
+
return;
|
|
167
|
+
} };
|
|
168
|
+
if (e.key === 'ArrowDown') {
|
|
169
|
+
e.preventDefault();
|
|
170
|
+
step(1);
|
|
171
|
+
}
|
|
172
|
+
else if (e.key === 'ArrowUp') {
|
|
173
|
+
e.preventDefault();
|
|
174
|
+
step(-1);
|
|
175
|
+
}
|
|
176
|
+
else if (e.key === 'Home' && !inSearch) {
|
|
177
|
+
e.preventDefault();
|
|
178
|
+
this._active = rows.find((r) => !r.option.disabled)?.option.value ?? '';
|
|
179
|
+
}
|
|
180
|
+
else if (e.key === 'End' && !inSearch) {
|
|
181
|
+
e.preventDefault();
|
|
182
|
+
this._active = [...rows].reverse().find((r) => !r.option.disabled)?.option.value ?? '';
|
|
183
|
+
}
|
|
184
|
+
else if (e.key === forward && !inSearch) {
|
|
185
|
+
e.preventDefault();
|
|
186
|
+
if (cur?.option.children?.length) {
|
|
187
|
+
if (this._expanded.includes(cur.option.value))
|
|
188
|
+
step(1);
|
|
189
|
+
else
|
|
190
|
+
this.#toggleBranch(cur.option.value, true);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
else if (e.key === back && !inSearch) {
|
|
194
|
+
e.preventDefault();
|
|
195
|
+
if (cur?.option.children?.length && this._expanded.includes(cur.option.value))
|
|
196
|
+
this.#toggleBranch(cur.option.value, false);
|
|
197
|
+
else if (cur?.parent)
|
|
198
|
+
this._active = cur.parent.value;
|
|
199
|
+
}
|
|
200
|
+
else if (e.key === 'Enter' || (e.key === ' ' && !inSearch)) {
|
|
201
|
+
e.preventDefault();
|
|
202
|
+
if (cur)
|
|
203
|
+
this.#choose(cur.option);
|
|
204
|
+
}
|
|
205
|
+
else if (e.key === 'Escape') {
|
|
206
|
+
e.preventDefault();
|
|
207
|
+
e.stopPropagation();
|
|
208
|
+
this.#close(true);
|
|
209
|
+
}
|
|
210
|
+
else if (e.key === 'Tab')
|
|
211
|
+
this.#close();
|
|
212
|
+
};
|
|
213
|
+
updated(changed) {
|
|
214
|
+
super.updated(changed);
|
|
215
|
+
if (this.multiple) {
|
|
216
|
+
const data = new FormData();
|
|
217
|
+
if (this.name)
|
|
218
|
+
for (const v of this.values)
|
|
219
|
+
data.append(this.name, v);
|
|
220
|
+
this.#internals.setFormValue(this.name && this.values.length ? data : null);
|
|
221
|
+
}
|
|
222
|
+
else
|
|
223
|
+
this.#internals.setFormValue(this.value || null);
|
|
224
|
+
const popup = this.renderRoot.querySelector('.pm-listbox-popup');
|
|
225
|
+
const trigger = this.renderRoot.querySelector('button');
|
|
226
|
+
if (!popup || !trigger)
|
|
227
|
+
return;
|
|
228
|
+
if (this._open) {
|
|
229
|
+
showPopup(popup);
|
|
230
|
+
this.#detach ??= attachBelow(popup, trigger, { sheet: true });
|
|
231
|
+
this.renderRoot.querySelector('[data-active]')?.scrollIntoView({ block: 'nearest' });
|
|
232
|
+
}
|
|
233
|
+
else {
|
|
234
|
+
this.#detach?.();
|
|
235
|
+
this.#detach = undefined;
|
|
236
|
+
hidePopup(popup);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
render() {
|
|
240
|
+
const flat = this.#all();
|
|
241
|
+
const labelOf = (v) => flat.find((r) => r.option.value === v)?.option.label ?? v;
|
|
242
|
+
const text = this.multiple ? (this.values.length === 1 ? labelOf(this.values[0]) : this.values.length ? `${labelOf(this.values[0])} and ${this.values.length - 1} more` : '') : this.value ? labelOf(this.value) : '';
|
|
243
|
+
const rows = this._open ? this.#rows() : [];
|
|
244
|
+
const searching = !!this._query.trim();
|
|
245
|
+
const invalid = this.#field.invalid;
|
|
246
|
+
return html `<div class="pm-field" part="field">
|
|
247
|
+
<span class="pm-label" id="l" part="label" ?data-required=${this.required}>${this.label}</span>
|
|
248
|
+
<button type="button" class="pm-input pm-picker-trigger" part="base" data-size=${this.size ?? nothing} role="combobox" aria-haspopup="tree" aria-expanded=${String(this._open)} aria-controls="tree"
|
|
249
|
+
aria-labelledby="l v" aria-describedby=${this.#field.describedBy ?? nothing} aria-invalid=${invalid ? 'true' : nothing} ?disabled=${this.disabled}
|
|
250
|
+
aria-activedescendant=${this._open && this._active && !this.searchable ? `t-${this._active}` : nothing}
|
|
251
|
+
@click=${() => (this._open ? this.#close() : this.#open())} @keydown=${this.#onKey}>
|
|
252
|
+
<span class="pm-picker-value" id="v" ?data-placeholder=${!text}>${text || this.placeholder}</span>
|
|
253
|
+
${this.multiple && this.values.length > 1 ? html `<span class="pm-picker-count" aria-hidden="true">${this.values.length}</span>` : nothing}
|
|
254
|
+
</button>
|
|
255
|
+
<div class="pm-listbox-popup pm-tree-panel" popover="manual" part="popup" @pointerdown=${(e) => { if (e.target.localName !== 'input')
|
|
256
|
+
e.preventDefault(); }}>
|
|
257
|
+
${this.searchable ? html `<div class="pm-tree-search"><input class="pm-input" data-size="sm" type="search" placeholder="Search…" aria-label="Search ${this.label}" role="combobox" aria-expanded="true" aria-controls="tree"
|
|
258
|
+
aria-activedescendant=${this._active ? `t-${this._active}` : nothing} .value=${this._query}
|
|
259
|
+
@input=${(e) => { this._query = e.target.value; this.updateComplete.then(() => { this._active = this.#rows().find((r) => !r.option.disabled)?.option.value ?? ''; }); }} @keydown=${this.#onKey} /></div>` : nothing}
|
|
260
|
+
<ul class="pm-listbox" id="tree" role=${rows.length ? 'tree' : 'group'} aria-labelledby="l" aria-multiselectable=${this.multiple && rows.length ? 'true' : nothing}>
|
|
261
|
+
${rows.map(({ option: o, depth }) => {
|
|
262
|
+
const branch = !!o.children?.length;
|
|
263
|
+
const open = searching || this._expanded.includes(o.value);
|
|
264
|
+
return html `<li class="pm-option" role="treeitem" id="t-${o.value}" style="--_depth: ${depth}" aria-level=${depth + 1} aria-disabled=${o.disabled ? 'true' : nothing}
|
|
265
|
+
aria-expanded=${branch ? String(open) : nothing}
|
|
266
|
+
aria-checked=${this.multiple ? this.#checked(o) : nothing} aria-selected=${this.multiple ? nothing : String(o.value === this.value)}
|
|
267
|
+
?data-active=${o.value === this._active}
|
|
268
|
+
@click=${() => { this._active = o.value; this.#choose(o); }}>
|
|
269
|
+
<span class="pm-tree-twist" aria-hidden="true" ?data-open=${open} ?data-leaf=${!branch}
|
|
270
|
+
@click=${(e) => { if (!branch)
|
|
271
|
+
return; e.stopPropagation(); this._active = o.value; this.#toggleBranch(o.value); }}></span>
|
|
272
|
+
${this.multiple ? html `<span class="pm-tree-box" aria-hidden="true"></span>` : nothing}
|
|
273
|
+
<span class="pm-option-label">${o.label}</span></li>`;
|
|
274
|
+
})}
|
|
275
|
+
${rows.length || !this._open ? nothing : html `<li class="pm-listbox-empty" role="presentation">No matches</li>`}
|
|
276
|
+
</ul>
|
|
277
|
+
</div>
|
|
278
|
+
${this.#field.messages()}
|
|
279
|
+
</div>`;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
defineElement('pm-tree-select', PmTreeSelect);
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { type PropertyDeclarations } from 'lit';
|
|
2
|
+
import { PmElement } from '../base.js';
|
|
3
|
+
/** One tree item as data (for `appendItems`, `loader` results via `mapItem`). */
|
|
4
|
+
export interface TreeItemData {
|
|
5
|
+
label: string;
|
|
6
|
+
value?: string;
|
|
7
|
+
/** Has children that load on first expand. */
|
|
8
|
+
lazy?: boolean;
|
|
9
|
+
/** Registered icon name. */
|
|
10
|
+
icon?: string;
|
|
11
|
+
children?: TreeItemData[];
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Tree view (file browsers, nested navigation).
|
|
15
|
+
*
|
|
16
|
+
* Full keyboard support per the WAI-ARIA tree pattern: ↑/↓ move, → expands or enters, ← collapses or goes to the
|
|
17
|
+
* parent, Home/End, Enter/Space select, type-ahead. `selection="checkbox"`: tri-state checkboxes that cascade to
|
|
18
|
+
* children and parents (Space toggles; `values` lists checked leaves). `filter` shows matching items and their
|
|
19
|
+
* ancestors, highlighted. `lazy` items load children on first expand (`pm-load`).
|
|
20
|
+
*
|
|
21
|
+
* Children from an API: set `src` (`src="/api/folders/{value}/children"`, `{value}` is the expanded item's value)
|
|
22
|
+
* or the `loader` property (`async (item, { signal }) => items`); the tree then builds the child items itself from
|
|
23
|
+
* `label-key`, `value-key`, `lazy-key` (has children to load), `icon-key` and `children-key` (nested items), or from
|
|
24
|
+
* `mapItem`. Failures collapse the item again and fire `pm-load-error`.
|
|
25
|
+
* @tag pm-tree
|
|
26
|
+
* @slot - `pm-tree-item` elements (nest them for children).
|
|
27
|
+
* @fires pm-select - An item was selected. detail: { value, item }
|
|
28
|
+
* @fires pm-check - Checkboxes changed. detail: { values, item, checked }
|
|
29
|
+
* @fires pm-load - A `lazy` item was expanded for the first time; append its children (done for you with `src` / `loader`). detail: { item, value }
|
|
30
|
+
* @fires pm-load-error - Loading children failed. detail: { item, value, error }
|
|
31
|
+
* @example <pm-tree label="Files"><pm-tree-item label="src" expanded><pm-tree-item label="index.ts" value="src/index.ts"></pm-tree-item></pm-tree-item><pm-tree-item label="README.md"></pm-tree-item></pm-tree>
|
|
32
|
+
*/
|
|
33
|
+
export declare class PmTree extends PmElement {
|
|
34
|
+
#private;
|
|
35
|
+
static componentName: string;
|
|
36
|
+
static styles: import("lit").CSSResult[];
|
|
37
|
+
static properties: PropertyDeclarations;
|
|
38
|
+
label?: string;
|
|
39
|
+
/** Value of the selected item. */
|
|
40
|
+
value?: string;
|
|
41
|
+
/** `single` (default) or `checkbox` (tri-state, cascading). */
|
|
42
|
+
selection?: 'single' | 'checkbox';
|
|
43
|
+
/** Show only items whose label contains this text (plus their ancestors). */
|
|
44
|
+
filter?: string;
|
|
45
|
+
/** Shown when the filter matches nothing. */
|
|
46
|
+
emptyText?: string;
|
|
47
|
+
_empty: boolean;
|
|
48
|
+
/** URL for an item's children; `{value}` is replaced with the expanded item's value. Response: JSON. */
|
|
49
|
+
src?: string;
|
|
50
|
+
/** Your own children loader (takes precedence over `src`): `async ({ value, item }, { signal }) => items`. */
|
|
51
|
+
loader?: (parent: {
|
|
52
|
+
value: string;
|
|
53
|
+
item: PmTreeItem;
|
|
54
|
+
}, ctx: {
|
|
55
|
+
signal: AbortSignal;
|
|
56
|
+
}) => Promise<unknown>;
|
|
57
|
+
/** Turn one server item into tree item data. */
|
|
58
|
+
mapItem?: (item: unknown) => TreeItemData;
|
|
59
|
+
/** Where the list is in the response (dotted path; empty = the response itself). */
|
|
60
|
+
childrenPath?: string;
|
|
61
|
+
/** Item field for the label (default `label`, then `name`, then `title`). */
|
|
62
|
+
labelKey?: string;
|
|
63
|
+
/** Item field for the value (default `value`, then `id`). */
|
|
64
|
+
valueKey?: string;
|
|
65
|
+
/** Item field that says it has children to load on expand (default `lazy`, then `hasChildren`). */
|
|
66
|
+
lazyKey?: string;
|
|
67
|
+
/** Item field with a registered icon name (default `icon`). */
|
|
68
|
+
iconKey?: string;
|
|
69
|
+
/** Item field with nested child items (default `children`). */
|
|
70
|
+
childrenKey?: string;
|
|
71
|
+
/** Values of checked leaf items (checkbox mode). */
|
|
72
|
+
get values(): string[];
|
|
73
|
+
/** Check the leaves with these values (checkbox mode). */
|
|
74
|
+
set values(v: string[]);
|
|
75
|
+
/** Check or uncheck an item and everything under it; parents become checked, unchecked or mixed. */
|
|
76
|
+
setChecked(item: PmTreeItem, checked: boolean): void;
|
|
77
|
+
connectedCallback(): void;
|
|
78
|
+
disconnectedCallback(): void;
|
|
79
|
+
/** Append tree items built from data to a parent item (or the tree). */
|
|
80
|
+
appendItems(parent: HTMLElement, items: TreeItemData[]): void;
|
|
81
|
+
render(): import("lit").TemplateResult<1>;
|
|
82
|
+
protected updated(): void;
|
|
83
|
+
/** Items currently visible (ancestors expanded), in order. */
|
|
84
|
+
visibleItems(): PmTreeItem[];
|
|
85
|
+
/** Select an item (emits pm-select). */
|
|
86
|
+
select(item: PmTreeItem): void;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Tree node. Nest `pm-tree-item`s inside to make a branch.
|
|
90
|
+
* @tag pm-tree-item
|
|
91
|
+
* @slot - Child `pm-tree-item` elements.
|
|
92
|
+
* @slot icon - Icon before the label.
|
|
93
|
+
* @slot end - Trailing content (count, badge, actions).
|
|
94
|
+
* @fires pm-toggle - Branch expanded or collapsed. detail: { expanded }
|
|
95
|
+
* @example <pm-tree-item label="Documents" expanded><pm-tree-item label="Report.pdf"></pm-tree-item></pm-tree-item>
|
|
96
|
+
*/
|
|
97
|
+
export declare class PmTreeItem extends PmElement {
|
|
98
|
+
#private;
|
|
99
|
+
static componentName: string;
|
|
100
|
+
static styles: import("lit").CSSResult[];
|
|
101
|
+
static properties: PropertyDeclarations;
|
|
102
|
+
/** Registered icon name (see `registerIcons`); an `icon` slot overrides it. */
|
|
103
|
+
icon?: string;
|
|
104
|
+
/** Checkbox state (tree `selection="checkbox"`). */
|
|
105
|
+
checked: boolean;
|
|
106
|
+
/** Some (not all) children are checked. Set by the tree. */
|
|
107
|
+
indeterminate: boolean;
|
|
108
|
+
/** Has children that load on first expand (`pm-load` on the tree). */
|
|
109
|
+
lazy: boolean;
|
|
110
|
+
/** Children are loading (cleared when they arrive). */
|
|
111
|
+
loading: boolean;
|
|
112
|
+
label?: string;
|
|
113
|
+
value?: string;
|
|
114
|
+
expanded: boolean;
|
|
115
|
+
selected: boolean;
|
|
116
|
+
disabled: boolean;
|
|
117
|
+
_hasChildren: boolean;
|
|
118
|
+
constructor();
|
|
119
|
+
get itemValue(): string;
|
|
120
|
+
get labelText(): string;
|
|
121
|
+
get isLeaf(): boolean;
|
|
122
|
+
childItems(): PmTreeItem[];
|
|
123
|
+
get depth(): number;
|
|
124
|
+
connectedCallback(): void;
|
|
125
|
+
/** Expand (true), collapse (false) or toggle. */
|
|
126
|
+
toggle(force?: boolean): void;
|
|
127
|
+
protected updated(): void;
|
|
128
|
+
render(): import("lit").TemplateResult<1>;
|
|
129
|
+
}
|