@threadlabs/looma 0.50.2 → 0.51.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/components/shared/binding-inputs.js +5 -0
- package/components/shared/calendar-model.js +84 -0
- package/components/shared/date-input-segments.js +25 -0
- package/components/shared/date-navigation.js +35 -0
- package/components/shared/date-picker.js +38 -0
- package/components/shared/date-range.js +61 -0
- package/components/shared/date-time.js +273 -0
- package/components/shared/external-value.js +12 -0
- package/components/shared/form-reset.js +1 -1
- package/components/shared/icons.js +2 -0
- package/components/shared/initial-field-value.js +14 -0
- package/components/shared/input-segments.js +190 -0
- package/components/shared/prepared-module.js +19 -0
- package/components/ui-button/ui-button.html +31 -10
- package/components/ui-calendar/calendar-source.js +34 -0
- package/components/ui-calendar/ui-calendar.html +221 -0
- package/components/ui-calendar/ui-calendar.js +185 -0
- package/components/ui-cluster/ui-cluster.html +5 -2
- package/components/ui-date-field/ui-date-field.html +143 -0
- package/components/ui-date-field/ui-date-field.js +258 -0
- package/components/ui-date-picker/ui-date-picker.html +213 -0
- package/components/ui-date-picker/ui-date-picker.js +153 -0
- package/components/ui-date-range-picker/ui-date-range-picker.html +202 -0
- package/components/ui-date-range-picker/ui-date-range-picker.js +224 -0
- package/components/ui-file-input/files.js +15 -0
- package/components/ui-file-input/ui-file-input.html +79 -0
- package/components/ui-file-input/ui-file-input.js +108 -0
- package/components/ui-form-field/ui-form-field.js +2 -2
- package/components/ui-grid/ui-grid.html +74 -5
- package/components/ui-icon/ui-icon.html +8 -0
- package/components/ui-icon-button/ui-icon-button.html +22 -7
- package/components/ui-input/ui-input.html +10 -1
- package/components/ui-input/ui-input.js +11 -5
- package/components/ui-input-group/ui-input-group.html +2 -2
- package/components/ui-input-group/ui-input-group.js +6 -5
- package/components/ui-popover/ui-popover.html +2 -0
- package/components/ui-popover/ui-popover.js +5 -1
- package/components/ui-select/ui-select.html +8 -3
- package/components/ui-time-field/ui-time-field.html +62 -0
- package/components/ui-time-field/ui-time-field.js +21 -0
- package/components/ui-time-picker/time-options.js +25 -0
- package/components/ui-time-picker/ui-time-picker.html +160 -0
- package/components/ui-time-picker/ui-time-picker.js +132 -0
- package/dist/index.js +68 -61
- package/docs/README.md +2 -2
- package/docs/catalog.json +14346 -6343
- package/docs/documentation.css +1 -1
- package/docs/framework-examples.mjs +13 -2
- package/docs/site.mjs +1 -1
- package/editor/components.css +62 -29
- package/editor/icons.d.ts +2 -0
- package/editor/index.js +602 -141
- package/package.json +6 -4
- package/styles/ui-action-bar.css +1 -1
- package/styles/ui-affordance-scope.css +1 -1
- package/styles/ui-avatar-group.css +1 -1
- package/styles/ui-avatar.css +1 -1
- package/styles/ui-badge.css +1 -1
- package/styles/ui-breadcrumb-item.css +1 -1
- package/styles/ui-breadcrumbs.css +1 -1
- package/styles/ui-button.css +19 -7
- package/styles/ui-calendar.css +1 -0
- package/styles/ui-callout.css +1 -1
- package/styles/ui-card-group.css +1 -1
- package/styles/ui-card.css +1 -1
- package/styles/ui-checkbox.css +1 -1
- package/styles/ui-cluster.css +4 -1
- package/styles/ui-color-picker.css +1 -1
- package/styles/ui-combobox.css +1 -1
- package/styles/ui-compact-content.css +1 -1
- package/styles/ui-compact-editor.css +1 -1
- package/styles/ui-compact-mark.css +1 -1
- package/styles/ui-compact-node.css +1 -1
- package/styles/ui-container.css +1 -1
- package/styles/ui-context-menu.css +1 -1
- package/styles/ui-cover.css +1 -1
- package/styles/ui-curve-editor.css +1 -1
- package/styles/ui-cycle-button.css +1 -1
- package/styles/ui-date-field.css +1 -0
- package/styles/ui-date-picker.css +1 -0
- package/styles/ui-date-range-picker.css +1 -0
- package/styles/ui-description-item.css +1 -1
- package/styles/ui-description-list.css +1 -1
- package/styles/ui-dialog.css +1 -1
- package/styles/ui-disclosure.css +1 -1
- package/styles/ui-editable.css +1 -1
- package/styles/ui-editor-block-actions.css +1 -1
- package/styles/ui-editor-chip-editor.css +1 -1
- package/styles/ui-editor-code-language.css +1 -1
- package/styles/ui-editor-footnote-editor.css +1 -1
- package/styles/ui-editor-formatting-tools.css +1 -1
- package/styles/ui-editor-image-toolbar.css +1 -1
- package/styles/ui-editor-insert-table-grid.css +1 -1
- package/styles/ui-editor-link-card.css +1 -1
- package/styles/ui-editor-link-form.css +1 -1
- package/styles/ui-editor-mention-menu-item.css +1 -1
- package/styles/ui-editor-mention-menu.css +1 -1
- package/styles/ui-editor-slash-menu-group.css +1 -1
- package/styles/ui-editor-slash-menu-item.css +1 -1
- package/styles/ui-editor-slash-menu.css +1 -1
- package/styles/ui-editor-surface.css +1 -1
- package/styles/ui-editor-table-context-menu.css +1 -1
- package/styles/ui-editor-table-overlay.css +1 -1
- package/styles/ui-editor-table-toolbar.css +1 -1
- package/styles/ui-editor-toolbar.css +1 -1
- package/styles/ui-editor.css +1 -1
- package/styles/ui-file-input.css +1 -0
- package/styles/ui-floating-action-button.css +1 -1
- package/styles/ui-form-field.css +1 -1
- package/styles/ui-grid.css +44 -1
- package/styles/ui-icon-button.css +19 -5
- package/styles/ui-icon.css +5 -1
- package/styles/ui-image.css +1 -1
- package/styles/ui-input-group.css +3 -3
- package/styles/ui-input.css +1 -1
- package/styles/ui-light-editor.css +1 -1
- package/styles/ui-list-item.css +1 -1
- package/styles/ui-list.css +1 -1
- package/styles/ui-listbox.css +1 -1
- package/styles/ui-menu-group.css +1 -1
- package/styles/ui-menu-item.css +1 -1
- package/styles/ui-menu.css +1 -1
- package/styles/ui-meter.css +1 -1
- package/styles/ui-nav-item.css +1 -1
- package/styles/ui-number-input.css +1 -1
- package/styles/ui-page-header.css +1 -1
- package/styles/ui-pagination.css +1 -1
- package/styles/ui-popover.css +1 -1
- package/styles/ui-radio-group.css +1 -1
- package/styles/ui-radio.css +1 -1
- package/styles/ui-reel.css +1 -1
- package/styles/ui-scroll-area.css +1 -1
- package/styles/ui-search-result-row.css +1 -1
- package/styles/ui-search-shell.css +1 -1
- package/styles/ui-section.css +1 -1
- package/styles/ui-select.css +9 -4
- package/styles/ui-separator.css +1 -1
- package/styles/ui-sidebar.css +1 -1
- package/styles/ui-site-header.css +19 -19
- package/styles/ui-skeleton.css +1 -1
- package/styles/ui-slider.css +1 -1
- package/styles/ui-spinner.css +1 -1
- package/styles/ui-stack.css +1 -1
- package/styles/ui-status-message.css +1 -1
- package/styles/ui-swatch.css +1 -1
- package/styles/ui-switch.css +1 -1
- package/styles/ui-switcher.css +1 -1
- package/styles/ui-table.css +1 -1
- package/styles/ui-tabs.css +1 -1
- package/styles/ui-text.css +1 -1
- package/styles/ui-textarea.css +1 -1
- package/styles/ui-time-field.css +1 -0
- package/styles/ui-time-picker.css +1 -0
- package/styles/ui-toast-region.css +1 -1
- package/styles/ui-toast.css +1 -1
- package/styles/ui-tooltip.css +1 -1
- package/styles/ui-top-bar.css +1 -1
- package/styles/ui-tree-item.css +1 -1
- package/styles/ui-tree.css +1 -1
- package/tokens.css +4 -0
- package/vanilla/UiActionBar.d.ts +1 -1
- package/vanilla/UiActionBar.js +1 -1
- package/vanilla/UiAffordanceScope.d.ts +1 -1
- package/vanilla/UiAffordanceScope.js +1 -1
- package/vanilla/UiAvatar.d.ts +1 -1
- package/vanilla/UiAvatar.js +1 -1
- package/vanilla/UiAvatarGroup.d.ts +1 -1
- package/vanilla/UiAvatarGroup.js +1 -1
- package/vanilla/UiBadge.d.ts +1 -1
- package/vanilla/UiBadge.js +1 -1
- package/vanilla/UiBreadcrumbItem.d.ts +1 -1
- package/vanilla/UiBreadcrumbItem.js +1 -1
- package/vanilla/UiBreadcrumbs.d.ts +1 -1
- package/vanilla/UiBreadcrumbs.js +1 -1
- package/vanilla/UiButton.d.ts +2 -1
- package/vanilla/UiButton.js +128 -108
- package/vanilla/UiCalendar.d.ts +50 -0
- package/vanilla/UiCalendar.js +477 -0
- package/vanilla/UiCallout.d.ts +1 -1
- package/vanilla/UiCallout.js +1 -1
- package/vanilla/UiCard.d.ts +1 -1
- package/vanilla/UiCard.js +1 -1
- package/vanilla/UiCardGroup.d.ts +1 -1
- package/vanilla/UiCardGroup.js +1 -1
- package/vanilla/UiCheckbox.d.ts +1 -1
- package/vanilla/UiCheckbox.js +1 -1
- package/vanilla/UiCluster.d.ts +2 -2
- package/vanilla/UiCluster.js +2 -2
- package/vanilla/UiColorPicker.d.ts +1 -1
- package/vanilla/UiColorPicker.js +1 -1
- package/vanilla/UiCombobox.d.ts +1 -1
- package/vanilla/UiCombobox.js +1 -1
- package/vanilla/UiCompactContent.d.ts +1 -1
- package/vanilla/UiCompactContent.js +1 -1
- package/vanilla/UiCompactEditor.d.ts +1 -1
- package/vanilla/UiCompactEditor.js +1 -1
- package/vanilla/UiCompactMark.d.ts +1 -1
- package/vanilla/UiCompactMark.js +1 -1
- package/vanilla/UiCompactNode.d.ts +1 -1
- package/vanilla/UiCompactNode.js +1 -1
- package/vanilla/UiContainer.d.ts +1 -1
- package/vanilla/UiContainer.js +1 -1
- package/vanilla/UiContextMenu.d.ts +1 -1
- package/vanilla/UiContextMenu.js +1 -1
- package/vanilla/UiCover.d.ts +1 -1
- package/vanilla/UiCover.js +1 -1
- package/vanilla/UiCurveEditor.d.ts +1 -1
- package/vanilla/UiCurveEditor.js +1 -1
- package/vanilla/UiCycleButton.d.ts +1 -1
- package/vanilla/UiCycleButton.js +1 -1
- package/vanilla/UiDateField.d.ts +52 -0
- package/vanilla/UiDateField.js +208 -0
- package/vanilla/UiDatePicker.d.ts +63 -0
- package/vanilla/UiDatePicker.js +360 -0
- package/vanilla/UiDateRangePicker.d.ts +60 -0
- package/vanilla/UiDateRangePicker.js +418 -0
- package/vanilla/UiDescriptionItem.d.ts +1 -1
- package/vanilla/UiDescriptionItem.js +1 -1
- package/vanilla/UiDescriptionList.d.ts +1 -1
- package/vanilla/UiDescriptionList.js +1 -1
- package/vanilla/UiDialog.d.ts +1 -1
- package/vanilla/UiDialog.js +1 -1
- package/vanilla/UiDisclosure.d.ts +1 -1
- package/vanilla/UiDisclosure.js +1 -1
- package/vanilla/UiEditable.d.ts +1 -1
- package/vanilla/UiEditable.js +1 -1
- package/vanilla/UiEditor.d.ts +1 -1
- package/vanilla/UiEditor.js +1 -1
- package/vanilla/UiEditorBlockActions.d.ts +1 -1
- package/vanilla/UiEditorBlockActions.js +1 -1
- package/vanilla/UiEditorChipEditor.d.ts +1 -1
- package/vanilla/UiEditorChipEditor.js +1 -1
- package/vanilla/UiEditorCodeLanguage.d.ts +1 -1
- package/vanilla/UiEditorCodeLanguage.js +1 -1
- package/vanilla/UiEditorFootnoteEditor.d.ts +1 -1
- package/vanilla/UiEditorFootnoteEditor.js +1 -1
- package/vanilla/UiEditorFormattingTools.d.ts +1 -1
- package/vanilla/UiEditorFormattingTools.js +1 -1
- package/vanilla/UiEditorImageToolbar.d.ts +1 -1
- package/vanilla/UiEditorImageToolbar.js +1 -1
- package/vanilla/UiEditorInsertTableGrid.d.ts +1 -1
- package/vanilla/UiEditorInsertTableGrid.js +1 -1
- package/vanilla/UiEditorLinkCard.d.ts +1 -1
- package/vanilla/UiEditorLinkCard.js +1 -1
- package/vanilla/UiEditorLinkForm.d.ts +1 -1
- package/vanilla/UiEditorLinkForm.js +1 -1
- package/vanilla/UiEditorMentionMenu.d.ts +1 -1
- package/vanilla/UiEditorMentionMenu.js +1 -1
- package/vanilla/UiEditorMentionMenuItem.d.ts +1 -1
- package/vanilla/UiEditorMentionMenuItem.js +1 -1
- package/vanilla/UiEditorSlashMenu.d.ts +1 -1
- package/vanilla/UiEditorSlashMenu.js +1 -1
- package/vanilla/UiEditorSlashMenuGroup.d.ts +1 -1
- package/vanilla/UiEditorSlashMenuGroup.js +1 -1
- package/vanilla/UiEditorSlashMenuItem.d.ts +1 -1
- package/vanilla/UiEditorSlashMenuItem.js +1 -1
- package/vanilla/UiEditorSurface.d.ts +1 -1
- package/vanilla/UiEditorSurface.js +1 -1
- package/vanilla/UiEditorTableContextMenu.d.ts +1 -1
- package/vanilla/UiEditorTableContextMenu.js +1 -1
- package/vanilla/UiEditorTableOverlay.d.ts +1 -1
- package/vanilla/UiEditorTableOverlay.js +1 -1
- package/vanilla/UiEditorTableToolbar.d.ts +1 -1
- package/vanilla/UiEditorTableToolbar.js +1 -1
- package/vanilla/UiEditorToolbar.d.ts +1 -1
- package/vanilla/UiEditorToolbar.js +1 -1
- package/vanilla/UiFileInput.d.ts +36 -0
- package/vanilla/UiFileInput.js +209 -0
- package/vanilla/UiFloatingActionButton.d.ts +1 -1
- package/vanilla/UiFloatingActionButton.js +1 -1
- package/vanilla/UiFormField.d.ts +1 -1
- package/vanilla/UiFormField.js +1 -1
- package/vanilla/UiGrid.d.ts +7 -2
- package/vanilla/UiGrid.js +85 -19
- package/vanilla/UiIcon.d.ts +2 -1
- package/vanilla/UiIcon.js +10 -10
- package/vanilla/UiIconButton.d.ts +2 -2
- package/vanilla/UiIconButton.js +2 -2
- package/vanilla/UiImage.d.ts +1 -1
- package/vanilla/UiImage.js +1 -1
- package/vanilla/UiInput.d.ts +2 -1
- package/vanilla/UiInput.js +11 -11
- package/vanilla/UiInputGroup.d.ts +1 -1
- package/vanilla/UiInputGroup.js +1 -1
- package/vanilla/UiLightEditor.d.ts +1 -1
- package/vanilla/UiLightEditor.js +1 -1
- package/vanilla/UiList.d.ts +1 -1
- package/vanilla/UiList.js +1 -1
- package/vanilla/UiListItem.d.ts +1 -1
- package/vanilla/UiListItem.js +1 -1
- package/vanilla/UiListbox.d.ts +1 -1
- package/vanilla/UiListbox.js +1 -1
- package/vanilla/UiMenu.d.ts +1 -1
- package/vanilla/UiMenu.js +1 -1
- package/vanilla/UiMenuGroup.d.ts +1 -1
- package/vanilla/UiMenuGroup.js +1 -1
- package/vanilla/UiMenuItem.d.ts +1 -1
- package/vanilla/UiMenuItem.js +1 -1
- package/vanilla/UiMeter.d.ts +1 -1
- package/vanilla/UiMeter.js +1 -1
- package/vanilla/UiNavItem.d.ts +1 -1
- package/vanilla/UiNavItem.js +1 -1
- package/vanilla/UiNumberInput.d.ts +1 -1
- package/vanilla/UiNumberInput.js +1 -1
- package/vanilla/UiPageHeader.d.ts +1 -1
- package/vanilla/UiPageHeader.js +1 -1
- package/vanilla/UiPagination.d.ts +1 -1
- package/vanilla/UiPagination.js +1 -1
- package/vanilla/UiPopover.d.ts +2 -1
- package/vanilla/UiPopover.js +4 -4
- package/vanilla/UiRadio.d.ts +1 -1
- package/vanilla/UiRadio.js +1 -1
- package/vanilla/UiRadioGroup.d.ts +1 -1
- package/vanilla/UiRadioGroup.js +1 -1
- package/vanilla/UiReel.d.ts +1 -1
- package/vanilla/UiReel.js +1 -1
- package/vanilla/UiScrollArea.d.ts +1 -1
- package/vanilla/UiScrollArea.js +1 -1
- package/vanilla/UiSearchResultRow.d.ts +1 -1
- package/vanilla/UiSearchResultRow.js +1 -1
- package/vanilla/UiSearchShell.d.ts +1 -1
- package/vanilla/UiSearchShell.js +1 -1
- package/vanilla/UiSection.d.ts +1 -1
- package/vanilla/UiSection.js +1 -1
- package/vanilla/UiSelect.d.ts +1 -1
- package/vanilla/UiSelect.js +1 -1
- package/vanilla/UiSeparator.d.ts +1 -1
- package/vanilla/UiSeparator.js +1 -1
- package/vanilla/UiSidebar.d.ts +1 -1
- package/vanilla/UiSidebar.js +1 -1
- package/vanilla/UiSiteHeader.d.ts +1 -1
- package/vanilla/UiSiteHeader.js +1 -1
- package/vanilla/UiSkeleton.d.ts +1 -1
- package/vanilla/UiSkeleton.js +1 -1
- package/vanilla/UiSlider.d.ts +1 -1
- package/vanilla/UiSlider.js +1 -1
- package/vanilla/UiSpinner.d.ts +1 -1
- package/vanilla/UiSpinner.js +1 -1
- package/vanilla/UiStack.d.ts +1 -1
- package/vanilla/UiStack.js +1 -1
- package/vanilla/UiStatusMessage.d.ts +1 -1
- package/vanilla/UiStatusMessage.js +1 -1
- package/vanilla/UiSwatch.d.ts +1 -1
- package/vanilla/UiSwatch.js +1 -1
- package/vanilla/UiSwitch.d.ts +1 -1
- package/vanilla/UiSwitch.js +1 -1
- package/vanilla/UiSwitcher.d.ts +1 -1
- package/vanilla/UiSwitcher.js +1 -1
- package/vanilla/UiTable.d.ts +1 -1
- package/vanilla/UiTable.js +1 -1
- package/vanilla/UiTabs.d.ts +1 -1
- package/vanilla/UiTabs.js +1 -1
- package/vanilla/UiText.d.ts +1 -1
- package/vanilla/UiText.js +1 -1
- package/vanilla/UiTextarea.d.ts +1 -1
- package/vanilla/UiTextarea.js +1 -1
- package/vanilla/UiTimeField.d.ts +42 -0
- package/vanilla/UiTimeField.js +112 -0
- package/vanilla/UiTimePicker.d.ts +48 -0
- package/vanilla/UiTimePicker.js +372 -0
- package/vanilla/UiToast.d.ts +1 -1
- package/vanilla/UiToast.js +1 -1
- package/vanilla/UiToastRegion.d.ts +1 -1
- package/vanilla/UiToastRegion.js +1 -1
- package/vanilla/UiTooltip.d.ts +1 -1
- package/vanilla/UiTooltip.js +1 -1
- package/vanilla/UiTopBar.d.ts +1 -1
- package/vanilla/UiTopBar.js +1 -1
- package/vanilla/UiTree.d.ts +1 -1
- package/vanilla/UiTree.js +1 -1
- package/vanilla/UiTreeItem.d.ts +1 -1
- package/vanilla/UiTreeItem.js +1 -1
- package/vanilla/index.js +7 -0
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { Temporal, canonicalValue, isValueAllowed } from "../shared/date-time.js";
|
|
2
|
+
import { afterFormReset } from "../shared/form-reset.js";
|
|
3
|
+
import { externalValueTracker } from "../shared/external-value.js";
|
|
4
|
+
import { initialFieldValue } from "../shared/initial-field-value.js";
|
|
5
|
+
import { timeOptions } from "./time-options.js";
|
|
6
|
+
|
|
7
|
+
/** Commit typed time and localized picker choices through one canonical field. */
|
|
8
|
+
export function connect(host) {
|
|
9
|
+
const element = host.element;
|
|
10
|
+
const field = element.querySelector("[data-time-field]");
|
|
11
|
+
const control = field.querySelector("[data-date-editor]");
|
|
12
|
+
const trigger = element.querySelector("[data-time-trigger]");
|
|
13
|
+
const popover = element.querySelector("[data-time-popover]");
|
|
14
|
+
const editors = ["hour", "minute", "second"].map(part => element.querySelector(`[data-time-${part}]`));
|
|
15
|
+
let current = host.state.current ?? host.props.value.value ?? "";
|
|
16
|
+
const externalChanged = externalValueTracker(element, { initialValue: host.props.value.value });
|
|
17
|
+
let draftBase = Temporal.PlainTime.from("00:00");
|
|
18
|
+
let connected = true;
|
|
19
|
+
let focusFrame;
|
|
20
|
+
const blocked = () => host.props.disabled.value || host.props.readonly.value || control.matches(":disabled, :read-only");
|
|
21
|
+
const settings = () => ({ type: "time", min: host.props.min.value, max: host.props.max.value });
|
|
22
|
+
const initial = initialFieldValue(field, { ...settings(), locale: host.props.locale.value, hourCycle: host.props.hourCycle.value });
|
|
23
|
+
try {
|
|
24
|
+
if (initial !== undefined && initial !== current && (initial || !host.props.required.value) && isValueAllowed(initial, settings())) {
|
|
25
|
+
current = initial; host.state.current = current;
|
|
26
|
+
}
|
|
27
|
+
} catch { /* The field retains an invalid native draft for correction. */ }
|
|
28
|
+
const updatePrecision = () => {
|
|
29
|
+
const precision = time => Boolean(time.second || time.millisecond || time.microsecond || time.nanosecond);
|
|
30
|
+
const bounds = [host.props.min.value, host.props.max.value].filter(Boolean).map(value => {
|
|
31
|
+
try { return Temporal.PlainTime.from(canonicalValue(value, { type: "time" })); } catch { return draftBase; }
|
|
32
|
+
});
|
|
33
|
+
host.state.showSeconds = host.props.granularity.value === "second" || precision(draftBase) || Number(editors[2].value) > 0 || bounds.some(precision);
|
|
34
|
+
};
|
|
35
|
+
const seed = () => {
|
|
36
|
+
try { draftBase = Temporal.PlainTime.from(canonicalValue(current || host.props.min.value || "00:00", { type: "time" })); }
|
|
37
|
+
catch { draftBase = Temporal.PlainTime.from("00:00"); }
|
|
38
|
+
["hour", "minute", "second"].forEach((part, index) => { editors[index].value = String(draftBase[part]); });
|
|
39
|
+
updatePrecision();
|
|
40
|
+
host.state.error = "";
|
|
41
|
+
};
|
|
42
|
+
const choices = () => {
|
|
43
|
+
try {
|
|
44
|
+
const time = draftBase.with(Object.fromEntries(["hour", "minute", "second"].map((part, index) => [part, Number(editors[index].value)])), { overflow: "reject" });
|
|
45
|
+
const availability = timeOptions(time.toString(), { ...settings(), showSeconds: host.state.showSeconds });
|
|
46
|
+
["hours", "minutes", "seconds"].forEach((part, index) => {
|
|
47
|
+
for (const choice of availability[part]) editors[index].options[Number(choice.value)].disabled = choice.disabled;
|
|
48
|
+
});
|
|
49
|
+
} catch (error) { host.state.error = error.message; }
|
|
50
|
+
};
|
|
51
|
+
const close = (restoreFocus = false) => {
|
|
52
|
+
host.state.opened = false;
|
|
53
|
+
host.state.error = "";
|
|
54
|
+
if (restoreFocus) queueMicrotask(() => { if (connected) trigger.focus(); });
|
|
55
|
+
};
|
|
56
|
+
const mutability = () => { host.state.fieldBlocked = blocked(); if (blocked()) close(); };
|
|
57
|
+
const observer = new MutationObserver(mutability);
|
|
58
|
+
observer.observe(control, { attributes: true, attributeFilter: ["disabled", "readonly"] });
|
|
59
|
+
mutability();
|
|
60
|
+
const relay = event => {
|
|
61
|
+
if (!(event instanceof CustomEvent)) return;
|
|
62
|
+
event.stopPropagation();
|
|
63
|
+
if (event.type === "input" || event.type === "change") {
|
|
64
|
+
current = event.detail.value;
|
|
65
|
+
host.state.current = current;
|
|
66
|
+
}
|
|
67
|
+
host.dispatch(event.type, event.detail);
|
|
68
|
+
};
|
|
69
|
+
const overlay = event => {
|
|
70
|
+
if (!(event instanceof CustomEvent)) return;
|
|
71
|
+
event.stopPropagation();
|
|
72
|
+
if (event.type === "open") {
|
|
73
|
+
if (blocked()) { close(); return; }
|
|
74
|
+
seed(); host.state.opened = true;
|
|
75
|
+
cancelAnimationFrame(focusFrame);
|
|
76
|
+
focusFrame = requestAnimationFrame(() => { if (connected && host.state.opened) { seed(); choices(); editors[0].focus(); } });
|
|
77
|
+
} else {
|
|
78
|
+
close(event.detail.reason === "escape");
|
|
79
|
+
}
|
|
80
|
+
host.dispatch(event.type, event.detail);
|
|
81
|
+
};
|
|
82
|
+
const swallow = event => {
|
|
83
|
+
event.stopPropagation();
|
|
84
|
+
if (editors.includes(event.target)) {
|
|
85
|
+
host.state.error = ""; choices();
|
|
86
|
+
if (event.type === "change") accept(event);
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
const accept = event => {
|
|
90
|
+
if (blocked() || !host.state.opened) return;
|
|
91
|
+
try {
|
|
92
|
+
const values = editors.map(input => Number(input.value));
|
|
93
|
+
if (editors.some((input, index) => !input.checkValidity() || !/^\d+$/.test(input.value) || !Number.isInteger(values[index]))) throw new RangeError("Enter whole hours, minutes and seconds.");
|
|
94
|
+
const value = canonicalValue(draftBase.with({ hour: values[0], minute: values[1], second: values[2] }, { overflow: "reject" }).toString(), { type: "time" });
|
|
95
|
+
if (!isValueAllowed(value, settings())) throw new RangeError("Choose a time within the permitted range.");
|
|
96
|
+
const accepted = field.dispatchEvent(new CustomEvent("set-value", { cancelable: true, detail: { value, trigger: event.isTrusted ? "keyboard" : "programmatic" } }));
|
|
97
|
+
if (!accepted) return;
|
|
98
|
+
} catch (error) { host.state.error = error.message; }
|
|
99
|
+
};
|
|
100
|
+
const request = event => {
|
|
101
|
+
if (event.target !== element) return;
|
|
102
|
+
const accepted = field.dispatchEvent(event instanceof CustomEvent ? new CustomEvent(event.type, { detail: event.detail, cancelable: event.cancelable }) : new Event(event.type));
|
|
103
|
+
if (!accepted) event.preventDefault();
|
|
104
|
+
};
|
|
105
|
+
const events = ["input", "change", "query-change", "validation-change"];
|
|
106
|
+
for (const name of events) field.addEventListener(name, relay);
|
|
107
|
+
for (const name of ["open", "close"]) popover.addEventListener(name, overlay);
|
|
108
|
+
for (const name of ["input", "change"]) popover.addEventListener(name, swallow);
|
|
109
|
+
for (const name of ["validate", "set-value"]) element.addEventListener(name, request);
|
|
110
|
+
if (!host.state.anchorId) host.state.anchorId = `ui-time-picker-${Math.random().toString(36).slice(2, 11)}`;
|
|
111
|
+
const stop = host.effect(() => {
|
|
112
|
+
const value = host.props.value.value;
|
|
113
|
+
host.state.hourFormat = { hour: "numeric", timeZone: "UTC", ...(host.props.hourCycle.value ? { hourCycle: host.props.hourCycle.value } : {}) };
|
|
114
|
+
if (externalChanged(value)) {
|
|
115
|
+
current = value ?? ""; host.state.current = current;
|
|
116
|
+
if (host.state.opened) seed();
|
|
117
|
+
}
|
|
118
|
+
if (blocked()) close();
|
|
119
|
+
if (host.state.opened) { updatePrecision(); choices(); }
|
|
120
|
+
});
|
|
121
|
+
host.state.enhanced = true;
|
|
122
|
+
const reset = afterFormReset(control, () => {
|
|
123
|
+
current = host.props.value.value ?? ""; host.state.current = current; close();
|
|
124
|
+
});
|
|
125
|
+
return () => {
|
|
126
|
+
connected = false; cancelAnimationFrame(focusFrame); observer.disconnect(); stop(); reset(); host.state.enhanced = false; close();
|
|
127
|
+
for (const name of events) field.removeEventListener(name, relay);
|
|
128
|
+
for (const name of ["open", "close"]) popover.removeEventListener(name, overlay);
|
|
129
|
+
for (const name of ["input", "change"]) popover.removeEventListener(name, swallow);
|
|
130
|
+
for (const name of ["validate", "set-value"]) element.removeEventListener(name, request);
|
|
131
|
+
};
|
|
132
|
+
}
|