@prismora/elements 0.0.0-stage → 0.1.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/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,95 @@
|
|
|
1
|
+
import { css, html, nothing } from 'lit';
|
|
2
|
+
import { live } from 'lit/directives/live.js';
|
|
3
|
+
import { PmElement, defineElement, nextId } from '../base.js';
|
|
4
|
+
import { FieldValidity } from '../field-validity.js';
|
|
5
|
+
import fieldCss from '../styles/field.js';
|
|
6
|
+
import rangeSliderCss from '../styles/range-slider.js';
|
|
7
|
+
/**
|
|
8
|
+
* Two-thumb range slider (price filters, time windows).
|
|
9
|
+
*
|
|
10
|
+
* Value is "low,high"; with `name` both numbers are submitted under that name. Thumbs never cross and keep `min-gap`
|
|
11
|
+
* apart. Each thumb is a native range input (full keyboard support), labelled "Minimum …" / "Maximum …".
|
|
12
|
+
* @tag pm-range-slider
|
|
13
|
+
* @fires pm-input - While dragging. detail: { value, low, high }
|
|
14
|
+
* @fires pm-change - When committed. detail: { value, low, high }
|
|
15
|
+
* @example <pm-range-slider label="Price" min="0" max="500" value="100,350" step="10" show-value></pm-range-slider>
|
|
16
|
+
*/
|
|
17
|
+
export class PmRangeSlider extends PmElement {
|
|
18
|
+
static { this.componentName = 'range-slider'; }
|
|
19
|
+
static { this.formAssociated = true; }
|
|
20
|
+
static { this.styles = [...PmElement.styles, fieldCss, rangeSliderCss, css `:host { display: block; } :host([hidden]) { display: none; }`]; }
|
|
21
|
+
static { this.properties = {
|
|
22
|
+
value: { reflect: true }, name: { reflect: true }, label: {}, hint: {}, min: { type: Number }, max: { type: Number }, step: { type: Number },
|
|
23
|
+
minGap: { type: Number, attribute: 'min-gap' }, showValue: { type: Boolean, attribute: 'show-value' }, disabled: { type: Boolean, reflect: true },
|
|
24
|
+
unit: {}, error: {}, size: { reflect: true },
|
|
25
|
+
}; }
|
|
26
|
+
#internals = this.attachInternals();
|
|
27
|
+
#field = new FieldValidity(this, this.#internals, {
|
|
28
|
+
hint: () => this.hint, error: () => this.error, missing: () => false, missingMessage: '',
|
|
29
|
+
anchor: () => this.renderRoot.querySelector('input'),
|
|
30
|
+
});
|
|
31
|
+
#id = nextId('rs');
|
|
32
|
+
#default = '';
|
|
33
|
+
constructor() { super(); this.value = ''; this.min = 0; this.max = 100; this.step = 1; this.minGap = 0; this.showValue = false; this.disabled = false; }
|
|
34
|
+
get low() { return this.#pair()[0]; }
|
|
35
|
+
get high() { return this.#pair()[1]; }
|
|
36
|
+
#pair() {
|
|
37
|
+
const [a, b] = this.value.split(',').map((x) => Number(x.trim()));
|
|
38
|
+
const lo = Number.isFinite(a) ? a : this.min;
|
|
39
|
+
const hi = Number.isFinite(b) ? b : this.max;
|
|
40
|
+
return [Math.max(this.min, Math.min(lo, hi)), Math.min(this.max, Math.max(lo, hi))];
|
|
41
|
+
}
|
|
42
|
+
connectedCallback() { super.connectedCallback(); this.#default = this.getAttribute('value') ?? ''; }
|
|
43
|
+
formResetCallback() { this.value = this.#default; }
|
|
44
|
+
formStateRestoreCallback(v) { this.value = v; }
|
|
45
|
+
formDisabledCallback(d) { this.disabled = d; }
|
|
46
|
+
updated() {
|
|
47
|
+
const [lo, hi] = this.#pair();
|
|
48
|
+
if (this.name) {
|
|
49
|
+
const fd = new FormData();
|
|
50
|
+
fd.append(this.name, String(lo));
|
|
51
|
+
fd.append(this.name, String(hi));
|
|
52
|
+
this.#internals.setFormValue(fd, `${lo},${hi}`);
|
|
53
|
+
}
|
|
54
|
+
else
|
|
55
|
+
this.#internals.setFormValue(`${lo},${hi}`);
|
|
56
|
+
}
|
|
57
|
+
#on(which, e, commit) {
|
|
58
|
+
const v = Number(e.target.value);
|
|
59
|
+
let [lo, hi] = this.#pair();
|
|
60
|
+
if (which === 0)
|
|
61
|
+
lo = Math.min(v, hi - this.minGap);
|
|
62
|
+
else
|
|
63
|
+
hi = Math.max(v, lo + this.minGap);
|
|
64
|
+
e.target.value = String(which === 0 ? lo : hi);
|
|
65
|
+
const value = `${lo},${hi}`;
|
|
66
|
+
if (value !== this.value)
|
|
67
|
+
this.value = value;
|
|
68
|
+
this.emit(commit ? 'pm-change' : 'pm-input', { value, low: lo, high: hi });
|
|
69
|
+
}
|
|
70
|
+
render() {
|
|
71
|
+
const [lo, hi] = this.#pair();
|
|
72
|
+
const span = this.max - this.min || 1;
|
|
73
|
+
const p = (n) => ((n - this.min) / span) * 100;
|
|
74
|
+
const fmt = (n) => `${n.toLocaleString(this.closest('[lang]')?.getAttribute('lang') ?? undefined)}${this.unit ?? ''}`;
|
|
75
|
+
const labelId = `${this.#id}-l`;
|
|
76
|
+
const thumb = (which) => html `<input type="range" class="pm-range-input" part=${which ? 'thumb-high' : 'thumb-low'} min=${this.min} max=${this.max} step=${this.step}
|
|
77
|
+
.value=${live(String(which ? hi : lo))} ?disabled=${this.disabled}
|
|
78
|
+
aria-label=${`${which ? 'Maximum' : 'Minimum'}${this.label ? ` ${this.label.toLowerCase()}` : ''}`} aria-valuetext=${fmt(which ? hi : lo)}
|
|
79
|
+
aria-describedby=${this.#field.describedBy ?? nothing} aria-invalid=${this.#field.invalid ? 'true' : nothing}
|
|
80
|
+
style=${which === 0 && lo > this.max - span * 0.02 ? 'z-index: 3' : ''}
|
|
81
|
+
@input=${(e) => this.#on(which, e, false)} @change=${(e) => this.#on(which, e, true)} />`;
|
|
82
|
+
return html `<div class="pm-field" part="field" role="group" aria-labelledby=${this.label ? labelId : nothing}>
|
|
83
|
+
${this.label || this.showValue ? html `<div class="pm-range-head">
|
|
84
|
+
${this.label ? html `<span id=${labelId} class="pm-range-label" part="label">${this.label}</span>` : nothing}
|
|
85
|
+
${this.showValue ? html `<output class="pm-range-value" aria-live="polite">${fmt(lo)} – ${fmt(hi)}</output>` : nothing}
|
|
86
|
+
</div>` : nothing}
|
|
87
|
+
<div class="pm-range" part="base" style=${`--_lo: ${p(lo)}%; --_hi: ${p(hi)}%`} ?data-disabled=${this.disabled} data-size=${this.size ?? nothing}>
|
|
88
|
+
<span class="pm-range-track" aria-hidden="true"><span class="pm-range-fill"></span></span>
|
|
89
|
+
${thumb(0)}${thumb(1)}
|
|
90
|
+
</div>
|
|
91
|
+
${this.#field.messages()}
|
|
92
|
+
</div>`;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
defineElement('pm-range-slider', PmRangeSlider);
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { type PropertyDeclarations } from 'lit';
|
|
2
|
+
import { PmElement } from '../base.js';
|
|
3
|
+
/**
|
|
4
|
+
* Star rating. Radio-group keyboard behaviour; form-associated; `readonly` for display.
|
|
5
|
+
* @tag pm-rating
|
|
6
|
+
* @fires pm-change - Value changed. detail: { value }
|
|
7
|
+
* @example <pm-rating label="Rate this product" value="4"></pm-rating>
|
|
8
|
+
*/
|
|
9
|
+
export declare class PmRating extends PmElement {
|
|
10
|
+
#private;
|
|
11
|
+
static componentName: string;
|
|
12
|
+
static formAssociated: boolean;
|
|
13
|
+
static styles: import("lit").CSSResult[];
|
|
14
|
+
static properties: PropertyDeclarations;
|
|
15
|
+
value: number;
|
|
16
|
+
max: number;
|
|
17
|
+
name?: string;
|
|
18
|
+
label: string;
|
|
19
|
+
size?: 'sm' | 'md' | 'lg';
|
|
20
|
+
readonly: boolean;
|
|
21
|
+
disabled: boolean;
|
|
22
|
+
/** Choosing the current value again clears it. */
|
|
23
|
+
clearable: boolean;
|
|
24
|
+
/** Help text under the field, linked to it for screen readers. */
|
|
25
|
+
hint?: string;
|
|
26
|
+
/** Custom error message. Setting it marks the field invalid. */
|
|
27
|
+
error?: string;
|
|
28
|
+
/** The form cannot be submitted until a value is chosen. */
|
|
29
|
+
required: boolean;
|
|
30
|
+
_hover: number;
|
|
31
|
+
constructor();
|
|
32
|
+
connectedCallback(): void;
|
|
33
|
+
formResetCallback(): void;
|
|
34
|
+
formStateRestoreCallback(v: string): void;
|
|
35
|
+
formDisabledCallback(d: boolean): void;
|
|
36
|
+
protected updated(): void;
|
|
37
|
+
render(): import("lit").TemplateResult<1>;
|
|
38
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { css, html, nothing } from 'lit';
|
|
2
|
+
import { PmElement, defineElement } from '../base.js';
|
|
3
|
+
import { FieldValidity } from '../field-validity.js';
|
|
4
|
+
import fieldCss from '../styles/field.js';
|
|
5
|
+
import ratingCss from '../styles/rating.js';
|
|
6
|
+
const STAR = html `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linejoin="round" aria-hidden="true"><path d="M12 3.5l2.6 5.4 5.9.8-4.3 4.1 1 5.8L12 16.9l-5.2 2.7 1-5.8-4.3-4.1 5.9-.8z"/></svg>`;
|
|
7
|
+
/**
|
|
8
|
+
* Star rating. Radio-group keyboard behaviour; form-associated; `readonly` for display.
|
|
9
|
+
* @tag pm-rating
|
|
10
|
+
* @fires pm-change - Value changed. detail: { value }
|
|
11
|
+
* @example <pm-rating label="Rate this product" value="4"></pm-rating>
|
|
12
|
+
*/
|
|
13
|
+
export class PmRating extends PmElement {
|
|
14
|
+
static { this.componentName = 'rating'; }
|
|
15
|
+
static { this.formAssociated = true; }
|
|
16
|
+
static { this.styles = [...PmElement.styles, fieldCss, ratingCss, css `:host { display: inline-flex; } :host([hidden]) { display: none; } .pm-field { justify-items: start; }`]; }
|
|
17
|
+
static { this.properties = {
|
|
18
|
+
value: { type: Number, reflect: true }, max: { type: Number }, name: { reflect: true }, label: {}, size: { reflect: true },
|
|
19
|
+
readonly: { type: Boolean, reflect: true }, disabled: { type: Boolean, reflect: true }, clearable: { type: Boolean }, _hover: { state: true },
|
|
20
|
+
hint: {}, error: {}, required: { type: Boolean, reflect: true },
|
|
21
|
+
}; }
|
|
22
|
+
#internals = this.attachInternals();
|
|
23
|
+
#field = new FieldValidity(this, this.#internals, {
|
|
24
|
+
hint: () => this.hint, error: () => this.error, missing: () => this.required && !this.value && !this.disabled,
|
|
25
|
+
missingMessage: 'Please choose a rating.', anchor: () => this.renderRoot.querySelector('[tabindex="0"]'),
|
|
26
|
+
});
|
|
27
|
+
#default = 0;
|
|
28
|
+
constructor() { super(); this.value = 0; this.max = 5; this.label = 'Rating'; this.readonly = false; this.disabled = false; this.clearable = false; this.required = false; this._hover = 0; }
|
|
29
|
+
connectedCallback() { super.connectedCallback(); this.#default = Number(this.getAttribute('value') ?? 0); }
|
|
30
|
+
formResetCallback() { this.value = this.#default; this.#field.reset(); }
|
|
31
|
+
formStateRestoreCallback(v) { this.value = Number(v); }
|
|
32
|
+
formDisabledCallback(d) { this.disabled = d; }
|
|
33
|
+
updated() { this.#internals.setFormValue(this.value ? String(this.value) : null); }
|
|
34
|
+
#set(v, focus = false) {
|
|
35
|
+
if (this.readonly || this.disabled)
|
|
36
|
+
return;
|
|
37
|
+
const next = this.clearable && v === this.value ? 0 : Math.max(0, Math.min(this.max, v));
|
|
38
|
+
if (next !== this.value) {
|
|
39
|
+
this.value = next;
|
|
40
|
+
this.#field.touch();
|
|
41
|
+
this.emit('pm-change', { value: next });
|
|
42
|
+
}
|
|
43
|
+
if (focus)
|
|
44
|
+
this.updateComplete.then(() => this.renderRoot.querySelector('[tabindex="0"]')?.focus());
|
|
45
|
+
}
|
|
46
|
+
#onKey(e) {
|
|
47
|
+
const rtl = getComputedStyle(this).direction === 'rtl';
|
|
48
|
+
const d = { ArrowRight: rtl ? -1 : 1, ArrowUp: 1, ArrowLeft: rtl ? 1 : -1, ArrowDown: -1 }[e.key];
|
|
49
|
+
if (d) {
|
|
50
|
+
e.preventDefault();
|
|
51
|
+
this.#set(Math.max(1, this.value + d), true);
|
|
52
|
+
}
|
|
53
|
+
else if (e.key === 'Home') {
|
|
54
|
+
e.preventDefault();
|
|
55
|
+
this.#set(1, true);
|
|
56
|
+
}
|
|
57
|
+
else if (e.key === 'End') {
|
|
58
|
+
e.preventDefault();
|
|
59
|
+
this.#set(this.max, true);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
render() {
|
|
63
|
+
const shown = this._hover || this.value;
|
|
64
|
+
if (this.readonly) {
|
|
65
|
+
return html `<span class="pm-rating" part="base" data-readonly data-size=${this.size ?? nothing} role="img" aria-label=${`${this.label}: ${this.value} out of ${this.max}`}>
|
|
66
|
+
${Array.from({ length: this.max }, (_, i) => html `<span class="pm-rating-star" ?data-on=${i < this.value}>${STAR}</span>`)}</span>`;
|
|
67
|
+
}
|
|
68
|
+
const focusIndex = Math.max(0, this.value - 1);
|
|
69
|
+
const group = html `<div class="pm-rating" part="base" role="radiogroup" aria-label=${this.label} data-size=${this.size ?? nothing}
|
|
70
|
+
aria-required=${this.required ? 'true' : nothing} aria-invalid=${this.#field.invalid ? 'true' : nothing}
|
|
71
|
+
aria-describedby=${this.#field.describedBy ?? nothing}
|
|
72
|
+
aria-disabled=${this.disabled ? 'true' : nothing} @keydown=${this.#onKey} @pointerleave=${() => (this._hover = 0)}>
|
|
73
|
+
${Array.from({ length: this.max }, (_, i) => html `<button type="button" class="pm-rating-star" part="star" role="radio"
|
|
74
|
+
aria-checked=${i + 1 === this.value ? 'true' : 'false'} aria-label=${`${i + 1} star${i ? 's' : ''}`} tabindex=${i === focusIndex ? 0 : -1}
|
|
75
|
+
?data-on=${i < shown} ?disabled=${this.disabled} @pointerenter=${() => (this._hover = i + 1)} @click=${() => this.#set(i + 1)}>${STAR}</button>`)}
|
|
76
|
+
</div>`;
|
|
77
|
+
return this.hint || this.#field.message ? html `<div class="pm-field" part="field">${group}${this.#field.messages()}</div>` : group;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
defineElement('pm-rating', PmRating);
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type PropertyDeclarations } from 'lit';
|
|
2
|
+
import { PmElement } from '../base.js';
|
|
3
|
+
/** "3 minutes ago" / "in 2 days" for a date, in the given locale. */
|
|
4
|
+
export declare function formatRelative(date: Date, locale?: string, now?: number, numeric?: 'auto' | 'always'): string;
|
|
5
|
+
/**
|
|
6
|
+
* Relative time ("5 minutes ago", "in 2 days") that keeps itself up to date. Renders a `<time>` with the full date
|
|
7
|
+
* as a tooltip. `format="datetime"` shows an absolute, locale-formatted date instead.
|
|
8
|
+
* @tag pm-relative-time
|
|
9
|
+
* @example <pm-relative-time datetime="2026-12-01T09:30:00Z"></pm-relative-time>
|
|
10
|
+
*/
|
|
11
|
+
export declare class PmRelativeTime extends PmElement {
|
|
12
|
+
#private;
|
|
13
|
+
static componentName: string;
|
|
14
|
+
static properties: PropertyDeclarations;
|
|
15
|
+
/** ISO date/time. */
|
|
16
|
+
datetime: string;
|
|
17
|
+
locale?: string;
|
|
18
|
+
/** relative (default) or datetime. */
|
|
19
|
+
format: 'relative' | 'datetime';
|
|
20
|
+
/** "auto" says "yesterday"; "always" says "1 day ago". */
|
|
21
|
+
numeric: 'auto' | 'always';
|
|
22
|
+
/** Date format of the full timestamp in the tooltip (Intl dateStyle). */
|
|
23
|
+
dateStyle?: 'full' | 'long' | 'medium' | 'short';
|
|
24
|
+
/** Time format of the full timestamp in the tooltip (Intl timeStyle). */
|
|
25
|
+
timeStyle?: 'full' | 'long' | 'medium' | 'short';
|
|
26
|
+
_now: number;
|
|
27
|
+
constructor();
|
|
28
|
+
disconnectedCallback(): void;
|
|
29
|
+
protected updated(): void;
|
|
30
|
+
render(): import("lit").TemplateResult<1>;
|
|
31
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { html } from 'lit';
|
|
2
|
+
import { PmElement, defineElement } from '../base.js';
|
|
3
|
+
const UNITS = [['year', 31536e6], ['month', 2592e6], ['week', 6048e5], ['day', 864e5], ['hour', 36e5], ['minute', 6e4], ['second', 1e3]];
|
|
4
|
+
/** "3 minutes ago" / "in 2 days" for a date, in the given locale. */
|
|
5
|
+
export function formatRelative(date, locale = 'en', now = Date.now(), numeric = 'auto') {
|
|
6
|
+
const diff = date.getTime() - now;
|
|
7
|
+
const rtf = new Intl.RelativeTimeFormat(locale, { numeric });
|
|
8
|
+
for (const [unit, ms] of UNITS)
|
|
9
|
+
if (Math.abs(diff) >= ms || unit === 'second')
|
|
10
|
+
return rtf.format(Math.round(diff / ms), unit);
|
|
11
|
+
return '';
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Relative time ("5 minutes ago", "in 2 days") that keeps itself up to date. Renders a `<time>` with the full date
|
|
15
|
+
* as a tooltip. `format="datetime"` shows an absolute, locale-formatted date instead.
|
|
16
|
+
* @tag pm-relative-time
|
|
17
|
+
* @example <pm-relative-time datetime="2026-12-01T09:30:00Z"></pm-relative-time>
|
|
18
|
+
*/
|
|
19
|
+
export class PmRelativeTime extends PmElement {
|
|
20
|
+
static { this.componentName = 'relative-time'; }
|
|
21
|
+
static { this.properties = {
|
|
22
|
+
datetime: { reflect: true }, locale: {}, format: {}, numeric: {}, dateStyle: { attribute: 'date-style' }, timeStyle: { attribute: 'time-style' }, _now: { state: true },
|
|
23
|
+
}; }
|
|
24
|
+
#timer;
|
|
25
|
+
constructor() { super(); this.datetime = ''; this.format = 'relative'; this.numeric = 'auto'; this._now = Date.now(); }
|
|
26
|
+
get #locale() { return this.locale || this.closest('[lang]')?.getAttribute('lang') || navigator.language || 'en'; }
|
|
27
|
+
disconnectedCallback() { super.disconnectedCallback(); clearTimeout(this.#timer); }
|
|
28
|
+
updated() {
|
|
29
|
+
clearTimeout(this.#timer);
|
|
30
|
+
if (this.format !== 'relative' || !this.isConnected)
|
|
31
|
+
return;
|
|
32
|
+
const d = new Date(this.datetime).getTime();
|
|
33
|
+
if (Number.isNaN(d))
|
|
34
|
+
return;
|
|
35
|
+
const age = Math.abs(Date.now() - d);
|
|
36
|
+
const wait = age < 6e4 ? 1e4 : age < 36e5 ? 3e4 : age < 864e5 ? 6e5 : 36e5;
|
|
37
|
+
this.#timer = setTimeout(() => { this._now = Date.now(); }, wait);
|
|
38
|
+
}
|
|
39
|
+
render() {
|
|
40
|
+
const d = new Date(this.datetime);
|
|
41
|
+
if (Number.isNaN(d.getTime()))
|
|
42
|
+
return html `<slot></slot>`;
|
|
43
|
+
const loc = this.#locale;
|
|
44
|
+
const full = new Intl.DateTimeFormat(loc, { dateStyle: 'full', timeStyle: 'short' }).format(d);
|
|
45
|
+
const text = this.format === 'datetime'
|
|
46
|
+
? new Intl.DateTimeFormat(loc, { dateStyle: this.dateStyle ?? 'medium', timeStyle: this.timeStyle }).format(d)
|
|
47
|
+
: formatRelative(d, loc, this._now, this.numeric);
|
|
48
|
+
return html `<time part="base" datetime=${this.datetime} title=${full}>${text}</time>`;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
defineElement('pm-relative-time', PmRelativeTime);
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { type PropertyDeclarations } from 'lit';
|
|
2
|
+
import { PmElement } from '../base.js';
|
|
3
|
+
export interface SchedulerEvent {
|
|
4
|
+
id?: string;
|
|
5
|
+
title: string;
|
|
6
|
+
/** Start and end as ISO date-times ("2026-12-14T10:00") or Date objects. */
|
|
7
|
+
start: string | Date;
|
|
8
|
+
end: string | Date;
|
|
9
|
+
/** Colour role: accent (default), secondary, success, warning, danger, info or neutral. */
|
|
10
|
+
tone?: string;
|
|
11
|
+
/** Shown in the row above the hours instead of on the time grid. */
|
|
12
|
+
allDay?: boolean;
|
|
13
|
+
}
|
|
14
|
+
type Placed = {
|
|
15
|
+
event: SchedulerEvent;
|
|
16
|
+
top: number;
|
|
17
|
+
height: number;
|
|
18
|
+
column: number;
|
|
19
|
+
columns: number;
|
|
20
|
+
start: Date;
|
|
21
|
+
end: Date;
|
|
22
|
+
};
|
|
23
|
+
/** Local date as YYYY-MM-DD. */
|
|
24
|
+
export declare const isoDay: (d: Date) => string;
|
|
25
|
+
/**
|
|
26
|
+
* Lay out one day's timed events: minutes from the first shown hour, and side-by-side columns for overlaps.
|
|
27
|
+
* Events are clipped to the visible hours; events entirely outside them are left out.
|
|
28
|
+
*/
|
|
29
|
+
export declare function layoutDay(events: SchedulerEvent[], day: Date, startHour: number, endHour: number): Placed[];
|
|
30
|
+
/**
|
|
31
|
+
* Scheduler: a week or day calendar with events on an hourly grid (bookings, shifts, meetings).
|
|
32
|
+
*
|
|
33
|
+
* Overlapping events sit side by side, all-day events get their own row and a line marks the current time. It
|
|
34
|
+
* switches to one day when narrow. Every event is a button named with its title and times; each day has an "Add"
|
|
35
|
+
* button so new events do not depend on clicking the grid. The element shows events; your code stores them.
|
|
36
|
+
* @tag pm-scheduler
|
|
37
|
+
* @fires pm-event-click - An event was activated. detail: { event }
|
|
38
|
+
* @fires pm-slot-click - An empty time was clicked, or a day's Add button was used. detail: { start, end } (ISO date-times, local)
|
|
39
|
+
* @fires pm-navigate - The shown period or view changed. detail: { date, view, from, to }
|
|
40
|
+
* @csspart base - The whole calendar.
|
|
41
|
+
* @csspart bar - The row with Today, previous/next and the view switch.
|
|
42
|
+
* @csspart day - One day's time column.
|
|
43
|
+
* @csspart event - An event button.
|
|
44
|
+
* @example <pm-scheduler label="Team calendar" date="2026-12-14" events='[{"title":"Stand-up","start":"2026-12-14T09:30","end":"2026-12-14T10:00"}]'></pm-scheduler>
|
|
45
|
+
*/
|
|
46
|
+
export declare class PmScheduler extends PmElement {
|
|
47
|
+
#private;
|
|
48
|
+
static componentName: string;
|
|
49
|
+
static styles: import("lit").CSSResult[];
|
|
50
|
+
static properties: PropertyDeclarations;
|
|
51
|
+
/** The events to show: { id, title, start, end, tone, allDay }. An array, or JSON in the attribute. */
|
|
52
|
+
events: SchedulerEvent[];
|
|
53
|
+
/** A day in the period to show, as YYYY-MM-DD (default today). */
|
|
54
|
+
date?: string;
|
|
55
|
+
/** week (default) or day. Narrow containers always show one day. */
|
|
56
|
+
view: 'week' | 'day';
|
|
57
|
+
/** First hour on the grid, 0 to 23 (default 7). */
|
|
58
|
+
startHour: number;
|
|
59
|
+
/** Hour the grid ends at, 1 to 24 (default 20). */
|
|
60
|
+
endHour: number;
|
|
61
|
+
/** First day of the week: 0 Sunday, 1 Monday (default). */
|
|
62
|
+
weekStart: number;
|
|
63
|
+
/** Accessible name of the calendar. */
|
|
64
|
+
label: string;
|
|
65
|
+
/** Language for day and month names (default: the page language). */
|
|
66
|
+
locale?: string;
|
|
67
|
+
/** Maximum height of the grid before it scrolls: any CSS length (default 32rem). */
|
|
68
|
+
height?: string;
|
|
69
|
+
/** Leave out Saturday and Sunday in the week view. */
|
|
70
|
+
hideWeekends: boolean;
|
|
71
|
+
_narrow: boolean;
|
|
72
|
+
_now: number;
|
|
73
|
+
constructor();
|
|
74
|
+
connectedCallback(): void;
|
|
75
|
+
disconnectedCallback(): void;
|
|
76
|
+
/** The days on screen. */
|
|
77
|
+
get days(): Date[];
|
|
78
|
+
/** Show the previous or next period (-1 or 1). */
|
|
79
|
+
step(dir: 1 | -1): void;
|
|
80
|
+
/** Show today. */
|
|
81
|
+
today(): void;
|
|
82
|
+
render(): import("lit").TemplateResult<1>;
|
|
83
|
+
}
|
|
84
|
+
export {};
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { css, html, nothing } from 'lit';
|
|
2
|
+
import { PmElement, defineElement } from '../base.js';
|
|
3
|
+
import buttonCss from '../styles/button.js';
|
|
4
|
+
import schedulerCss from '../styles/scheduler.js';
|
|
5
|
+
const startOfDay = (d) => new Date(d.getFullYear(), d.getMonth(), d.getDate());
|
|
6
|
+
const addDays = (d, n) => new Date(d.getFullYear(), d.getMonth(), d.getDate() + n);
|
|
7
|
+
const sameDay = (a, b) => a.getFullYear() === b.getFullYear() && a.getMonth() === b.getMonth() && a.getDate() === b.getDate();
|
|
8
|
+
/** Local date as YYYY-MM-DD. */
|
|
9
|
+
export const isoDay = (d) => `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`;
|
|
10
|
+
/**
|
|
11
|
+
* Lay out one day's timed events: minutes from the first shown hour, and side-by-side columns for overlaps.
|
|
12
|
+
* Events are clipped to the visible hours; events entirely outside them are left out.
|
|
13
|
+
*/
|
|
14
|
+
export function layoutDay(events, day, startHour, endHour) {
|
|
15
|
+
const from = startOfDay(day).getTime() + startHour * 3_600_000;
|
|
16
|
+
const to = startOfDay(day).getTime() + endHour * 3_600_000;
|
|
17
|
+
const items = events
|
|
18
|
+
.filter((e) => !e.allDay)
|
|
19
|
+
.map((event) => ({ event, start: new Date(event.start), end: new Date(event.end) }))
|
|
20
|
+
.filter((e) => !Number.isNaN(e.start.getTime()) && !Number.isNaN(e.end.getTime()) && e.start.getTime() < to && e.end.getTime() > from)
|
|
21
|
+
.sort((a, b) => a.start.getTime() - b.start.getTime() || b.end.getTime() - a.end.getTime());
|
|
22
|
+
const placed = [];
|
|
23
|
+
let cluster = [];
|
|
24
|
+
let clusterEnd = 0;
|
|
25
|
+
const close = () => { const n = Math.max(1, ...cluster.map((p) => p.column + 1)); for (const p of cluster)
|
|
26
|
+
p.columns = n; cluster = []; };
|
|
27
|
+
for (const it of items) {
|
|
28
|
+
const s = Math.max(it.start.getTime(), from);
|
|
29
|
+
const e = Math.max(s + 15 * 60_000, Math.min(it.end.getTime(), to));
|
|
30
|
+
if (cluster.length && s >= clusterEnd)
|
|
31
|
+
close();
|
|
32
|
+
// First column whose last event has ended.
|
|
33
|
+
let column = 0;
|
|
34
|
+
while (cluster.some((p) => p.column === column && p.top + p.height > (s - from) / 60_000))
|
|
35
|
+
column++;
|
|
36
|
+
const p = { event: it.event, start: it.start, end: it.end, top: (s - from) / 60_000, height: (e - s) / 60_000, column, columns: 1 };
|
|
37
|
+
cluster.push(p);
|
|
38
|
+
placed.push(p);
|
|
39
|
+
clusterEnd = Math.max(clusterEnd, e);
|
|
40
|
+
}
|
|
41
|
+
close();
|
|
42
|
+
return placed;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Scheduler: a week or day calendar with events on an hourly grid (bookings, shifts, meetings).
|
|
46
|
+
*
|
|
47
|
+
* Overlapping events sit side by side, all-day events get their own row and a line marks the current time. It
|
|
48
|
+
* switches to one day when narrow. Every event is a button named with its title and times; each day has an "Add"
|
|
49
|
+
* button so new events do not depend on clicking the grid. The element shows events; your code stores them.
|
|
50
|
+
* @tag pm-scheduler
|
|
51
|
+
* @fires pm-event-click - An event was activated. detail: { event }
|
|
52
|
+
* @fires pm-slot-click - An empty time was clicked, or a day's Add button was used. detail: { start, end } (ISO date-times, local)
|
|
53
|
+
* @fires pm-navigate - The shown period or view changed. detail: { date, view, from, to }
|
|
54
|
+
* @csspart base - The whole calendar.
|
|
55
|
+
* @csspart bar - The row with Today, previous/next and the view switch.
|
|
56
|
+
* @csspart day - One day's time column.
|
|
57
|
+
* @csspart event - An event button.
|
|
58
|
+
* @example <pm-scheduler label="Team calendar" date="2026-12-14" events='[{"title":"Stand-up","start":"2026-12-14T09:30","end":"2026-12-14T10:00"}]'></pm-scheduler>
|
|
59
|
+
*/
|
|
60
|
+
export class PmScheduler extends PmElement {
|
|
61
|
+
static { this.componentName = 'scheduler'; }
|
|
62
|
+
static { this.styles = [...PmElement.styles, buttonCss, schedulerCss, css `:host { display: block; min-inline-size: 0; } :host([hidden]) { display: none; }`]; }
|
|
63
|
+
static { this.properties = {
|
|
64
|
+
events: { type: Array }, date: {}, view: { reflect: true }, startHour: { type: Number, attribute: 'start-hour' }, endHour: { type: Number, attribute: 'end-hour' },
|
|
65
|
+
weekStart: { type: Number, attribute: 'week-start' }, label: {}, locale: {}, height: {}, hideWeekends: { type: Boolean, attribute: 'hide-weekends' },
|
|
66
|
+
_narrow: { state: true }, _now: { state: true },
|
|
67
|
+
}; }
|
|
68
|
+
#resize;
|
|
69
|
+
#timer = 0;
|
|
70
|
+
constructor() {
|
|
71
|
+
super();
|
|
72
|
+
this.events = [];
|
|
73
|
+
this.view = 'week';
|
|
74
|
+
this.startHour = 7;
|
|
75
|
+
this.endHour = 20;
|
|
76
|
+
this.weekStart = 1;
|
|
77
|
+
this.label = 'Calendar';
|
|
78
|
+
this.hideWeekends = false;
|
|
79
|
+
this._narrow = false;
|
|
80
|
+
this._now = Date.now();
|
|
81
|
+
}
|
|
82
|
+
connectedCallback() {
|
|
83
|
+
super.connectedCallback();
|
|
84
|
+
this.#resize = new ResizeObserver(([entry]) => { this._narrow = (entry?.contentRect.width ?? 999) < 544; });
|
|
85
|
+
this.#resize.observe(this);
|
|
86
|
+
this.#timer = window.setInterval(() => { this._now = Date.now(); }, 60_000);
|
|
87
|
+
}
|
|
88
|
+
disconnectedCallback() { super.disconnectedCallback(); this.#resize?.disconnect(); clearInterval(this.#timer); }
|
|
89
|
+
get #locale() { return this.locale || this.closest('[lang]')?.getAttribute('lang') || document.documentElement.lang || undefined; }
|
|
90
|
+
get #focus() {
|
|
91
|
+
const m = this.date?.match(/^(\d{4})-(\d{2})-(\d{2})/);
|
|
92
|
+
return m ? new Date(Number(m[1]), Number(m[2]) - 1, Number(m[3])) : startOfDay(new Date(this._now));
|
|
93
|
+
}
|
|
94
|
+
get #mode() { return this._narrow || this.view === 'day' ? 'day' : 'week'; }
|
|
95
|
+
/** The days on screen. */
|
|
96
|
+
get days() {
|
|
97
|
+
const focus = this.#focus;
|
|
98
|
+
if (this.#mode === 'day')
|
|
99
|
+
return [focus];
|
|
100
|
+
const first = addDays(focus, -((focus.getDay() - this.weekStart + 7) % 7));
|
|
101
|
+
return Array.from({ length: 7 }, (_x, i) => addDays(first, i)).filter((d) => !this.hideWeekends || (d.getDay() !== 0 && d.getDay() !== 6));
|
|
102
|
+
}
|
|
103
|
+
#go(to, view = this.view) {
|
|
104
|
+
this.date = isoDay(to);
|
|
105
|
+
this.view = view;
|
|
106
|
+
this.updateComplete.then(() => {
|
|
107
|
+
const days = this.days;
|
|
108
|
+
this.emit('pm-navigate', { date: this.date, view: this.#mode, from: isoDay(days[0]), to: isoDay(days[days.length - 1]) });
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
/** Show the previous or next period (-1 or 1). */
|
|
112
|
+
step(dir) { this.#go(addDays(this.#focus, dir * (this.#mode === 'day' ? 1 : 7))); }
|
|
113
|
+
/** Show today. */
|
|
114
|
+
today() { this.#go(startOfDay(new Date())); }
|
|
115
|
+
/** An all-day event covers every day from its start to its end (an end at midnight belongs to the day before). */
|
|
116
|
+
#allDay(d) {
|
|
117
|
+
return this.events.filter((e) => e.allDay && startOfDay(new Date(e.start)).getTime() <= d.getTime() && d.getTime() <= startOfDay(new Date(Math.max(new Date(e.start).getTime(), new Date(e.end).getTime() - 1))).getTime());
|
|
118
|
+
}
|
|
119
|
+
#any(days) { return days.some((d) => this.#allDay(d).length || layoutDay(this.events, d, this.startHour, this.endHour).length); }
|
|
120
|
+
#time(d) { return new Intl.DateTimeFormat(this.#locale, { hour: 'numeric', minute: '2-digit' }).format(d); }
|
|
121
|
+
#slot(day, minutes) {
|
|
122
|
+
const start = new Date(startOfDay(day).getTime() + this.startHour * 3_600_000 + minutes * 60_000);
|
|
123
|
+
const end = new Date(start.getTime() + 3_600_000);
|
|
124
|
+
const iso = (d) => `${isoDay(d)}T${String(d.getHours()).padStart(2, '0')}:${String(d.getMinutes()).padStart(2, '0')}`;
|
|
125
|
+
this.emit('pm-slot-click', { start: iso(start), end: iso(end) });
|
|
126
|
+
}
|
|
127
|
+
#onGridClick(day, e) {
|
|
128
|
+
if (e.target.closest('.pm-scheduler-event'))
|
|
129
|
+
return;
|
|
130
|
+
const col = e.currentTarget;
|
|
131
|
+
const hourPx = col.offsetHeight / Math.max(1, this.endHour - this.startHour);
|
|
132
|
+
const minutes = Math.floor(((e.clientY - col.getBoundingClientRect().top) / hourPx) * 2) * 30;
|
|
133
|
+
this.#slot(day, Math.max(0, minutes));
|
|
134
|
+
}
|
|
135
|
+
render() {
|
|
136
|
+
const days = this.days;
|
|
137
|
+
const loc = this.#locale;
|
|
138
|
+
const hours = Math.max(1, this.endHour - this.startHour);
|
|
139
|
+
const today = new Date(this._now);
|
|
140
|
+
const mode = this.#mode;
|
|
141
|
+
const fmtDay = new Intl.DateTimeFormat(loc, { weekday: 'short' });
|
|
142
|
+
const fmtFull = new Intl.DateTimeFormat(loc, { weekday: 'long', day: 'numeric', month: 'long' });
|
|
143
|
+
const title = mode === 'day'
|
|
144
|
+
? new Intl.DateTimeFormat(loc, { weekday: 'long', day: 'numeric', month: 'long', year: 'numeric' }).format(days[0])
|
|
145
|
+
: new Intl.DateTimeFormat(loc, { day: 'numeric', month: 'short', year: 'numeric' }).formatRange(days[0], days[days.length - 1]);
|
|
146
|
+
const hourLabel = new Intl.DateTimeFormat(loc, { hour: 'numeric' });
|
|
147
|
+
const nowMin = (today.getHours() - this.startHour) * 60 + today.getMinutes();
|
|
148
|
+
// Short or all-day events show only their title; the time stays in the accessible name.
|
|
149
|
+
const evButton = (ev, range, style, short = !style) => html `<button type="button" class="pm-scheduler-event" part="event" data-tone=${ev.tone ?? 'accent'} style=${style ?? nothing}
|
|
150
|
+
?data-short=${short} @click=${() => this.emit('pm-event-click', { event: ev })}><b>${ev.title}</b><span class=${short ? 'pm-visually-hidden' : ''}><span class="pm-visually-hidden">, </span>${range}</span></button>`;
|
|
151
|
+
return html `<section class="pm-scheduler" part="base" aria-label=${this.label} style="--_days: ${days.length}; ${this.height ? `--_height: ${this.height}` : ''}">
|
|
152
|
+
<div class="pm-scheduler-bar" part="bar">
|
|
153
|
+
<button type="button" class="pm-button" data-variant="outline" data-tone="neutral" data-size="sm" @click=${() => this.today()}>Today</button>
|
|
154
|
+
<button type="button" class="pm-button" data-variant="ghost" data-tone="neutral" data-size="sm" data-icon aria-label=${mode === 'day' ? 'Previous day' : 'Previous week'} @click=${() => this.step(-1)}><span aria-hidden="true">‹</span></button>
|
|
155
|
+
<button type="button" class="pm-button" data-variant="ghost" data-tone="neutral" data-size="sm" data-icon aria-label=${mode === 'day' ? 'Next day' : 'Next week'} @click=${() => this.step(1)}><span aria-hidden="true">›</span></button>
|
|
156
|
+
<h2 class="pm-scheduler-title" aria-live="polite">${title}</h2>
|
|
157
|
+
${this._narrow ? nothing : html `<div class="pm-scheduler-views" role="group" aria-label="View">
|
|
158
|
+
<button type="button" aria-pressed=${String(mode === 'day')} @click=${() => this.#go(this.#focus, 'day')}>Day</button>
|
|
159
|
+
<button type="button" aria-pressed=${String(mode === 'week')} @click=${() => this.#go(this.#focus, 'week')}>Week</button>
|
|
160
|
+
</div>`}
|
|
161
|
+
</div>
|
|
162
|
+
<div class="pm-scheduler-scroll" tabindex="0" role="group" aria-label="${this.label}: ${title}">
|
|
163
|
+
<div class="pm-scheduler-grid">
|
|
164
|
+
<div class="pm-scheduler-corner"></div>
|
|
165
|
+
${days.map((d) => {
|
|
166
|
+
const allDay = this.#allDay(d);
|
|
167
|
+
return html `<div class="pm-scheduler-day-head" ?data-today=${sameDay(d, today)}>
|
|
168
|
+
<h3 aria-label=${fmtFull.format(d)}>${fmtDay.format(d)} <b>${d.getDate()}</b></h3>
|
|
169
|
+
<button type="button" class="pm-scheduler-add" aria-label="Add event on ${fmtFull.format(d)}" title="Add event" @click=${() => this.#slot(d, 120)}><svg viewBox="0 0 24 24" width="1em" height="1em" fill="none" stroke="currentColor" stroke-width="2.25" stroke-linecap="round" aria-hidden="true"><path d="M12 5v14M5 12h14"/></svg></button>
|
|
170
|
+
${allDay.length ? html `<div class="pm-scheduler-allday">${allDay.map((ev) => evButton(ev, 'all day'))}</div>` : nothing}
|
|
171
|
+
</div>`;
|
|
172
|
+
})}
|
|
173
|
+
<div class="pm-scheduler-times" aria-hidden="true">${Array.from({ length: hours }, (_x, i) => html `<span>${hourLabel.format(new Date(2000, 0, 1, this.startHour + i))}</span>`)}</div>
|
|
174
|
+
${days.map((d) => {
|
|
175
|
+
const placed = layoutDay(this.events, d, this.startHour, this.endHour);
|
|
176
|
+
return html `<div class="pm-scheduler-day" part="day" ?data-today=${sameDay(d, today)} style="block-size: calc(var(--_hour) * ${hours})" @click=${(e) => this.#onGridClick(d, e)}>
|
|
177
|
+
${sameDay(d, today) && nowMin >= 0 && nowMin <= hours * 60 ? html `<div class="pm-scheduler-now" style="inset-block-start: calc(var(--_hour) * ${nowMin / 60})"></div>` : nothing}
|
|
178
|
+
<ul aria-label="Events on ${fmtFull.format(d)}">${placed.map((p) => html `<li>${evButton(p.event, `${this.#time(p.start)} to ${this.#time(p.end)}`, `inset-block-start: calc(var(--_hour) * ${p.top / 60}); block-size: calc(var(--_hour) * ${p.height / 60}); inset-inline-start: ${(p.column / p.columns) * 100}%; inline-size: ${100 / p.columns}%`, p.height < 45)}</li>`)}</ul>
|
|
179
|
+
</div>`;
|
|
180
|
+
})}
|
|
181
|
+
</div>
|
|
182
|
+
</div>
|
|
183
|
+
${this.#any(days) ? nothing : html `<p class="pm-scheduler-empty" role="status">No events in this period.</p>`}
|
|
184
|
+
</section>`;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
defineElement('pm-scheduler', PmScheduler);
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { type PropertyDeclarations } from 'lit';
|
|
2
|
+
import { PmElement } from '../base.js';
|
|
3
|
+
/**
|
|
4
|
+
* Segmented control: pick one of a few options (view switchers, filters). Radio-group semantics, form-associated.
|
|
5
|
+
* @tag pm-segmented
|
|
6
|
+
* @slot - `pm-segment` elements.
|
|
7
|
+
* @fires pm-change - Selection changed. detail: { value }
|
|
8
|
+
* @example <pm-segmented label="View" value="grid"><pm-segment value="list">List</pm-segment><pm-segment value="grid">Grid</pm-segment><pm-segment value="board">Board</pm-segment></pm-segmented>
|
|
9
|
+
*/
|
|
10
|
+
export declare class PmSegmented extends PmElement {
|
|
11
|
+
#private;
|
|
12
|
+
static componentName: string;
|
|
13
|
+
static formAssociated: boolean;
|
|
14
|
+
static styles: import("lit").CSSResult[];
|
|
15
|
+
static properties: PropertyDeclarations;
|
|
16
|
+
value?: string;
|
|
17
|
+
name?: string;
|
|
18
|
+
/** Accessible name of the group. */
|
|
19
|
+
label?: string;
|
|
20
|
+
size?: 'sm' | 'md' | 'lg';
|
|
21
|
+
/** Stretch to the container width. */
|
|
22
|
+
full: boolean;
|
|
23
|
+
disabled: boolean;
|
|
24
|
+
/** Help text under the field, linked to it for screen readers. */
|
|
25
|
+
hint?: string;
|
|
26
|
+
/** Custom error message. Setting it marks the field invalid. */
|
|
27
|
+
error?: string;
|
|
28
|
+
/** The form cannot be submitted until a value is chosen. */
|
|
29
|
+
required: boolean;
|
|
30
|
+
constructor();
|
|
31
|
+
connectedCallback(): void;
|
|
32
|
+
formResetCallback(): void;
|
|
33
|
+
formStateRestoreCallback(v: string): void;
|
|
34
|
+
formDisabledCallback(d: boolean): void;
|
|
35
|
+
render(): import("lit").TemplateResult<1>;
|
|
36
|
+
protected updated(): void;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* One option of a segmented control.
|
|
40
|
+
* @tag pm-segment
|
|
41
|
+
* @slot - Label (text and/or icon).
|
|
42
|
+
* @example <pm-segment value="grid">Grid</pm-segment>
|
|
43
|
+
*/
|
|
44
|
+
export declare class PmSegment extends PmElement {
|
|
45
|
+
static componentName: string;
|
|
46
|
+
static styles: import("lit").CSSResult[];
|
|
47
|
+
static properties: PropertyDeclarations;
|
|
48
|
+
value: string;
|
|
49
|
+
disabled: boolean;
|
|
50
|
+
/** Accessible name for icon-only segments. */
|
|
51
|
+
label?: string;
|
|
52
|
+
checked: boolean;
|
|
53
|
+
groupDisabled: boolean;
|
|
54
|
+
constructor();
|
|
55
|
+
connectedCallback(): void;
|
|
56
|
+
protected updated(): void;
|
|
57
|
+
render(): import("lit").TemplateResult<1>;
|
|
58
|
+
}
|