frontile 0.18.3 → 0.18.6
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/declarations/-private/reveal-within.d.ts +19 -0
- package/declarations/-private/reveal-within.d.ts.map +1 -0
- package/declarations/components/collections/calendar/year-grid.d.ts.map +1 -1
- package/declarations/components/forms/autocomplete.d.ts +49 -1
- package/declarations/components/forms/autocomplete.d.ts.map +1 -1
- package/declarations/components/forms/date-input/segment-group.d.ts +2 -1
- package/declarations/components/forms/date-input/segment-group.d.ts.map +1 -1
- package/declarations/components/forms/date-input/segments.d.ts +3 -1
- package/declarations/components/forms/date-input/segments.d.ts.map +1 -1
- package/declarations/components/forms/date-picker/date-picker.d.ts +119 -1
- package/declarations/components/forms/date-picker/date-picker.d.ts.map +1 -1
- package/declarations/components/forms/date-picker/time-columns.d.ts +87 -0
- package/declarations/components/forms/date-picker/time-columns.d.ts.map +1 -0
- package/declarations/components/forms/date-picker/types.d.ts +28 -0
- package/declarations/components/forms/date-picker/types.d.ts.map +1 -1
- package/declarations/components/forms/select/native-mirror.d.ts +3 -2
- package/declarations/components/forms/select/native-mirror.d.ts.map +1 -1
- package/declarations/components/forms/select/select.d.ts +42 -3
- package/declarations/components/forms/select/select.d.ts.map +1 -1
- package/declarations/components/forms/select/types.d.ts +36 -1
- package/declarations/components/forms/select/types.d.ts.map +1 -1
- package/declarations/components/overlays/overlay.d.ts +17 -2
- package/declarations/components/overlays/overlay.d.ts.map +1 -1
- package/declarations/test-support.d.ts.map +1 -1
- package/declarations/utils/filter.d.ts +30 -0
- package/declarations/utils/filter.d.ts.map +1 -1
- package/dist/components/collections/calendar/year-grid.js +1 -30
- package/dist/components/collections/calendar/year-grid.js.map +1 -1
- package/dist/components/forms/autocomplete.js +35 -4
- package/dist/components/forms/autocomplete.js.map +1 -1
- package/dist/components/forms/date-input/segment-group.js +1 -1
- package/dist/components/forms/date-input/segment-group.js.map +1 -1
- package/dist/components/forms/date-input/segments.js +1 -1
- package/dist/components/forms/date-input/segments.js.map +1 -1
- package/dist/components/forms/date-input.js +1 -1
- package/dist/components/forms/date-picker/date-picker.js +57 -6
- package/dist/components/forms/date-picker/date-picker.js.map +1 -1
- package/dist/components/forms/date-picker/time-columns.js +238 -0
- package/dist/components/forms/date-picker/time-columns.js.map +1 -0
- package/dist/components/forms/index.js +1 -1
- package/dist/components/forms/select/native-mirror.js.map +1 -1
- package/dist/components/forms/select/select.js +76 -4
- package/dist/components/forms/select/select.js.map +1 -1
- package/dist/components/overlays/overlay.js +55 -7
- package/dist/components/overlays/overlay.js.map +1 -1
- package/dist/forms.js +1 -1
- package/dist/index.js +1 -1
- package/dist/reveal-within-BcqpOmSI.js +33 -0
- package/dist/reveal-within-BcqpOmSI.js.map +1 -0
- package/dist/test-support.js +3 -1
- package/dist/test-support.js.map +1 -1
- package/dist/utils/filter.js +32 -1
- package/dist/utils/filter.js.map +1 -1
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"autocomplete.js","sources":["../../../src/components/forms/autocomplete.gts"],"sourcesContent":["import Component from '@glimmer/component';\nimport { tracked, cached } from '@glimmer/tracking';\nimport { on } from '@ember/modifier';\nimport type Owner from '@ember/owner';\nimport { NativeSelect, type ListItem } from './native-select';\nimport { Listbox, type ListboxSignature } from '../collections/listbox';\nimport {\n useStyles,\n type AutocompleteSlots,\n type AutocompleteVariants,\n type SlotsToClasses\n} from '@frontile/theme';\nimport { Spinner } from '../utilities/spinner';\nimport { VisuallyHidden } from '../utilities/visually-hidden';\nimport { ref } from '../../utils/ref';\nimport { ControlBlurTracker } from '../../-private/control-blur';\nimport {\n Popover,\n type PopoverSignature,\n type ContentSignature\n} from '../overlays/popover';\nimport { FormControl, type FormControlSharedArgs } from './form-control';\nimport { triggerFormInputEvent } from '../../utils/forms-utils-index';\nimport { CloseButton } from '../buttons/close-button';\nimport { IconChevronUpDown } from '../../-private/icons';\nimport { keyAndLabelForItem } from '../../utils/listManager';\nimport { filterAndRankItems, type FilterFn } from '../../utils/filter';\nimport { debounce, cancel } from '@ember/runloop';\nimport { renamedArgValue } from '../../-private/deprecated-args';\n\nimport { modifier } from 'ember-modifier';\n\ninterface AutocompleteArgs<T>\n extends\n Pick<\n PopoverSignature['Args'],\n | 'placement'\n | 'flipOptions'\n | 'middleware'\n | 'shiftOptions'\n | 'offsetOptions'\n | 'strategy'\n | 'didClose'\n >,\n Pick<\n ListboxSignature<T>['Args'],\n | 'variant'\n | 'appearance'\n | 'color'\n | 'intent'\n | 'disabledKeys'\n | 'allowEmpty'\n | 'items'\n | 'onAction'\n >,\n Pick<\n ContentSignature['Args'],\n | 'renderInPlace'\n | 'target'\n | 'transitionDuration'\n | 'backdrop'\n | 'disableTransitions'\n | 'focusTrapOptions'\n | 'closeOnOutsideClick'\n | 'closeOnEscapeKey'\n | 'backdropTransition'\n | 'transition'\n >,\n FormControlSharedArgs {\n /**\n * The currently selected key.\n *\n * Autocomplete is single-selection only — for a searchable multi-select,\n * use `Select` with `@isFilterable` and `@selectionMode=\"multiple\"`.\n *\n * **Data Flow:**\n * - Pass this to set the initial selection\n * - Update this in your `onSelectionChange` handler to maintain two-way binding\n * - The component calls `onSelectionChange` whenever the user changes the selection\n */\n selectedKey?: string | null;\n\n /**\n * Callback fired when the selection changes.\n *\n * Update your `@selectedKey` state in this callback to maintain two-way binding.\n *\n * @param key - The newly selected key, or null if selection was cleared\n */\n onSelectionChange?: (key: string | null) => void;\n /**\n * The unique identifier for the autocomplete component.\n */\n id?: string;\n\n /**\n * Defines the input size of the autocomplete.\n */\n inputSize?: AutocompleteVariants['size'];\n\n /**\n * Defines the size of the popover dropdown.\n * - 'sm': Small\n * - 'md': Medium\n * - 'lg': Large\n * - 'trigger': Same size as the trigger\n *\n * @defaultValue 'trigger'\n */\n popoverSize?: 'sm' | 'md' | 'lg' | 'trigger';\n\n /**\n * Custom classes to style different slots within the autocomplete component.\n */\n classes?: SlotsToClasses<AutocompleteSlots>;\n\n /**\n * Whether the autocomplete should close upon selecting an item.\n *\n * @defaultValue true\n */\n closeOnItemSelect?: boolean;\n\n /**\n * Whether scrolling should be blocked when the dropdown is open.\n *\n * @defaultValue true\n */\n blockScroll?: boolean;\n\n /**\n * Whether the focus trap should be disabled when the dropdown is open.\n *\n * @defaultValue true\n */\n disableFocusTrap?: boolean;\n\n /**\n * The placeholder text displayed when the input is empty.\n */\n placeholder?: string;\n\n /**\n * Whether the autocomplete should be disabled, preventing user interaction.\n */\n isDisabled?: boolean;\n\n /**\n * The text value of the input.\n *\n * Pass this together with `onInputChange` to control the input text externally,\n * for example to implement server-side filtering.\n */\n inputValue?: string;\n\n /**\n * Callback fired whenever the user changes the input text.\n *\n * @param value - The current text of the input\n */\n onInputChange?: (value: string) => void;\n\n /**\n * Function to filter the items against the current input text.\n *\n * The default implementation ranks by relevance, so the closest match is\n * listed first rather than whichever match came first in `@items`.\n *\n * @param itemValue - The label of an item in the dropdown.\n * @param inputValue - The user's input text.\n * @returns A number to rank (higher first, `0` means no match) or a boolean\n * to filter only, preserving the order of `@items`.\n */\n filter?: FilterFn;\n\n /**\n * Disables the built-in filtering, rendering `@items` as-is.\n * Use together with `inputValue`/`onInputChange` when filtering happens\n * outside of the component (e.g. server-side).\n *\n * @defaultValue false\n */\n disableFiltering?: boolean;\n\n /**\n * Async search function. When provided, the component calls it (debounced)\n * as the user types and renders the resolved items, showing a loading\n * spinner while the returned promise is pending. Stale responses are\n * ignored (latest query wins). Built-in filtering is disabled; `@items`\n * is used as the initial list before the first search.\n *\n * @param query - The current input text\n * @returns The items matching the query\n */\n onSearch?: (query: string) => Promise<T[]> | T[];\n\n /**\n * Debounce duration, in milliseconds, applied to `onSearch` calls.\n *\n * @defaultValue 250\n */\n searchDebounce?: number;\n\n /**\n * When true, the text typed by the user is kept on blur/close even if it\n * does not match any option. By default the input reverts to the selected\n * item's label (or empty) when the dropdown closes without a selection.\n *\n * @defaultValue false\n */\n allowsCustomValue?: boolean;\n\n /**\n * If true, the autocomplete will show a loading spinner instead of the dropdown icon.\n * The spinner is also shown automatically while an `onSearch` promise is pending.\n */\n isLoading?: boolean;\n\n /**\n * The name attribute for the autocomplete component, useful for form submissions.\n */\n name?: string;\n\n /**\n * Whether to include a clear button in the autocomplete component.\n * If enabled, this allows users to clear the selection and input text.\n *\n * This option deliberately overrides `allowEmpty`: that argument governs\n * deselecting an *option* in the listbox, while this is a separate affordance\n * you opt into for exactly the purpose of emptying the field. Since\n * `allowEmpty` defaults to false, honouring it here would render the button\n * dead by default.\n *\n * No clear button is rendered on a disabled Autocomplete.\n *\n * @defaultValue false\n */\n isClearable?: boolean;\n\n /**\n * Controls pointer-events property of startContent.\n * If you want to pass the click event to the input, set it to `none`.\n *\n * @defaultValue 'auto'\n */\n startContentPointerEvents?: 'none' | 'auto';\n\n /**\n * Controls pointer-events property of endContent.\n * Defaults to `none` to pass click events to the input. If your content\n * needs to capture events, add the `pointer-events-auto` class to that element.\n *\n * @defaultValue 'none'\n */\n endContentPointerEvents?: 'none' | 'auto';\n\n /**\n * If true, hides the empty content when there are no options available.\n *\n * @defaultValue false\n */\n hideEmptyContent?: boolean;\n\n /**\n * Message shown in the dropdown of an async autocomplete (`onSearch`)\n * while the query is blank — e.g. \"Type to search for an address…\".\n * Prompts the user to start typing when they open the dropdown by\n * clicking. Also customizable via the `searchMessage` block.\n */\n searchMessage?: string;\n\n /**\n * Callback fired when focus leaves the Autocomplete.\n *\n * \"Leaves the Autocomplete\" means the whole control: the input *and* its\n * dropdown, which is rendered outside the input in the DOM. Moving focus\n * between them -- which is what clicking an option does -- is not a blur, so\n * this does not fire while the user is picking an option. It fires once, when\n * focus lands somewhere outside the control (or nowhere, with the dropdown\n * closed).\n *\n * This is what `Field` drives blur validation from.\n */\n onBlur?: () => void;\n}\n\ninterface AutocompleteSignature<T> {\n Args: AutocompleteArgs<T>;\n Element: HTMLDivElement;\n Blocks: ListboxSignature<T>['Blocks'] & {\n /**\n * Content to display at the **beginning** of the autocomplete component.\n * This can be an icon, a label, or any custom UI element.\n */\n startContent: [];\n\n /**\n * Content to display at the **end** of the autocomplete component.\n * This can be an icon, a button, or any custom UI element.\n */\n endContent: [];\n\n /**\n * The content to display when there are no matching options.\n * If `hideEmptyContent` argument is true, this content will not be shown.\n */\n emptyContent: [];\n\n /**\n * Message shown in the dropdown of an async autocomplete while the\n * query is blank, prompting the user to start typing. Takes priority\n * over the `searchMessage` argument.\n */\n searchMessage: [];\n };\n}\n\n/**\n * Autocomplete Component - a text input combined with a listbox popover,\n * following the WAI-ARIA 1.2 combobox pattern.\n *\n * Users filter the options by typing (type-ahead). Options can come from a\n * static list (built-in filtering), an externally filtered list\n * (`disableFiltering` + `onInputChange`), or an async source (`onSearch`).\n *\n */\nclass Autocomplete<T = unknown> extends Component<AutocompleteSignature<T>> {\n @tracked nodes: ListItem[] = [];\n @tracked isOpen = false;\n\n /**\n * Internal tracked selection state.\n * Synced with @selectedKey via the updateSelectedKey modifier.\n */\n @tracked _selectedKey: string | null = null;\n\n /**\n * The text the user has typed. `undefined` means the user is not editing,\n * so the input displays the selected item's label instead.\n */\n @tracked _inputValue?: string;\n\n /**\n * Items resolved from the latest `onSearch` call. `undefined` until the\n * first search resolves; `@items` is rendered in the meantime.\n */\n @tracked asyncItems?: T[];\n\n @tracked isSearchPending = false;\n\n /** Monotonic token to discard out-of-order onSearch resolutions. */\n #searchToken = 0;\n\n #pendingSearch?: ReturnType<typeof debounce>;\n\n /** Element id of the currently active (highlighted) option, for aria-activedescendant. */\n @tracked activeDescendant?: string;\n\n /**\n * Label of the selected key, captured at selection time. Needed in async\n * mode, where the selected item may no longer be present in the currently\n * rendered items (e.g. after search results are reset on close).\n */\n @tracked selectedLabel?: string;\n\n containerRef = ref<HTMLDivElement>();\n triggerRef = ref<HTMLInputElement>();\n\n constructor(owner: Owner, args: AutocompleteArgs<T>) {\n super(owner, args);\n this._selectedKey = this.args.selectedKey || null;\n }\n\n willDestroy(): void {\n super.willDestroy();\n if (this.#pendingSearch) {\n cancel(this.#pendingSearch);\n }\n // Nothing may resolve against a destroyed component.\n this.blurTracker.cancel();\n }\n\n onSelectionChange = (keys: string[]) => {\n this.applySelection(keys[0] ?? null);\n };\n\n onNativeSelectionChange = (key: string | null) => {\n this.applySelection(key);\n };\n\n applySelection(key: string | null) {\n this.selectedLabel = key\n ? this.nodes.find((n) => n.key === key)?.textValue\n : undefined;\n this._selectedKey = key;\n this.args.onSelectionChange?.(key);\n this.clearInputValue();\n triggerFormInputEvent(this.containerRef.current);\n }\n\n onOpenChange = (isOpen: boolean) => {\n this.isOpen = isOpen;\n };\n\n onInput = (event: Event) => {\n const target = event.target as HTMLInputElement;\n this.setInputValue(target.value);\n\n if (!this.isOpen) {\n this.isOpen = true;\n }\n };\n\n setInputValue(value: string) {\n this._inputValue = value;\n\n if (typeof this.args.onInputChange === 'function') {\n this.args.onInputChange(value);\n }\n\n if (typeof this.args.onSearch === 'function') {\n if (value === '') {\n // A blank query shows the default `@items` again instead of searching.\n this.resetSearch();\n return;\n }\n\n this.isSearchPending = true;\n this.#pendingSearch = debounce(\n this,\n this.performSearch,\n value,\n this.args.searchDebounce ?? 250\n );\n }\n }\n\n /** Cancels any in-flight search and restores the default `@items`. */\n resetSearch() {\n if (this.#pendingSearch) {\n cancel(this.#pendingSearch);\n }\n this.#searchToken++;\n this.asyncItems = undefined;\n this.isSearchPending = false;\n }\n\n clearInputValue() {\n this._inputValue = undefined;\n if (typeof this.args.onInputChange === 'function') {\n this.args.onInputChange('');\n }\n }\n\n async performSearch(query: string) {\n const token = ++this.#searchToken;\n\n try {\n const result = await this.args.onSearch?.(query);\n if (token === this.#searchToken && !this.isDestroying) {\n this.asyncItems = result;\n }\n } finally {\n if (token === this.#searchToken && !this.isDestroying) {\n this.isSearchPending = false;\n }\n }\n }\n\n onKeyDown = (event: KeyboardEvent) => {\n if (event.key === 'Enter' && this.isOpen) {\n // Prevent form submission while the dropdown is open. Selecting the\n // active option is the Listbox's job: it handles Enter on keydown, so\n // canceling this event no longer suppresses the one it listens to.\n event.preventDefault();\n }\n };\n\n /** Current selection as an array, for the Listbox / NativeSelect API. */\n get selectedKeys(): string[] {\n return this._selectedKey ? [this._selectedKey] : [];\n }\n\n get blockScroll() {\n return this.args.blockScroll !== false;\n }\n\n get disableFocusTrap() {\n return this.args.disableFocusTrap !== false;\n }\n\n onAction = (key: string) => {\n if (typeof this.args.onAction === 'function') {\n this.args.onAction(key);\n }\n\n if (this.args.closeOnItemSelect !== false) {\n this.isOpen = false;\n }\n\n // Deliberately does not touch `@onBlur`. Picking an option is not focus\n // leaving the control; `blurTracker` decides that from the input's own\n // `focusout`.\n };\n\n /**\n * Reports focus leaving the *whole* control -- the input and its portaled\n * dropdown -- rather than the input, which blurs on the way into the\n * dropdown whenever an option is clicked. See `ControlBlurTracker`.\n */\n blurTracker = new ControlBlurTracker({\n trigger: () => this.triggerRef.current,\n container: () => this.containerRef.current,\n isOpen: () => this.isOpen,\n isDestroyed: () => this.isDestroyed || this.isDestroying,\n onBlur: () => this.args.onBlur?.()\n });\n\n clearSelectedKeys = () => {\n this.onSelectionChange([]);\n this.clearInputValue();\n this.triggerRef.current?.focus();\n };\n\n onItemsChange = (nodes: ListItem[], _: 'add' | 'remove') => {\n this.nodes = nodes;\n };\n\n didClose = () => {\n if (!this.args.allowsCustomValue) {\n this._inputValue = undefined;\n }\n this.activeDescendant = undefined;\n\n // Reset async results so reopening shows the default `@items` again.\n if (typeof this.args.onSearch === 'function') {\n this.resetSearch();\n }\n\n this.args.didClose?.();\n };\n\n onActiveItemChange = (_key?: string, item?: ListItem) => {\n this.activeDescendant = item?.el.id || undefined;\n };\n\n get selectedTextValue(): string {\n const key = this._selectedKey;\n if (!key) {\n return '';\n }\n const node = this.nodes.find((n) => n.key === key);\n return node?.textValue ?? this.selectedLabel ?? key;\n }\n\n get inputValue(): string {\n if (typeof this.args.inputValue === 'string') {\n return this.args.inputValue;\n }\n if (this._inputValue !== undefined) {\n return this._inputValue;\n }\n return this.selectedTextValue;\n }\n\n get isFiltering(): boolean {\n const value =\n typeof this.args.inputValue === 'string'\n ? this.args.inputValue\n : this._inputValue;\n\n return typeof value === 'string' && value !== '';\n }\n\n get backdrop() {\n return this.args.backdrop ?? 'transparent';\n }\n\n @cached\n get classes() {\n const { autocomplete } = useStyles();\n // Referenced here, on the always-rendered root, so `@appearance`/\n // `@variant` (and `@intent`/`@color`) raises its deprecation regardless\n // of whether the popover content (and so the internal `Listbox`) is\n // currently mounted.\n void this.variant;\n void this.color;\n return autocomplete({\n size: this.args.inputSize\n });\n }\n\n /**\n * Resolved once (`@cached`) and forwarded to the internal `Listbox` as\n * `@variant` only -- never `@appearance` as well, which would make the\n * inner `Listbox` raise its own deprecation for the same usage.\n */\n @cached\n get variant() {\n return renamedArgValue(\n this.args.variant,\n this.args.appearance,\n { default: 'solid', outlined: 'outline', faded: 'subtle' } as const,\n {\n component: 'Autocomplete',\n from: 'appearance',\n to: 'variant',\n id: 'frontile.autocomplete.appearance'\n }\n );\n }\n\n /**\n * Resolved once (`@cached`) and forwarded to the internal `Listbox` as\n * `@color` only -- never `@intent` as well, which would make the inner\n * `Listbox` raise its own deprecation for the same usage.\n */\n @cached\n get color() {\n return renamedArgValue(\n this.args.color,\n this.args.intent,\n { default: 'neutral' } as const,\n {\n component: 'Autocomplete',\n from: 'intent',\n to: 'color',\n id: 'frontile.autocomplete.intent'\n }\n );\n }\n\n /**\n * Whether the clear button takes the chevron's place: something to clear,\n * and a control that can act on it.\n *\n * `@allowEmpty` is deliberately not consulted -- it governs deselecting an\n * *option* in the listbox, while `@isClearable` is a separate affordance the\n * consumer opts into for exactly this purpose (and `@allowEmpty` defaults to\n * false, so honouring it here would leave the button dead by default). A\n * disabled Autocomplete shows no clear button at all: it carries no disabled\n * state of its own, so it would be a focusable button that clears a field\n * the user is not allowed to change.\n */\n get isClearable() {\n return (\n this.args.isClearable &&\n !this.args.isDisabled &&\n (this.selectedKeys.length > 0 || this.isFiltering)\n );\n }\n\n get isLoading() {\n return this.args.isLoading || this.isSearchPending;\n }\n\n @cached\n get filteredItems() {\n if (typeof this.args.onSearch === 'function') {\n return this.asyncItems ?? this.args.items;\n }\n\n if (this.args.disableFiltering || !this.isFiltering) {\n return this.args.items;\n }\n\n return filterAndRankItems(\n this.args.items,\n this.inputValue,\n (item) => keyAndLabelForItem(item).label,\n this.args.filter\n );\n }\n\n /**\n * True when an async autocomplete is open with a blank query and nothing\n * to show — the moment to prompt the user to start typing.\n */\n get isSearchPromptState(): boolean {\n return (\n typeof this.args.onSearch === 'function' &&\n !this.isFiltering &&\n !this.isLoading &&\n (this.filteredItems?.length ?? 0) === 0\n );\n }\n\n get showEmptyContent() {\n return (\n this.filteredItems?.length === 0 &&\n !this.isLoading &&\n !this.args.hideEmptyContent\n );\n }\n\n get autoActivateMode(): 'first' | 'selected' {\n if (this.isFiltering) {\n return 'first';\n }\n return 'selected';\n }\n\n /**\n * Syncs internal `_selectedKey` with external `@selectedKey` argument.\n */\n updateSelectedKey = modifier(\n (_: HTMLDivElement, [selectedKey]: [string | null | undefined]) => {\n if (selectedKey !== undefined) {\n this._selectedKey = selectedKey;\n }\n }\n );\n\n <template>\n <div\n {{this.updateSelectedKey @selectedKey}}\n {{this.containerRef.setup}}\n class={{this.classes.base class=@classes.base}}\n data-component=\"autocomplete\"\n data-part=\"base\"\n ...attributes\n >\n <FormControl\n @id={{@id}}\n @size={{@inputSize}}\n @label={{@label}}\n @isRequired={{@isRequired}}\n @description={{@description}}\n @errors={{@errors}}\n @isInvalid={{@isInvalid}}\n as |c|\n >\n <Popover\n @placement={{@placement}}\n @flipOptions={{@flipOptions}}\n @middleware={{@middleware}}\n @shiftOptions={{@shiftOptions}}\n @offsetOptions={{@offsetOptions}}\n @strategy={{@strategy}}\n @didClose={{this.didClose}}\n @isOpen={{this.isOpen}}\n @onOpenChange={{this.onOpenChange}}\n as |p|\n >\n <VisuallyHidden>\n <NativeSelect\n @items={{this.filteredItems}}\n @allowEmpty={{@allowEmpty}}\n @disabledKeys={{@disabledKeys}}\n @onSelectionChange={{this.onNativeSelectionChange}}\n @selectedKey={{this._selectedKey}}\n @selectionMode=\"single\"\n @onItemsChange={{this.onItemsChange}}\n @placeholder={{@placeholder}}\n @id={{c.id}}\n @name={{@name}}\n tabindex=\"-1\"\n disabled={{@isDisabled}}\n >\n <:item as |l|>\n <l.Item @key={{l.key}}>\n {{l.label}}\n </l.Item>\n </:item>\n <:default as |l|>\n {{! @glint-expect-error: the signature of the native select is not the same as the listbox}}\n {{yield l to=\"default\"}}\n </:default>\n </NativeSelect>\n </VisuallyHidden>\n\n <div\n class={{this.classes.innerContainer class=@classes.innerContainer}}\n data-part=\"inner-container\"\n >\n {{#if (has-block \"startContent\")}}\n <div\n data-part=\"start-content\"\n class={{this.classes.startContent\n class=@classes.startContent\n startContentPointerEvents=(if\n @startContentPointerEvents @startContentPointerEvents \"auto\"\n )\n }}\n >\n {{yield to=\"startContent\"}}\n </div>\n {{/if}}\n {{! aria-expanded and aria-controls are set at runtime by the\n Popover trigger modifier, and role=combobox is not implicit\n on a text input }}\n {{! template-lint-disable no-redundant-role require-mandatory-role-attributes }}\n <input\n type=\"text\"\n role=\"combobox\"\n aria-autocomplete=\"list\"\n aria-activedescendant={{this.activeDescendant}}\n autocomplete=\"off\"\n autocapitalize=\"off\"\n autocorrect=\"off\"\n spellcheck=\"false\"\n {{p.trigger}}\n {{p.anchor}}\n {{this.triggerRef.setup}}\n data-part=\"input\"\n disabled={{@isDisabled}}\n placeholder={{@placeholder}}\n class={{this.classes.input\n class=@classes.input\n hasStartContent=(has-block \"startContent\")\n hasEndContent=true\n }}\n value={{this.inputValue}}\n {{on \"input\" this.onInput}}\n {{on \"keydown\" this.onKeyDown}}\n {{on \"focusout\" this.blurTracker.handleFocusOut}}\n />\n <div\n data-part=\"end-content\"\n class={{this.classes.endContent\n class=@classes.endContent\n endContentPointerEvents=(if\n @endContentPointerEvents @endContentPointerEvents \"none\"\n )\n }}\n >\n {{yield to=\"endContent\"}}\n\n {{#if this.isLoading}}\n <Spinner @size={{if (isSm @inputSize) \"xs\" \"sm\"}} />\n {{else if this.isClearable}}\n <CloseButton\n @title=\"Clear\"\n @variant=\"soft\"\n @size=\"xs\"\n @class={{this.classes.clearButton class=@classes.clearButton}}\n data-part=\"clear-button\"\n @onPress={{this.clearSelectedKeys}}\n />\n {{else}}\n <IconChevronUpDown\n data-part=\"icon\"\n class={{this.classes.icon class=@classes.icon}}\n />\n {{/if}}\n </div>\n </div>\n\n <p.Content\n @size={{if @popoverSize @popoverSize \"trigger\"}}\n @target={{@target}}\n @renderInPlace={{@renderInPlace}}\n @disableFocusTrap={{this.disableFocusTrap}}\n @blockScroll={{this.blockScroll}}\n @transitionDuration={{@transitionDuration}}\n @backdrop={{this.backdrop}}\n @disableTransitions={{@disableTransitions}}\n @focusTrapOptions={{@focusTrapOptions}}\n @closeOnOutsideClick={{@closeOnOutsideClick}}\n @closeOnEscapeKey={{@closeOnEscapeKey}}\n @backdropTransition={{@backdropTransition}}\n @transition={{@transition}}\n @preventAutoFocus={{true}}\n >\n <Listbox\n @items={{this.filteredItems}}\n @allowEmpty={{@allowEmpty}}\n @variant={{this.variant}}\n @disabledKeys={{@disabledKeys}}\n @color={{this.color}}\n @isKeyboardEventsEnabled={{true}}\n @onAction={{this.onAction}}\n @onSelectionChange={{this.onSelectionChange}}\n @onActiveItemChange={{this.onActiveItemChange}}\n @selectedKeys={{this.selectedKeys}}\n @selectionMode=\"single\"\n @type=\"listbox\"\n @class={{this.classes.listbox class=@classes.listbox}}\n @elementToAddKeyboardEvents={{this.triggerRef.current}}\n @autoActivateMode={{this.autoActivateMode}}\n data-part=\"listbox\"\n >\n <:item as |l|>\n {{#if (has-block \"item\")}}\n {{yield l to=\"item\"}}\n {{else}}\n <l.Item\n @key={{l.key}}\n @variant={{this.variant}}\n @color={{this.color}}\n >\n {{l.label}}\n </l.Item>\n {{/if}}\n </:item>\n <:default as |l|>\n {{yield l to=\"default\"}}\n </:default>\n </Listbox>\n {{#if\n (and\n this.isSearchPromptState\n (or @searchMessage (has-block \"searchMessage\"))\n )\n }}\n <div\n class={{this.classes.emptyContent class=@classes.emptyContent}}\n data-part=\"empty-content\"\n >\n {{#if (has-block \"searchMessage\")}}\n {{yield to=\"searchMessage\"}}\n {{else}}\n {{@searchMessage}}\n {{/if}}\n </div>\n {{else if this.showEmptyContent}}\n <div\n class={{this.classes.emptyContent class=@classes.emptyContent}}\n data-part=\"empty-content\"\n >\n {{#if (has-block \"emptyContent\")}}\n {{yield to=\"emptyContent\"}}\n {{else}}\n No results found.\n {{/if}}\n </div>\n {{/if}}\n </p.Content>\n </Popover>\n </FormControl>\n </div>\n </template>\n}\n\nconst isSm = (size: AutocompleteVariants['size']) => size === 'sm';\nconst and = (a: unknown, b: unknown) => Boolean(a) && Boolean(b);\nconst or = (a: unknown, b: unknown) => Boolean(a) || Boolean(b);\n\nexport { Autocomplete, type AutocompleteSignature };\nexport default Autocomplete;\n"],"names":["Autocomplete","Component","g","prototype","tracked","i","containerRef","ref","triggerRef","constructor","owner","args","_selectedKey","selectedKey","willDestroy","cancel","blurTracker","onSelectionChange","keys","applySelection","onNativeSelectionChange","key","selectedLabel","nodes","find","n","textValue","undefined","clearInputValue","triggerFormInputEvent","current","onOpenChange","isOpen","onInput","event","target","setInputValue","value","_inputValue","onInputChange","onSearch","resetSearch","isSearchPending","debounce","performSearch","searchDebounce","asyncItems","query","token","result","isDestroying","onKeyDown","preventDefault","selectedKeys","blockScroll","disableFocusTrap","onAction","closeOnItemSelect","ControlBlurTracker","trigger","container","isDestroyed","onBlur","clearSelectedKeys","focus","onItemsChange","_","didClose","allowsCustomValue","activeDescendant","onActiveItemChange","_key","item","el","id","selectedTextValue","node","inputValue","isFiltering","backdrop","classes","autocomplete","useStyles","variant","color","size","inputSize","cached","renamedArgValue","appearance","default","outlined","faded","component","from","to","intent","isClearable","isDisabled","length","isLoading","filteredItems","items","disableFiltering","filterAndRankItems","keyAndLabelForItem","label","filter","isSearchPromptState","showEmptyContent","hideEmptyContent","autoActivateMode","updateSelectedKey","modifier","setComponentTemplate","precompileTemplate","strictMode","scope","FormControl","Popover","VisuallyHidden","NativeSelect","on","Spinner","isSm","CloseButton","IconChevronUpDown","Listbox","and","or","a","b","Boolean"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA6TA;;;;;;;;AAQC;AACD,MAAMA,YAAA,SAAkCC,UAAgC;AAAA,EAAA;IAAAC,eAAA,CAAA,IAAA,CAAAC,SAAA,EAAA,OAAA,EAAA,CACrEC,OAAA,CAAA,EAAA,YAAA;AAAA,MAAA,OAA4B,EAAE;AAAA,IAAA,CAAA,CAAA;AAAA;EAAA,MAAA,IAAAC,2BAAA,CAAA,IAAA,EAAA,OAAA,CAAA,EAAA,MAAA;AAAA,EAAA;IAAAH,eAAA,CAAA,IAAA,CAAAC,SAAA,EAAA,QAAA,EAAA,CAC9BC,OAAA,CAAA,EAAA,YAAA;AAAA,MAAA,OAAiB,KAAA;AAAA,IAAA,CAAA,CAAA;AAAA;EAAA,OAAA,IAAAC,2BAAA,CAAA,IAAA,EAAA,QAAA,CAAA,EAAA,MAAA;AAAA,EAAA;IAAAH,eAAA,CAAA,IAAA,CAAAC,SAAA,EAAA,cAAA,EAAA,CAMjBC,OAAA,CAAA,EAAA,YAAA;AAAA,MAAA,OAAsC,IAAA;AAAA,IAAA,CAAA,CAAA;AAAA;EAAA,aAAA,IAAAC,2BAAA,CAAA,IAAA,EAAA,cAAA,CAAA,EAAA,MAAA;AAJvC;;;AAGC;AAHD,EAAA;IAAAH,eAAA,CAAA,IAAA,CAAAC,SAAA,EAAA,aAAA,EAAA,CAUCC,OAAA,CAAA,CAAA;AAAA;EAAA,YAAA,IAAAC,2BAAA,CAAA,IAAA,EAAA,aAAA,CAAA,EAAA,MAAA;AAJD;;;AAGC;AAHD,EAAA;IAAAH,eAAA,CAAA,IAAA,CAAAC,SAAA,EAAA,YAAA,EAAA,CAUCC,OAAA,CAAA,CAAA;AAAA;EAAA,WAAA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AA,CAAAC,kBAAA,CAAA,8sLAAA,EA0NA;MAAAC,UAAA,EAAA,IAAA;AAAAC,MAAAA,KAAA,EAAAA,OAAA;QAAAC,WAAA;QAAAC,OAAA;QAAAC,cAAA;QAAAC,YAAA;QAAAC,EAAA;QAAAC,OAAA;QAAAC,IAAA;QAAAC,WAAA;QAAAC,iBAAA;QAAAC,OAAA;QAAAC,GAAA;AAAAC,QAAAA;AAAA,OAAA;KAAU,CAAA,EAAV,IAAW,CAAA;AAAD;AACZ;AAEA,MAAML,IAAA,GAAQvC,QAAuCA,IAAA,KAAS,IAAA;AAC9D,MAAM2C,GAAA,GAAMA,CAACE,CAAU,EAAEC,CAAU,KAAKC,OAAA,CAAQF,CAAA,CAAA,IAAME,OAAA,CAAQD,CAAA,CAAA;AAC9D,MAAMF,EAAA,GAAKA,CAACC,CAAU,EAAEC,CAAU,KAAKC,OAAA,CAAQF,CAAA,CAAA,IAAME,OAAA,CAAQD,CAAA,CAAA;;"}
|
|
1
|
+
{"version":3,"file":"autocomplete.js","sources":["../../../src/components/forms/autocomplete.gts"],"sourcesContent":["import Component from '@glimmer/component';\nimport { tracked, cached } from '@glimmer/tracking';\nimport { on } from '@ember/modifier';\nimport type Owner from '@ember/owner';\nimport { NativeSelect, type ListItem } from './native-select';\nimport { Listbox, type ListboxSignature } from '../collections/listbox';\nimport {\n useStyles,\n type AutocompleteSlots,\n type AutocompleteVariants,\n type SlotsToClasses\n} from '@frontile/theme';\nimport { Spinner } from '../utilities/spinner';\nimport { VisuallyHidden } from '../utilities/visually-hidden';\nimport { ref } from '../../utils/ref';\nimport { ControlBlurTracker } from '../../-private/control-blur';\nimport {\n Popover,\n type PopoverSignature,\n type ContentSignature\n} from '../overlays/popover';\nimport { FormControl, type FormControlSharedArgs } from './form-control';\nimport { triggerFormInputEvent } from '../../utils/forms-utils-index';\nimport { CloseButton } from '../buttons/close-button';\nimport { IconChevronUpDown } from '../../-private/icons';\nimport { keyAndLabelForItem } from '../../utils/listManager';\nimport {\n filterAndRankItems,\n limitItems,\n type FilterFn,\n type DisplayLimitContentArgs\n} from '../../utils/filter';\nimport { debounce, cancel } from '@ember/runloop';\nimport { assert } from '@ember/debug';\nimport { renamedArgValue } from '../../-private/deprecated-args';\n\nimport { modifier } from 'ember-modifier';\n\ninterface AutocompleteArgs<T>\n extends\n Pick<\n PopoverSignature['Args'],\n | 'placement'\n | 'flipOptions'\n | 'middleware'\n | 'shiftOptions'\n | 'offsetOptions'\n | 'strategy'\n | 'didClose'\n >,\n Pick<\n ListboxSignature<T>['Args'],\n | 'variant'\n | 'appearance'\n | 'color'\n | 'intent'\n | 'disabledKeys'\n | 'allowEmpty'\n | 'items'\n | 'onAction'\n >,\n Pick<\n ContentSignature['Args'],\n | 'renderInPlace'\n | 'target'\n | 'transitionDuration'\n | 'backdrop'\n | 'disableTransitions'\n | 'focusTrapOptions'\n | 'closeOnOutsideClick'\n | 'closeOnEscapeKey'\n | 'backdropTransition'\n | 'transition'\n >,\n FormControlSharedArgs {\n /**\n * The currently selected key.\n *\n * Autocomplete is single-selection only — for a searchable multi-select,\n * use `Select` with `@isFilterable` and `@selectionMode=\"multiple\"`.\n *\n * **Data Flow:**\n * - Pass this to set the initial selection\n * - Update this in your `onSelectionChange` handler to maintain two-way binding\n * - The component calls `onSelectionChange` whenever the user changes the selection\n */\n selectedKey?: string | null;\n\n /**\n * Callback fired when the selection changes.\n *\n * Update your `@selectedKey` state in this callback to maintain two-way binding.\n *\n * @param key - The newly selected key, or null if selection was cleared\n */\n onSelectionChange?: (key: string | null) => void;\n /**\n * The unique identifier for the autocomplete component.\n */\n id?: string;\n\n /**\n * Defines the input size of the autocomplete.\n */\n inputSize?: AutocompleteVariants['size'];\n\n /**\n * Defines the size of the popover dropdown.\n * - 'sm': Small\n * - 'md': Medium\n * - 'lg': Large\n * - 'trigger': Same size as the trigger\n *\n * @defaultValue 'trigger'\n */\n popoverSize?: 'sm' | 'md' | 'lg' | 'trigger';\n\n /**\n * Custom classes to style different slots within the autocomplete component.\n */\n classes?: SlotsToClasses<AutocompleteSlots>;\n\n /**\n * Whether the autocomplete should close upon selecting an item.\n *\n * @defaultValue true\n */\n closeOnItemSelect?: boolean;\n\n /**\n * Whether scrolling should be blocked when the dropdown is open.\n *\n * @defaultValue true\n */\n blockScroll?: boolean;\n\n /**\n * Whether the focus trap should be disabled when the dropdown is open.\n *\n * @defaultValue true\n */\n disableFocusTrap?: boolean;\n\n /**\n * The placeholder text displayed when the input is empty.\n */\n placeholder?: string;\n\n /**\n * Whether the autocomplete should be disabled, preventing user interaction.\n */\n isDisabled?: boolean;\n\n /**\n * The text value of the input.\n *\n * Pass this together with `onInputChange` to control the input text externally,\n * for example to implement server-side filtering.\n */\n inputValue?: string;\n\n /**\n * Callback fired whenever the user changes the input text.\n *\n * @param value - The current text of the input\n */\n onInputChange?: (value: string) => void;\n\n /**\n * Function to filter the items against the current input text.\n *\n * The default implementation ranks by relevance, so the closest match is\n * listed first rather than whichever match came first in `@items`.\n *\n * @param itemValue - The label of an item in the dropdown.\n * @param inputValue - The user's input text.\n * @returns A number to rank (higher first, `0` means no match) or a boolean\n * to filter only, preserving the order of `@items`.\n */\n filter?: FilterFn;\n\n /**\n * Disables the built-in filtering, rendering `@items` as-is.\n * Use together with `inputValue`/`onInputChange` when filtering happens\n * outside of the component (e.g. server-side).\n *\n * @defaultValue false\n */\n disableFiltering?: boolean;\n\n /**\n * The most options the dropdown renders at once.\n *\n * Every rendered option is DOM to build, and to rebuild on each keystroke as\n * the matches change, so a list of hundreds of options makes typing lag.\n * With a limit, only the first `displayLimit` options are rendered, in the\n * order the filter ranked them, and the `displayLimitContent` block says how\n * many more there are. The rest are reached by typing a narrower query.\n *\n * It caps whatever the dropdown would show: the built-in matches, `@items`\n * under `disableFiltering`, or the results of `onSearch`. The selected\n * option is always rendered, even past the limit.\n *\n * @defaultValue undefined (every option is rendered)\n */\n displayLimit?: number;\n\n /**\n * Async search function. When provided, the component calls it (debounced)\n * as the user types and renders the resolved items, showing a loading\n * spinner while the returned promise is pending. Stale responses are\n * ignored (latest query wins). Built-in filtering is disabled; `@items`\n * is used as the initial list before the first search.\n *\n * @param query - The current input text\n * @returns The items matching the query\n */\n onSearch?: (query: string) => Promise<T[]> | T[];\n\n /**\n * Debounce duration, in milliseconds, applied to `onSearch` calls.\n *\n * @defaultValue 250\n */\n searchDebounce?: number;\n\n /**\n * When true, the text typed by the user is kept on blur/close even if it\n * does not match any option. By default the input reverts to the selected\n * item's label (or empty) when the dropdown closes without a selection.\n *\n * @defaultValue false\n */\n allowsCustomValue?: boolean;\n\n /**\n * If true, the autocomplete will show a loading spinner instead of the dropdown icon.\n * The spinner is also shown automatically while an `onSearch` promise is pending.\n */\n isLoading?: boolean;\n\n /**\n * The name attribute for the autocomplete component, useful for form submissions.\n */\n name?: string;\n\n /**\n * Whether to include a clear button in the autocomplete component.\n * If enabled, this allows users to clear the selection and input text.\n *\n * This option deliberately overrides `allowEmpty`: that argument governs\n * deselecting an *option* in the listbox, while this is a separate affordance\n * you opt into for exactly the purpose of emptying the field. Since\n * `allowEmpty` defaults to false, honouring it here would render the button\n * dead by default.\n *\n * No clear button is rendered on a disabled Autocomplete.\n *\n * @defaultValue false\n */\n isClearable?: boolean;\n\n /**\n * Controls pointer-events property of startContent.\n * If you want to pass the click event to the input, set it to `none`.\n *\n * @defaultValue 'auto'\n */\n startContentPointerEvents?: 'none' | 'auto';\n\n /**\n * Controls pointer-events property of endContent.\n * Defaults to `none` to pass click events to the input. If your content\n * needs to capture events, add the `pointer-events-auto` class to that element.\n *\n * @defaultValue 'none'\n */\n endContentPointerEvents?: 'none' | 'auto';\n\n /**\n * If true, hides the empty content when there are no options available.\n *\n * @defaultValue false\n */\n hideEmptyContent?: boolean;\n\n /**\n * If true, hides the display limit content when `@displayLimit` leaves\n * options out.\n *\n * @defaultValue false\n */\n hideDisplayLimitContent?: boolean;\n\n /**\n * Message shown in the dropdown of an async autocomplete (`onSearch`)\n * while the query is blank — e.g. \"Type to search for an address…\".\n * Prompts the user to start typing when they open the dropdown by\n * clicking. Also customizable via the `searchMessage` block.\n */\n searchMessage?: string;\n\n /**\n * Callback fired when focus leaves the Autocomplete.\n *\n * \"Leaves the Autocomplete\" means the whole control: the input *and* its\n * dropdown, which is rendered outside the input in the DOM. Moving focus\n * between them -- which is what clicking an option does -- is not a blur, so\n * this does not fire while the user is picking an option. It fires once, when\n * focus lands somewhere outside the control (or nowhere, with the dropdown\n * closed).\n *\n * This is what `Field` drives blur validation from.\n */\n onBlur?: () => void;\n}\n\ninterface AutocompleteSignature<T> {\n Args: AutocompleteArgs<T>;\n Element: HTMLDivElement;\n Blocks: ListboxSignature<T>['Blocks'] & {\n /**\n * Content to display at the **beginning** of the autocomplete component.\n * This can be an icon, a label, or any custom UI element.\n */\n startContent: [];\n\n /**\n * Content to display at the **end** of the autocomplete component.\n * This can be an icon, a button, or any custom UI element.\n */\n endContent: [];\n\n /**\n * The content to display when there are no matching options.\n * If `hideEmptyContent` argument is true, this content will not be shown.\n */\n emptyContent: [];\n\n /**\n * The content to display below the options when `@displayLimit` leaves\n * some of them out. Yields how many options are shown and how many match\n * in total. If `hideDisplayLimitContent` argument is true, this content\n * will not be shown.\n */\n displayLimitContent: [DisplayLimitContentArgs];\n\n /**\n * Message shown in the dropdown of an async autocomplete while the\n * query is blank, prompting the user to start typing. Takes priority\n * over the `searchMessage` argument.\n */\n searchMessage: [];\n };\n}\n\n/**\n * Autocomplete Component - a text input combined with a listbox popover,\n * following the WAI-ARIA 1.2 combobox pattern.\n *\n * Users filter the options by typing (type-ahead). Options can come from a\n * static list (built-in filtering), an externally filtered list\n * (`disableFiltering` + `onInputChange`), or an async source (`onSearch`).\n *\n */\nclass Autocomplete<T = unknown> extends Component<AutocompleteSignature<T>> {\n @tracked nodes: ListItem[] = [];\n @tracked isOpen = false;\n\n /**\n * Internal tracked selection state.\n * Synced with @selectedKey via the updateSelectedKey modifier.\n */\n @tracked _selectedKey: string | null = null;\n\n /**\n * The text the user has typed. `undefined` means the user is not editing,\n * so the input displays the selected item's label instead.\n */\n @tracked _inputValue?: string;\n\n /**\n * Items resolved from the latest `onSearch` call. `undefined` until the\n * first search resolves; `@items` is rendered in the meantime.\n */\n @tracked asyncItems?: T[];\n\n @tracked isSearchPending = false;\n\n /** Monotonic token to discard out-of-order onSearch resolutions. */\n #searchToken = 0;\n\n #pendingSearch?: ReturnType<typeof debounce>;\n\n /** Element id of the currently active (highlighted) option, for aria-activedescendant. */\n @tracked activeDescendant?: string;\n\n /**\n * Label of the selected key, captured at selection time. Needed in async\n * mode, where the selected item may no longer be present in the currently\n * rendered items (e.g. after search results are reset on close).\n */\n @tracked selectedLabel?: string;\n\n containerRef = ref<HTMLDivElement>();\n triggerRef = ref<HTMLInputElement>();\n\n constructor(owner: Owner, args: AutocompleteArgs<T>) {\n super(owner, args);\n this._selectedKey = this.args.selectedKey || null;\n }\n\n willDestroy(): void {\n super.willDestroy();\n if (this.#pendingSearch) {\n cancel(this.#pendingSearch);\n }\n // Nothing may resolve against a destroyed component.\n this.blurTracker.cancel();\n }\n\n onSelectionChange = (keys: string[]) => {\n this.applySelection(keys[0] ?? null);\n };\n\n onNativeSelectionChange = (key: string | null) => {\n this.applySelection(key);\n };\n\n applySelection(key: string | null) {\n this.selectedLabel = key\n ? this.nodes.find((n) => n.key === key)?.textValue\n : undefined;\n this._selectedKey = key;\n this.args.onSelectionChange?.(key);\n this.clearInputValue();\n triggerFormInputEvent(this.containerRef.current);\n }\n\n onOpenChange = (isOpen: boolean) => {\n this.isOpen = isOpen;\n };\n\n onInput = (event: Event) => {\n const target = event.target as HTMLInputElement;\n this.setInputValue(target.value);\n\n if (!this.isOpen) {\n this.isOpen = true;\n }\n };\n\n setInputValue(value: string) {\n this._inputValue = value;\n\n if (typeof this.args.onInputChange === 'function') {\n this.args.onInputChange(value);\n }\n\n if (typeof this.args.onSearch === 'function') {\n if (value === '') {\n // A blank query shows the default `@items` again instead of searching.\n this.resetSearch();\n return;\n }\n\n this.isSearchPending = true;\n this.#pendingSearch = debounce(\n this,\n this.performSearch,\n value,\n this.args.searchDebounce ?? 250\n );\n }\n }\n\n /** Cancels any in-flight search and restores the default `@items`. */\n resetSearch() {\n if (this.#pendingSearch) {\n cancel(this.#pendingSearch);\n }\n this.#searchToken++;\n this.asyncItems = undefined;\n this.isSearchPending = false;\n }\n\n clearInputValue() {\n this._inputValue = undefined;\n if (typeof this.args.onInputChange === 'function') {\n this.args.onInputChange('');\n }\n }\n\n async performSearch(query: string) {\n const token = ++this.#searchToken;\n\n try {\n const result = await this.args.onSearch?.(query);\n if (token === this.#searchToken && !this.isDestroying) {\n this.asyncItems = result;\n }\n } finally {\n if (token === this.#searchToken && !this.isDestroying) {\n this.isSearchPending = false;\n }\n }\n }\n\n onKeyDown = (event: KeyboardEvent) => {\n if (event.key === 'Enter' && this.isOpen) {\n // Prevent form submission while the dropdown is open. Selecting the\n // active option is the Listbox's job: it handles Enter on keydown, so\n // canceling this event no longer suppresses the one it listens to.\n event.preventDefault();\n }\n };\n\n /** Current selection as an array, for the Listbox / NativeSelect API. */\n get selectedKeys(): string[] {\n return this._selectedKey ? [this._selectedKey] : [];\n }\n\n get blockScroll() {\n return this.args.blockScroll !== false;\n }\n\n get disableFocusTrap() {\n return this.args.disableFocusTrap !== false;\n }\n\n onAction = (key: string) => {\n if (typeof this.args.onAction === 'function') {\n this.args.onAction(key);\n }\n\n if (this.args.closeOnItemSelect !== false) {\n this.isOpen = false;\n }\n\n // Deliberately does not touch `@onBlur`. Picking an option is not focus\n // leaving the control; `blurTracker` decides that from the input's own\n // `focusout`.\n };\n\n /**\n * Reports focus leaving the *whole* control -- the input and its portaled\n * dropdown -- rather than the input, which blurs on the way into the\n * dropdown whenever an option is clicked. See `ControlBlurTracker`.\n */\n blurTracker = new ControlBlurTracker({\n trigger: () => this.triggerRef.current,\n container: () => this.containerRef.current,\n isOpen: () => this.isOpen,\n isDestroyed: () => this.isDestroyed || this.isDestroying,\n onBlur: () => this.args.onBlur?.()\n });\n\n clearSelectedKeys = () => {\n this.onSelectionChange([]);\n this.clearInputValue();\n this.triggerRef.current?.focus();\n };\n\n onItemsChange = (nodes: ListItem[], _: 'add' | 'remove') => {\n this.nodes = nodes;\n };\n\n didClose = () => {\n if (!this.args.allowsCustomValue) {\n this._inputValue = undefined;\n }\n this.activeDescendant = undefined;\n\n // Reset async results so reopening shows the default `@items` again.\n if (typeof this.args.onSearch === 'function') {\n this.resetSearch();\n }\n\n this.args.didClose?.();\n };\n\n onActiveItemChange = (_key?: string, item?: ListItem) => {\n this.activeDescendant = item?.el.id || undefined;\n };\n\n get selectedTextValue(): string {\n const key = this._selectedKey;\n if (!key) {\n return '';\n }\n const node = this.nodes.find((n) => n.key === key);\n return node?.textValue ?? this.selectedLabel ?? key;\n }\n\n get inputValue(): string {\n if (typeof this.args.inputValue === 'string') {\n return this.args.inputValue;\n }\n if (this._inputValue !== undefined) {\n return this._inputValue;\n }\n return this.selectedTextValue;\n }\n\n get isFiltering(): boolean {\n const value =\n typeof this.args.inputValue === 'string'\n ? this.args.inputValue\n : this._inputValue;\n\n return typeof value === 'string' && value !== '';\n }\n\n get backdrop() {\n return this.args.backdrop ?? 'transparent';\n }\n\n @cached\n get classes() {\n const { autocomplete } = useStyles();\n // Referenced here, on the always-rendered root, so `@appearance`/\n // `@variant` (and `@intent`/`@color`) raises its deprecation regardless\n // of whether the popover content (and so the internal `Listbox`) is\n // currently mounted.\n void this.variant;\n void this.color;\n return autocomplete({\n size: this.args.inputSize\n });\n }\n\n /**\n * Resolved once (`@cached`) and forwarded to the internal `Listbox` as\n * `@variant` only -- never `@appearance` as well, which would make the\n * inner `Listbox` raise its own deprecation for the same usage.\n */\n @cached\n get variant() {\n return renamedArgValue(\n this.args.variant,\n this.args.appearance,\n { default: 'solid', outlined: 'outline', faded: 'subtle' } as const,\n {\n component: 'Autocomplete',\n from: 'appearance',\n to: 'variant',\n id: 'frontile.autocomplete.appearance'\n }\n );\n }\n\n /**\n * Resolved once (`@cached`) and forwarded to the internal `Listbox` as\n * `@color` only -- never `@intent` as well, which would make the inner\n * `Listbox` raise its own deprecation for the same usage.\n */\n @cached\n get color() {\n return renamedArgValue(\n this.args.color,\n this.args.intent,\n { default: 'neutral' } as const,\n {\n component: 'Autocomplete',\n from: 'intent',\n to: 'color',\n id: 'frontile.autocomplete.intent'\n }\n );\n }\n\n /**\n * Whether the clear button takes the chevron's place: something to clear,\n * and a control that can act on it.\n *\n * `@allowEmpty` is deliberately not consulted -- it governs deselecting an\n * *option* in the listbox, while `@isClearable` is a separate affordance the\n * consumer opts into for exactly this purpose (and `@allowEmpty` defaults to\n * false, so honouring it here would leave the button dead by default). A\n * disabled Autocomplete shows no clear button at all: it carries no disabled\n * state of its own, so it would be a focusable button that clears a field\n * the user is not allowed to change.\n */\n get isClearable() {\n return (\n this.args.isClearable &&\n !this.args.isDisabled &&\n (this.selectedKeys.length > 0 || this.isFiltering)\n );\n }\n\n get isLoading() {\n return this.args.isLoading || this.isSearchPending;\n }\n\n @cached\n get filteredItems() {\n if (typeof this.args.onSearch === 'function') {\n return this.asyncItems ?? this.args.items;\n }\n\n if (this.args.disableFiltering || !this.isFiltering) {\n return this.args.items;\n }\n\n return filterAndRankItems(\n this.args.items,\n this.inputValue,\n (item) => keyAndLabelForItem(item).label,\n this.args.filter\n );\n }\n\n /**\n * The options the listbox renders: `filteredItems`, capped by\n * `@displayLimit`.\n */\n @cached\n get displayedItems() {\n const { displayLimit } = this.args;\n assert(\n `Autocomplete: @displayLimit must be a positive integer, received ${String(displayLimit)}`,\n displayLimit === undefined ||\n (Number.isInteger(displayLimit) && displayLimit > 0)\n );\n\n const selectedKeys = this.selectedKeys;\n return limitItems(this.filteredItems, displayLimit, (item) =>\n selectedKeys.includes(keyAndLabelForItem(item).key)\n );\n }\n\n /**\n * What the display limit content reports, or `undefined` when nothing is\n * left out.\n */\n get displayLimitContent(): DisplayLimitContentArgs | undefined {\n const shown = this.displayedItems?.length ?? 0;\n const total = this.filteredItems?.length ?? 0;\n if (shown === total || this.args.hideDisplayLimitContent) {\n return undefined;\n }\n return { shown, total };\n }\n\n /**\n * True when an async autocomplete is open with a blank query and nothing\n * to show — the moment to prompt the user to start typing.\n */\n get isSearchPromptState(): boolean {\n return (\n typeof this.args.onSearch === 'function' &&\n !this.isFiltering &&\n !this.isLoading &&\n (this.filteredItems?.length ?? 0) === 0\n );\n }\n\n get showEmptyContent() {\n return (\n this.filteredItems?.length === 0 &&\n !this.isLoading &&\n !this.args.hideEmptyContent\n );\n }\n\n get autoActivateMode(): 'first' | 'selected' {\n if (this.isFiltering) {\n return 'first';\n }\n return 'selected';\n }\n\n /**\n * Syncs internal `_selectedKey` with external `@selectedKey` argument.\n */\n updateSelectedKey = modifier(\n (_: HTMLDivElement, [selectedKey]: [string | null | undefined]) => {\n if (selectedKey !== undefined) {\n this._selectedKey = selectedKey;\n }\n }\n );\n\n <template>\n <div\n {{this.updateSelectedKey @selectedKey}}\n {{this.containerRef.setup}}\n class={{this.classes.base class=@classes.base}}\n data-component=\"autocomplete\"\n data-part=\"base\"\n ...attributes\n >\n <FormControl\n @id={{@id}}\n @size={{@inputSize}}\n @label={{@label}}\n @isRequired={{@isRequired}}\n @description={{@description}}\n @errors={{@errors}}\n @isInvalid={{@isInvalid}}\n as |c|\n >\n <Popover\n @placement={{@placement}}\n @flipOptions={{@flipOptions}}\n @middleware={{@middleware}}\n @shiftOptions={{@shiftOptions}}\n @offsetOptions={{@offsetOptions}}\n @strategy={{@strategy}}\n @didClose={{this.didClose}}\n @isOpen={{this.isOpen}}\n @onOpenChange={{this.onOpenChange}}\n as |p|\n >\n <VisuallyHidden>\n {{! Limited like the listbox: it holds the options the user can\n pick, and a hidden list of every match would cost the same\n rendering @displayLimit saves. The selection is always kept. }}\n <NativeSelect\n @items={{this.displayedItems}}\n @allowEmpty={{@allowEmpty}}\n @disabledKeys={{@disabledKeys}}\n @onSelectionChange={{this.onNativeSelectionChange}}\n @selectedKey={{this._selectedKey}}\n @selectionMode=\"single\"\n @onItemsChange={{this.onItemsChange}}\n @placeholder={{@placeholder}}\n @id={{c.id}}\n @name={{@name}}\n tabindex=\"-1\"\n disabled={{@isDisabled}}\n >\n <:item as |l|>\n <l.Item @key={{l.key}}>\n {{l.label}}\n </l.Item>\n </:item>\n <:default as |l|>\n {{! @glint-expect-error: the signature of the native select is not the same as the listbox}}\n {{yield l to=\"default\"}}\n </:default>\n </NativeSelect>\n </VisuallyHidden>\n\n <div\n class={{this.classes.innerContainer class=@classes.innerContainer}}\n data-part=\"inner-container\"\n >\n {{#if (has-block \"startContent\")}}\n <div\n data-part=\"start-content\"\n class={{this.classes.startContent\n class=@classes.startContent\n startContentPointerEvents=(if\n @startContentPointerEvents @startContentPointerEvents \"auto\"\n )\n }}\n >\n {{yield to=\"startContent\"}}\n </div>\n {{/if}}\n {{! aria-expanded and aria-controls are set at runtime by the\n Popover trigger modifier, and role=combobox is not implicit\n on a text input }}\n {{! template-lint-disable no-redundant-role require-mandatory-role-attributes }}\n <input\n type=\"text\"\n role=\"combobox\"\n aria-autocomplete=\"list\"\n aria-activedescendant={{this.activeDescendant}}\n autocomplete=\"off\"\n autocapitalize=\"off\"\n autocorrect=\"off\"\n spellcheck=\"false\"\n {{p.trigger}}\n {{p.anchor}}\n {{this.triggerRef.setup}}\n data-part=\"input\"\n disabled={{@isDisabled}}\n placeholder={{@placeholder}}\n class={{this.classes.input\n class=@classes.input\n hasStartContent=(has-block \"startContent\")\n hasEndContent=true\n }}\n value={{this.inputValue}}\n {{on \"input\" this.onInput}}\n {{on \"keydown\" this.onKeyDown}}\n {{on \"focusout\" this.blurTracker.handleFocusOut}}\n />\n <div\n data-part=\"end-content\"\n class={{this.classes.endContent\n class=@classes.endContent\n endContentPointerEvents=(if\n @endContentPointerEvents @endContentPointerEvents \"none\"\n )\n }}\n >\n {{yield to=\"endContent\"}}\n\n {{#if this.isLoading}}\n <Spinner @size={{if (isSm @inputSize) \"xs\" \"sm\"}} />\n {{else if this.isClearable}}\n <CloseButton\n @title=\"Clear\"\n @variant=\"soft\"\n @size=\"xs\"\n @class={{this.classes.clearButton class=@classes.clearButton}}\n data-part=\"clear-button\"\n @onPress={{this.clearSelectedKeys}}\n />\n {{else}}\n <IconChevronUpDown\n data-part=\"icon\"\n class={{this.classes.icon class=@classes.icon}}\n />\n {{/if}}\n </div>\n </div>\n\n <p.Content\n @size={{if @popoverSize @popoverSize \"trigger\"}}\n @target={{@target}}\n @renderInPlace={{@renderInPlace}}\n @disableFocusTrap={{this.disableFocusTrap}}\n @blockScroll={{this.blockScroll}}\n @transitionDuration={{@transitionDuration}}\n @backdrop={{this.backdrop}}\n @disableTransitions={{@disableTransitions}}\n @focusTrapOptions={{@focusTrapOptions}}\n @closeOnOutsideClick={{@closeOnOutsideClick}}\n @closeOnEscapeKey={{@closeOnEscapeKey}}\n @backdropTransition={{@backdropTransition}}\n @transition={{@transition}}\n @preventAutoFocus={{true}}\n >\n <Listbox\n @items={{this.displayedItems}}\n @allowEmpty={{@allowEmpty}}\n @variant={{this.variant}}\n @disabledKeys={{@disabledKeys}}\n @color={{this.color}}\n @isKeyboardEventsEnabled={{true}}\n @onAction={{this.onAction}}\n @onSelectionChange={{this.onSelectionChange}}\n @onActiveItemChange={{this.onActiveItemChange}}\n @selectedKeys={{this.selectedKeys}}\n @selectionMode=\"single\"\n @type=\"listbox\"\n @class={{this.classes.listbox class=@classes.listbox}}\n @elementToAddKeyboardEvents={{this.triggerRef.current}}\n @autoActivateMode={{this.autoActivateMode}}\n data-part=\"listbox\"\n >\n <:item as |l|>\n {{#if (has-block \"item\")}}\n {{yield l to=\"item\"}}\n {{else}}\n <l.Item\n @key={{l.key}}\n @variant={{this.variant}}\n @color={{this.color}}\n >\n {{l.label}}\n </l.Item>\n {{/if}}\n </:item>\n <:default as |l|>\n {{yield l to=\"default\"}}\n </:default>\n </Listbox>\n {{#if\n (and\n this.isSearchPromptState\n (or @searchMessage (has-block \"searchMessage\"))\n )\n }}\n <div\n class={{this.classes.emptyContent class=@classes.emptyContent}}\n data-part=\"empty-content\"\n >\n {{#if (has-block \"searchMessage\")}}\n {{yield to=\"searchMessage\"}}\n {{else}}\n {{@searchMessage}}\n {{/if}}\n </div>\n {{else if this.showEmptyContent}}\n <div\n class={{this.classes.emptyContent class=@classes.emptyContent}}\n data-part=\"empty-content\"\n >\n {{#if (has-block \"emptyContent\")}}\n {{yield to=\"emptyContent\"}}\n {{else}}\n No results found.\n {{/if}}\n </div>\n {{/if}}\n {{#if this.displayLimitContent}}\n <div\n class={{this.classes.displayLimitContent\n class=@classes.displayLimitContent\n }}\n data-part=\"display-limit-content\"\n >\n {{#if (has-block \"displayLimitContent\")}}\n {{yield this.displayLimitContent to=\"displayLimitContent\"}}\n {{else}}\n Showing\n {{this.displayLimitContent.shown}}\n of\n {{this.displayLimitContent.total}}. Type to narrow down.\n {{/if}}\n </div>\n {{/if}}\n </p.Content>\n </Popover>\n </FormControl>\n </div>\n </template>\n}\n\nconst isSm = (size: AutocompleteVariants['size']) => size === 'sm';\nconst and = (a: unknown, b: unknown) => Boolean(a) && Boolean(b);\nconst or = (a: unknown, b: unknown) => Boolean(a) || Boolean(b);\n\nexport { Autocomplete, type AutocompleteSignature };\nexport default Autocomplete;\n"],"names":["Autocomplete","Component","g","prototype","tracked","i","containerRef","ref","triggerRef","constructor","owner","args","_selectedKey","selectedKey","willDestroy","cancel","blurTracker","onSelectionChange","keys","applySelection","onNativeSelectionChange","key","selectedLabel","nodes","find","n","textValue","undefined","clearInputValue","triggerFormInputEvent","current","onOpenChange","isOpen","onInput","event","target","setInputValue","value","_inputValue","onInputChange","onSearch","resetSearch","isSearchPending","debounce","performSearch","searchDebounce","asyncItems","query","token","result","isDestroying","onKeyDown","preventDefault","selectedKeys","blockScroll","disableFocusTrap","onAction","closeOnItemSelect","ControlBlurTracker","trigger","container","isDestroyed","onBlur","clearSelectedKeys","focus","onItemsChange","_","didClose","allowsCustomValue","activeDescendant","onActiveItemChange","_key","item","el","id","selectedTextValue","node","inputValue","isFiltering","backdrop","classes","autocomplete","useStyles","variant","color","size","inputSize","cached","renamedArgValue","appearance","default","outlined","faded","component","from","to","intent","isClearable","isDisabled","length","isLoading","filteredItems","items","disableFiltering","filterAndRankItems","keyAndLabelForItem","label","filter","displayedItems","displayLimit","assert","String","Number","isInteger","limitItems","includes","displayLimitContent","shown","total","hideDisplayLimitContent","isSearchPromptState","showEmptyContent","hideEmptyContent","autoActivateMode","updateSelectedKey","modifier","setComponentTemplate","precompileTemplate","strictMode","scope","FormControl","Popover","VisuallyHidden","NativeSelect","on","Spinner","isSm","CloseButton","IconChevronUpDown","Listbox","and","or","a","b","Boolean"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAoWA;;;;;;;;AAQC;AACD,MAAMA,YAAA,SAAkCC,UAAgC;AAAA,EAAA;IAAAC,eAAA,CAAA,IAAA,CAAAC,SAAA,EAAA,OAAA,EAAA,CACrEC,OAAA,CAAA,EAAA,YAAA;AAAA,MAAA,OAA4B,EAAE;AAAA,IAAA,CAAA,CAAA;AAAA;EAAA,MAAA,IAAAC,2BAAA,CAAA,IAAA,EAAA,OAAA,CAAA,EAAA,MAAA;AAAA,EAAA;IAAAH,eAAA,CAAA,IAAA,CAAAC,SAAA,EAAA,QAAA,EAAA,CAC9BC,OAAA,CAAA,EAAA,YAAA;AAAA,MAAA,OAAiB,KAAA;AAAA,IAAA,CAAA,CAAA;AAAA;EAAA,OAAA,IAAAC,2BAAA,CAAA,IAAA,EAAA,QAAA,CAAA,EAAA,MAAA;AAAA,EAAA;IAAAH,eAAA,CAAA,IAAA,CAAAC,SAAA,EAAA,cAAA,EAAA,CAMjBC,OAAA,CAAA,EAAA,YAAA;AAAA,MAAA,OAAsC,IAAA;AAAA,IAAA,CAAA,CAAA;AAAA;EAAA,aAAA,IAAAC,2BAAA,CAAA,IAAA,EAAA,cAAA,CAAA,EAAA,MAAA;AAJvC;;;AAGC;AAHD,EAAA;IAAAH,eAAA,CAAA,IAAA,CAAAC,SAAA,EAA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AAA,IAAA;AAAAC,MAAAA,KAAA,EAAAA,OAAA;QAAAC,WAAA;QAAAC,OAAA;QAAAC,cAAA;QAAAC,YAAA;QAAAC,EAAA;QAAAC,OAAA;QAAAC,IAAA;QAAAC,WAAA;QAAAC,iBAAA;QAAAC,OAAA;QAAAC,GAAA;AAAAC,QAAAA;AAAA,OAAA;KAAU,CAAA,EAAV,IAAW,CAAA;AAAD;AACZ;AAEA,MAAML,IAAA,GAAQnD,QAAuCA,IAAA,KAAS,IAAA;AAC9D,MAAMuD,GAAA,GAAMA,CAACE,CAAU,EAAEC,CAAU,KAAKC,OAAA,CAAQF,CAAA,CAAA,IAAME,OAAA,CAAQD,CAAA,CAAA;AAC9D,MAAMF,EAAA,GAAKA,CAACC,CAAU,EAAEC,CAAU,KAAKC,OAAA,CAAQF,CAAA,CAAA,IAAME,OAAA,CAAQD,CAAA,CAAA;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"segment-group.js","sources":["../../../../src/components/forms/date-input/segment-group.gts"],"sourcesContent":["import Component from '@glimmer/component';\nimport { cached } from '@glimmer/tracking';\nimport { fn } from '@ember/helper';\nimport { on } from '@ember/modifier';\nimport {\n isSegment,\n applyDigit,\n applyLetter,\n commitSegment,\n step,\n clearSegment,\n deleteDigit,\n displaySegment\n} from './segments';\nimport { parsePasted, formatForClipboard, splitRange } from './clipboard';\nimport type {\n Part,\n Segment,\n SegmentType,\n SegmentGroupClasses,\n SegmentGroupUserClasses\n} from './types';\n\ninterface SegmentGroupSignature {\n Args: {\n parts: Part[];\n /** Hands the whole list back; the group holds no state of its own. */\n onPartsChange: (parts: Part[]) => void;\n /**\n * Offered text that reads as two dates rather than one. Only `DatePicker`\n * in `@mode=\"range\"` supplies it, and only to its *start* group: pasting\n * a range into the end of a field and having it rewrite the start would\n * be surprising. Without it, such text is simply declined.\n */\n onRangePaste?: (start: Part[], end: Part[]) => void;\n locale: string;\n placeholderValue: Date;\n isDisabled?: boolean;\n isReadOnly?: boolean;\n isInvalid?: boolean;\n /** Rendered as the group's own id, so a `<label for>` can target it. */\n id?: string;\n /**\n * The field's name. A `role=\"group\"` is not a labelable element, so a\n * sibling `<label for>` does not name it on its own -- this does.\n */\n label?: string;\n labelledBy?: string;\n describedBy?: string;\n segmentLabels?: Partial<Record<SegmentType, string>>;\n /**\n * Only the three slots this group renders, so that `DateInput`'s\n * `dateInput` recipe and `DatePicker`'s `datePicker` recipe both satisfy\n * it. See {@link SegmentGroupClasses}.\n */\n classes: SegmentGroupClasses;\n userClasses?: SegmentGroupUserClasses;\n };\n Element: HTMLDivElement;\n}\n\nconst DEFAULT_LABELS: Record<SegmentType, string> = {\n year: 'year',\n month: 'month',\n day: 'day',\n hour: 'hour',\n minute: 'minute',\n dayPeriod: 'AM/PM'\n};\n\n/** How much PageUp/PageDown moves, per segment. */\nconst PAGE_STEP: Record<SegmentType, number> = {\n day: 7,\n month: 3,\n year: 10,\n hour: 2,\n minute: 15,\n dayPeriod: 1\n};\n\n/**\n * Everything one rendered part needs, resolved to primitives.\n *\n * The template cannot narrow the `Part` union -- `eq` is unavailable and Glint\n * does not carry a type predicate through `{{#if}}` -- so the narrowing happens\n * here, in TypeScript, and the template only ever reads optional primitives.\n * That keeps `part.type` off a `LiteralPart` without a cast anywhere.\n */\ninterface Cell {\n index: number;\n isSegment: boolean;\n /** The segment's display text, or the literal's text. */\n text: string;\n type?: SegmentType;\n isEmpty: boolean;\n label?: string;\n /** `text` for AM/PM, typed by letter; `numeric` for everything else. */\n inputMode: 'numeric' | 'text';\n valueNow?: number;\n valueMin?: number;\n valueMax?: number;\n valueText?: string;\n}\n\n/**\n * One row of date segments. Private: `DateInput` and `DatePicker` both render\n * it, and neither wants the other's `FormControl` wrapper.\n */\nclass SegmentGroup extends Component<SegmentGroupSignature> {\n get isEditable(): boolean {\n return !this.args.isDisabled && !this.args.isReadOnly;\n }\n\n labelFor = (type: SegmentType): string =>\n this.args.segmentLabels?.[type] ?? DEFAULT_LABELS[type];\n\n /**\n * Built once per locale rather than inside {@link valueTextFor}: `cells`\n * recomputes on every keystroke, and an `Intl` constructor is expensive\n * enough that building one per keypress is the costliest thing this\n * component would otherwise do.\n */\n @cached\n get monthNames(): Intl.DateTimeFormat {\n return new Intl.DateTimeFormat(this.args.locale, { month: 'long' });\n }\n\n /**\n * What a screen reader reads instead of the raw number. A month is read by\n * name -- \"January\", not \"1\" -- which is the whole point of `aria-valuetext`.\n */\n valueTextFor = (segment: Segment): string | undefined => {\n if (segment.value === null) return undefined;\n if (segment.labels) return segment.labels[segment.value];\n if (segment.type !== 'month') return String(segment.value);\n\n // Any year and day will do; only the month is read back out.\n return this.monthNames.format(new Date(2026, segment.value - 1, 1));\n };\n\n @cached\n get cells(): Cell[] {\n return this.args.parts.map((part, index) => {\n if (!isSegment(part)) {\n return {\n index,\n isSegment: false,\n isEmpty: false,\n text: part.text,\n inputMode: 'numeric'\n };\n }\n\n return {\n index,\n isSegment: true,\n text: displaySegment(part),\n type: part.type,\n isEmpty: part.value === null,\n label: this.labelFor(part.type),\n inputMode: part.labels ? 'text' : 'numeric',\n // `undefined` rather than `null`: an empty segment has no current\n // value, and `aria-valuenow=\"null\"` would be a value of sorts.\n valueNow: part.value ?? undefined,\n valueMin: part.min,\n valueMax: part.max,\n valueText: this.valueTextFor(part)\n };\n });\n }\n\n /** The segment elements, in document order -- the focus order too. */\n private segmentElements(from: HTMLElement): HTMLElement[] {\n const group = from.closest('[data-part=\"group\"]');\n return group\n ? Array.from(group.querySelectorAll<HTMLElement>('[data-part=\"segment\"]'))\n : [];\n }\n\n /**\n * Left and right are *visual* directions, so in an RTL locale they run\n * against document order: pressing the left arrow in `yyyy/mm/dd` laid out\n * right-to-left should move to the segment drawn to the left, which is the\n * later one in the DOM.\n */\n private focusSibling(from: HTMLElement, delta: number): void {\n const all = this.segmentElements(from);\n const step = this.isRtl(from) ? -delta : delta;\n const next = all[all.indexOf(from) + step];\n next?.focus();\n }\n\n private isRtl(from: HTMLElement): boolean {\n const group = from.closest<HTMLElement>('[data-part=\"group\"]') ?? from;\n return getComputedStyle(group).direction === 'rtl';\n }\n\n private focusEdge(from: HTMLElement, edge: 'first' | 'last'): void {\n const all = this.segmentElements(from);\n (edge === 'first' ? all[0] : all[all.length - 1])?.focus();\n }\n\n /** Replaces one segment by index and reports the new list. */\n private replace(index: number, segment: Segment): void {\n const next = this.args.parts.map((part, i) =>\n i === index ? segment : part\n );\n this.args.onPartsChange(next);\n }\n\n handleKeyDown = (index: number, event: KeyboardEvent): void => {\n const part = this.args.parts[index];\n if (!part || !isSegment(part)) return;\n\n const element = event.target as HTMLElement;\n const { key } = event;\n\n // Navigation works even when the field is read-only; editing does not.\n if (key === 'ArrowRight') {\n event.preventDefault();\n this.focusSibling(element, 1);\n return;\n }\n if (key === 'ArrowLeft') {\n event.preventDefault();\n this.focusSibling(element, -1);\n return;\n }\n if (key === 'Home') {\n event.preventDefault();\n this.focusEdge(element, 'first');\n return;\n }\n if (key === 'End') {\n event.preventDefault();\n this.focusEdge(element, 'last');\n return;\n }\n\n if (!this.isEditable) return;\n\n if (key === 'ArrowUp' || key === 'ArrowDown') {\n event.preventDefault();\n const delta = key === 'ArrowUp' ? 1 : -1;\n this.replace(index, step(part, delta, this.args.placeholderValue));\n return;\n }\n\n if (key === 'PageUp' || key === 'PageDown') {\n event.preventDefault();\n const magnitude = PAGE_STEP[part.type];\n const delta = key === 'PageUp' ? magnitude : -magnitude;\n this.replace(index, step(part, delta, this.args.placeholderValue));\n return;\n }\n\n if (key === 'Backspace') {\n event.preventDefault();\n this.replace(index, deleteDigit(part));\n return;\n }\n\n if (key === 'Delete') {\n event.preventDefault();\n this.replace(index, clearSegment(part));\n return;\n }\n\n if (/^\\d$/.test(key)) {\n event.preventDefault();\n // AM/PM has no digits to take.\n if (part.labels) return;\n const { segment, isFull } = applyDigit(part, key);\n this.replace(index, segment);\n // Advancing before the DOM has caught up is safe: the segment elements\n // are keyed by index and are updated, never re-created.\n if (isFull) this.focusSibling(element, 1);\n return;\n }\n\n if (part.labels && key.length === 1 && !event.metaKey && !event.ctrlKey) {\n event.preventDefault();\n const { segment, isFull } = applyLetter(part, key);\n if (segment !== part) this.replace(index, segment);\n if (isFull) this.focusSibling(element, 1);\n return;\n }\n\n // Everything else -- letters, symbols -- would otherwise be inserted into\n // the contenteditable span as literal text.\n if (key.length === 1 && !event.metaKey && !event.ctrlKey) {\n event.preventDefault();\n }\n };\n\n /**\n * Leaving a segment finishes it: the digits in it stop being something the\n * user is still typing and become their answer, which is what turns a typed\n * `26` into 2026. Tab, arrow-key navigation and a click elsewhere all arrive\n * here, because moving focus is the one thing they have in common.\n */\n handleFocusOut = (index: number): void => {\n if (!this.isEditable) return;\n\n const part = this.args.parts[index];\n if (!part || !isSegment(part) || part.isCommitted) return;\n\n const committed = commitSegment(part);\n // An empty segment commits to itself; reporting it would be churn.\n if (committed !== part) this.replace(index, committed);\n };\n\n /**\n * `contenteditable`'s hazard: anything not handled above arrives here and\n * would be written into the span's DOM, desynchronising the display from the\n * model. Every input type is refused; the model is the only writer.\n */\n handleBeforeInput = (event: Event): void => {\n event.preventDefault();\n };\n\n /**\n * Always `preventDefault`: the browser would otherwise write the pasted text\n * into the contenteditable span, and the model would no longer describe what\n * is on screen. Unparseable text is dropped silently -- a date field that\n * guessed would be worse than one that declined.\n */\n handlePaste = (event: ClipboardEvent): void => {\n event.preventDefault();\n if (!this.isEditable) return;\n\n const text = event.clipboardData?.getData('text/plain') ?? '';\n const parsed = parsePasted(text, this.args.parts);\n if (parsed) {\n this.args.onPartsChange(parsed);\n return;\n }\n\n this.tryRangePaste(text);\n };\n\n /**\n * A second reading of text a single date could not be made of.\n *\n * Both halves are parsed against *this* group's parts, which is sound\n * because the two groups of a range are built from the same locale and\n * format and so have identical shape, and because a half only counts when\n * it parses in full -- nothing of this group's own state survives into the\n * list handed to the other one.\n */\n private tryRangePaste(text: string): void {\n const onRangePaste = this.args.onRangePaste;\n if (!onRangePaste) return;\n\n const halves = splitRange(text);\n if (!halves) return;\n\n const start = parsePasted(halves[0], this.args.parts);\n const end = parsePasted(halves[1], this.args.parts);\n if (start && end) onRangePaste(start, end);\n }\n\n handleCopy = (event: ClipboardEvent): void => {\n event.preventDefault();\n event.clipboardData?.setData(\n 'text/plain',\n formatForClipboard(this.args.parts)\n );\n };\n\n handleCut = (event: ClipboardEvent): void => {\n this.handleCopy(event);\n if (!this.isEditable) return;\n\n this.args.onPartsChange(\n this.args.parts.map((p) => (isSegment(p) ? clearSegment(p) : p))\n );\n };\n\n <template>\n <div\n role=\"group\"\n data-part=\"group\"\n id={{@id}}\n aria-label={{@label}}\n aria-labelledby={{@labelledBy}}\n aria-describedby={{@describedBy}}\n aria-disabled={{if @isDisabled \"true\"}}\n {{! `role=\"group\"` supports neither aria-readonly nor aria-invalid --\n neither is global in ARIA 1.2, and ember-template-lint's\n no-unsupported-role-attributes is right to reject them here (its\n autofixer deletes them silently, which is how they went missing\n once already). Both live on the spinbuttons below instead, where\n the role does support them and where assistive technology actually\n lands. These data attributes carry the same state for styling and\n for tests. }}\n data-readonly={{if @isReadOnly \"true\" \"false\"}}\n data-invalid={{if @isInvalid \"true\" \"false\"}}\n class={{@classes.group class=@userClasses.group}}\n {{on \"paste\" this.handlePaste}}\n {{on \"copy\" this.handleCopy}}\n {{on \"cut\" this.handleCut}}\n ...attributes\n >\n {{#each this.cells key=\"index\" as |cell|}}\n {{#if cell.isSegment}}\n <span\n role=\"spinbutton\"\n tabindex={{unless @isDisabled \"0\"}}\n contenteditable={{if this.isEditable \"true\" \"false\"}}\n inputmode={{cell.inputMode}}\n spellcheck=\"false\"\n autocorrect=\"off\"\n data-part=\"segment\"\n data-type={{cell.type}}\n data-placeholder={{if cell.isEmpty \"true\" \"false\"}}\n data-disabled={{if @isDisabled \"true\" \"false\"}}\n aria-readonly={{if @isReadOnly \"true\"}}\n aria-invalid={{if @isInvalid \"true\"}}\n aria-label={{cell.label}}\n aria-valuenow={{cell.valueNow}}\n aria-valuemin={{cell.valueMin}}\n aria-valuemax={{cell.valueMax}}\n aria-valuetext={{cell.valueText}}\n class={{@classes.segment class=@userClasses.segment}}\n {{on \"keydown\" (fn this.handleKeyDown cell.index)}}\n {{on \"focusout\" (fn this.handleFocusOut cell.index)}}\n {{on \"beforeinput\" this.handleBeforeInput}}\n >{{cell.text}}</span>\n {{else}}\n <span\n data-part=\"literal\"\n aria-hidden=\"true\"\n class={{@classes.literal class=@userClasses.literal}}\n >{{cell.text}}</span>\n {{/if}}\n {{/each}}\n </div>\n </template>\n}\n\nexport { SegmentGroup, type SegmentGroupSignature };\nexport default SegmentGroup;\n"],"names":["DEFAULT_LABELS","year","month","day","hour","minute","dayPeriod","PAGE_STEP","SegmentGroup","Component","isEditable","args","isDisabled","isReadOnly","labelFor","type","segmentLabels","monthNames","Intl","DateTimeFormat","locale","n","prototype","cached","valueTextFor","segment","value","undefined","labels","String","format","Date","cells","parts","map","part","index","isSegment","isEmpty","text","inputMode","displaySegment","label","valueNow","valueMin","min","valueMax","max","valueText","segmentElements","from","group","closest","Array","querySelectorAll","focusSibling","delta","all","step","isRtl","next","indexOf","focus","getComputedStyle","direction","focusEdge","edge","length","replace","i","onPartsChange","handleKeyDown","event","element","target","key","preventDefault","placeholderValue","magnitude","deleteDigit","clearSegment","test","isFull","applyDigit","metaKey","ctrlKey","applyLetter","handleFocusOut","isCommitted","committed","commitSegment","handleBeforeInput","handlePaste","clipboardData","getData","parsed","parsePasted","tryRangePaste","onRangePaste","halves","splitRange","start","end","handleCopy","setData","formatForClipboard","handleCut","p","setComponentTemplate","precompileTemplate","strictMode","scope","on","fn"],"mappings":";;;;;;;;;;AA6DA,MAAMA,cAA0C,GAAI;AAClDC,EAAAA,IAAA,EAAM,MAAA;AACNC,EAAAA,KAAA,EAAO,OAAA;AACPC,EAAAA,GAAA,EAAK,KAAA;AACLC,EAAAA,IAAA,EAAM,MAAA;AACNC,EAAAA,MAAA,EAAQ,QAAA;AACRC,EAAAA,SAAA,EAAW;AACb,CAAA;AAE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AA,IAAI,CAAC,IAAI,CAAC9D,UAAU,EAAE;IAEtB,IAAI,CAACC,IAAI,CAAC2D,aAAa,CACrB,IAAI,CAAC3D,IAAI,CAACsB,KAAK,CAACC,GAAG,CAAEyE,CAAA,IAAOtE,UAAUsE,CAAA,CAAA,GAAK3B,YAAA,CAAa2B,KAAKA,CAAC,CAAA,CAAA;EAElE,CAAA;AAEA,EAAA;IAAAC,oBAAA,CAAAC,kBAAA,CAAA,6/DAAA,EA2DA;MAAAC,UAAA,EAAA,IAAA;AAAAC,MAAAA,KAAA,EAAAA,OAAA;QAAAC,EAAA;AAAAC,QAAAA;AAAA,OAAA;KAAU,CAAA,EAAV,IAAW,CAAA;AAAD;AACZ;;"}
|
|
1
|
+
{"version":3,"file":"segment-group.js","sources":["../../../../src/components/forms/date-input/segment-group.gts"],"sourcesContent":["import Component from '@glimmer/component';\nimport { cached } from '@glimmer/tracking';\nimport { fn } from '@ember/helper';\nimport { on } from '@ember/modifier';\nimport {\n isSegment,\n applyDigit,\n applyLetter,\n commitSegment,\n step,\n clearSegment,\n deleteDigit,\n displaySegment\n} from './segments';\nimport { parsePasted, formatForClipboard, splitRange } from './clipboard';\nimport type {\n Part,\n Segment,\n SegmentType,\n SegmentGroupClasses,\n SegmentGroupUserClasses\n} from './types';\n\ninterface SegmentGroupSignature {\n Args: {\n parts: Part[];\n /** Hands the whole list back; the group holds no state of its own. */\n onPartsChange: (parts: Part[]) => void;\n /**\n * Offered text that reads as two dates rather than one. Only `DatePicker`\n * in `@mode=\"range\"` supplies it, and only to its *start* group: pasting\n * a range into the end of a field and having it rewrite the start would\n * be surprising. Without it, such text is simply declined.\n */\n onRangePaste?: (start: Part[], end: Part[]) => void;\n locale: string;\n placeholderValue: Date;\n isDisabled?: boolean;\n isReadOnly?: boolean;\n isInvalid?: boolean;\n /** Rendered as the group's own id, so a `<label for>` can target it. */\n id?: string;\n /**\n * The field's name. A `role=\"group\"` is not a labelable element, so a\n * sibling `<label for>` does not name it on its own -- this does.\n */\n label?: string;\n labelledBy?: string;\n describedBy?: string;\n segmentLabels?: Partial<Record<SegmentType, string>>;\n /**\n * Only the three slots this group renders, so that `DateInput`'s\n * `dateInput` recipe and `DatePicker`'s `datePicker` recipe both satisfy\n * it. See {@link SegmentGroupClasses}.\n */\n classes: SegmentGroupClasses;\n userClasses?: SegmentGroupUserClasses;\n };\n Element: HTMLDivElement;\n}\n\nconst DEFAULT_LABELS: Record<SegmentType, string> = {\n year: 'year',\n month: 'month',\n day: 'day',\n hour: 'hour',\n minute: 'minute',\n dayPeriod: 'AM/PM'\n};\n\n/** How much PageUp/PageDown moves, per segment. */\nconst PAGE_STEP: Record<SegmentType, number> = {\n day: 7,\n month: 3,\n year: 10,\n hour: 2,\n minute: 15,\n dayPeriod: 1\n};\n\n/**\n * Everything one rendered part needs, resolved to primitives.\n *\n * The template cannot narrow the `Part` union -- `eq` is unavailable and Glint\n * does not carry a type predicate through `{{#if}}` -- so the narrowing happens\n * here, in TypeScript, and the template only ever reads optional primitives.\n * That keeps `part.type` off a `LiteralPart` without a cast anywhere.\n */\ninterface Cell {\n index: number;\n isSegment: boolean;\n /** The segment's display text, or the literal's text. */\n text: string;\n type?: SegmentType;\n isEmpty: boolean;\n label?: string;\n /** `text` for AM/PM, typed by letter; `numeric` for everything else. */\n inputMode: 'numeric' | 'text';\n valueNow?: number;\n valueMin?: number;\n valueMax?: number;\n valueText?: string;\n}\n\n/**\n * One row of date segments. Private: `DateInput` and `DatePicker` both render\n * it, and neither wants the other's `FormControl` wrapper.\n */\nclass SegmentGroup extends Component<SegmentGroupSignature> {\n get isEditable(): boolean {\n return !this.args.isDisabled && !this.args.isReadOnly;\n }\n\n labelFor = (type: SegmentType): string =>\n this.args.segmentLabels?.[type] ?? DEFAULT_LABELS[type];\n\n /**\n * Built once per locale rather than inside {@link valueTextFor}: `cells`\n * recomputes on every keystroke, and an `Intl` constructor is expensive\n * enough that building one per keypress is the costliest thing this\n * component would otherwise do.\n */\n @cached\n get monthNames(): Intl.DateTimeFormat {\n return new Intl.DateTimeFormat(this.args.locale, { month: 'long' });\n }\n\n /**\n * What a screen reader reads instead of the raw number. A month is read by\n * name -- \"January\", not \"1\" -- which is the whole point of `aria-valuetext`.\n */\n valueTextFor = (segment: Segment): string | undefined => {\n if (segment.value === null) return undefined;\n if (segment.labels) return segment.labels[segment.value];\n if (segment.type !== 'month') return String(segment.value);\n\n // Any year and day will do; only the month is read back out.\n return this.monthNames.format(new Date(2026, segment.value - 1, 1));\n };\n\n @cached\n get cells(): Cell[] {\n return this.args.parts.map((part, index) => {\n if (!isSegment(part)) {\n return {\n index,\n isSegment: false,\n isEmpty: false,\n text: part.text,\n inputMode: 'numeric'\n };\n }\n\n return {\n index,\n isSegment: true,\n text: displaySegment(part),\n type: part.type,\n isEmpty: part.value === null,\n label: this.labelFor(part.type),\n inputMode: part.labels ? 'text' : 'numeric',\n // `undefined` rather than `null`: an empty segment has no current\n // value, and `aria-valuenow=\"null\"` would be a value of sorts.\n valueNow: part.value ?? undefined,\n valueMin: part.min,\n valueMax: part.max,\n valueText: this.valueTextFor(part)\n };\n });\n }\n\n /** The segment elements, in document order -- the focus order too. */\n private segmentElements(from: HTMLElement): HTMLElement[] {\n const group = from.closest('[data-part=\"group\"]');\n return group\n ? Array.from(group.querySelectorAll<HTMLElement>('[data-part=\"segment\"]'))\n : [];\n }\n\n /**\n * Left and right are *visual* directions, so in an RTL locale they run\n * against document order: pressing the left arrow in `yyyy/mm/dd` laid out\n * right-to-left should move to the segment drawn to the left, which is the\n * later one in the DOM.\n */\n private focusSibling(from: HTMLElement, delta: number): void {\n const all = this.segmentElements(from);\n const step = this.isRtl(from) ? -delta : delta;\n const next = all[all.indexOf(from) + step];\n next?.focus();\n }\n\n private isRtl(from: HTMLElement): boolean {\n const group = from.closest<HTMLElement>('[data-part=\"group\"]') ?? from;\n return getComputedStyle(group).direction === 'rtl';\n }\n\n private focusEdge(from: HTMLElement, edge: 'first' | 'last'): void {\n const all = this.segmentElements(from);\n (edge === 'first' ? all[0] : all[all.length - 1])?.focus();\n }\n\n /** Replaces one segment by index and reports the new list. */\n private replace(index: number, segment: Segment): void {\n const next = this.args.parts.map((part, i) =>\n i === index ? segment : part\n );\n this.args.onPartsChange(next);\n }\n\n handleKeyDown = (index: number, event: KeyboardEvent): void => {\n const part = this.args.parts[index];\n if (!part || !isSegment(part)) return;\n\n const element = event.target as HTMLElement;\n const { key } = event;\n\n // Navigation works even when the field is read-only; editing does not.\n if (key === 'ArrowRight') {\n event.preventDefault();\n this.focusSibling(element, 1);\n return;\n }\n if (key === 'ArrowLeft') {\n event.preventDefault();\n this.focusSibling(element, -1);\n return;\n }\n if (key === 'Home') {\n event.preventDefault();\n this.focusEdge(element, 'first');\n return;\n }\n if (key === 'End') {\n event.preventDefault();\n this.focusEdge(element, 'last');\n return;\n }\n\n if (!this.isEditable) return;\n\n if (key === 'ArrowUp' || key === 'ArrowDown') {\n event.preventDefault();\n const delta = key === 'ArrowUp' ? 1 : -1;\n this.replace(index, step(part, delta, this.args.placeholderValue));\n return;\n }\n\n if (key === 'PageUp' || key === 'PageDown') {\n event.preventDefault();\n const magnitude = PAGE_STEP[part.type];\n const delta = key === 'PageUp' ? magnitude : -magnitude;\n this.replace(index, step(part, delta, this.args.placeholderValue));\n return;\n }\n\n if (key === 'Backspace') {\n event.preventDefault();\n this.replace(index, deleteDigit(part));\n return;\n }\n\n if (key === 'Delete') {\n event.preventDefault();\n this.replace(index, clearSegment(part));\n return;\n }\n\n if (/^\\d$/.test(key)) {\n event.preventDefault();\n // AM/PM has no digits to take.\n if (part.labels) return;\n const { segment, isFull } = applyDigit(part, key);\n this.replace(index, segment);\n // Advancing before the DOM has caught up is safe: the segment elements\n // are keyed by index and are updated, never re-created.\n if (isFull) this.focusSibling(element, 1);\n return;\n }\n\n if (part.labels && key.length === 1 && !event.metaKey && !event.ctrlKey) {\n event.preventDefault();\n const { segment, isFull } = applyLetter(part, key);\n if (segment !== part) this.replace(index, segment);\n if (isFull) this.focusSibling(element, 1);\n return;\n }\n\n // Everything else -- letters, symbols -- would otherwise be inserted into\n // the contenteditable span as literal text.\n if (key.length === 1 && !event.metaKey && !event.ctrlKey) {\n event.preventDefault();\n }\n };\n\n /**\n * Leaving a segment finishes it: the digits in it stop being something the\n * user is still typing and become their answer, which is what turns a typed\n * `26` into 2026. Tab, arrow-key navigation and a click elsewhere all arrive\n * here, because moving focus is the one thing they have in common.\n */\n handleFocusOut = (index: number): void => {\n if (!this.isEditable) return;\n\n const part = this.args.parts[index];\n if (!part || !isSegment(part) || part.isCommitted) return;\n\n const committed = commitSegment(part);\n // An empty segment commits to itself; reporting it would be churn.\n if (committed !== part) this.replace(index, committed);\n };\n\n /**\n * `contenteditable`'s hazard: anything not handled above arrives here and\n * would be written into the span's DOM, desynchronising the display from the\n * model. Every input type is refused; the model is the only writer.\n */\n handleBeforeInput = (event: Event): void => {\n event.preventDefault();\n };\n\n /**\n * Always `preventDefault`: the browser would otherwise write the pasted text\n * into the contenteditable span, and the model would no longer describe what\n * is on screen. Unparseable text is dropped silently -- a date field that\n * guessed would be worse than one that declined.\n */\n handlePaste = (event: ClipboardEvent): void => {\n event.preventDefault();\n if (!this.isEditable) return;\n\n const text = event.clipboardData?.getData('text/plain') ?? '';\n const parsed = parsePasted(text, this.args.parts);\n if (parsed) {\n this.args.onPartsChange(parsed);\n return;\n }\n\n this.tryRangePaste(text);\n };\n\n /**\n * A second reading of text a single date could not be made of.\n *\n * Both halves are parsed against *this* group's parts, which is sound\n * because the two groups of a range are built from the same locale and\n * format and so have identical shape, and because a half only counts when\n * it parses in full -- nothing of this group's own state survives into the\n * list handed to the other one.\n */\n private tryRangePaste(text: string): void {\n const onRangePaste = this.args.onRangePaste;\n if (!onRangePaste) return;\n\n const halves = splitRange(text);\n if (!halves) return;\n\n const start = parsePasted(halves[0], this.args.parts);\n const end = parsePasted(halves[1], this.args.parts);\n if (start && end) onRangePaste(start, end);\n }\n\n handleCopy = (event: ClipboardEvent): void => {\n event.preventDefault();\n event.clipboardData?.setData(\n 'text/plain',\n formatForClipboard(this.args.parts)\n );\n };\n\n handleCut = (event: ClipboardEvent): void => {\n this.handleCopy(event);\n if (!this.isEditable) return;\n\n this.args.onPartsChange(\n this.args.parts.map((p) => (isSegment(p) ? clearSegment(p) : p))\n );\n };\n\n <template>\n <div\n role=\"group\"\n data-part=\"group\"\n id={{@id}}\n aria-label={{@label}}\n aria-labelledby={{@labelledBy}}\n aria-describedby={{@describedBy}}\n aria-disabled={{if @isDisabled \"true\"}}\n {{! `role=\"group\"` supports neither aria-readonly nor aria-invalid --\n neither is global in ARIA 1.2, and ember-template-lint's\n no-unsupported-role-attributes is right to reject them here (its\n autofixer deletes them silently, which is how they went missing\n once already). Both live on the spinbuttons below instead, where\n the role does support them and where assistive technology actually\n lands. These data attributes carry the same state for styling and\n for tests. }}\n data-readonly={{if @isReadOnly \"true\" \"false\"}}\n data-invalid={{if @isInvalid \"true\" \"false\"}}\n class={{@classes.group class=@userClasses.group}}\n {{on \"paste\" this.handlePaste}}\n {{on \"copy\" this.handleCopy}}\n {{on \"cut\" this.handleCut}}\n ...attributes\n >\n {{#each this.cells key=\"index\" as |cell|}}\n {{#if cell.isSegment}}\n <span\n role=\"spinbutton\"\n tabindex={{unless @isDisabled \"0\"}}\n contenteditable={{if this.isEditable \"true\" \"false\"}}\n inputmode={{cell.inputMode}}\n spellcheck=\"false\"\n autocorrect=\"off\"\n data-part=\"segment\"\n data-type={{cell.type}}\n data-placeholder={{if cell.isEmpty \"true\" \"false\"}}\n data-disabled={{if @isDisabled \"true\" \"false\"}}\n aria-readonly={{if @isReadOnly \"true\"}}\n aria-invalid={{if @isInvalid \"true\"}}\n aria-label={{cell.label}}\n aria-valuenow={{cell.valueNow}}\n aria-valuemin={{cell.valueMin}}\n aria-valuemax={{cell.valueMax}}\n aria-valuetext={{cell.valueText}}\n class={{@classes.segment class=@userClasses.segment}}\n {{on \"keydown\" (fn this.handleKeyDown cell.index)}}\n {{on \"focusout\" (fn this.handleFocusOut cell.index)}}\n {{on \"beforeinput\" this.handleBeforeInput}}\n >{{cell.text}}</span>\n {{else}}\n <span\n data-part=\"literal\"\n aria-hidden=\"true\"\n class={{@classes.literal class=@userClasses.literal}}\n >{{cell.text}}</span>\n {{/if}}\n {{/each}}\n </div>\n </template>\n}\n\nexport {\n SegmentGroup,\n DEFAULT_LABELS as DEFAULT_SEGMENT_LABELS,\n type SegmentGroupSignature\n};\nexport default SegmentGroup;\n"],"names":["DEFAULT_LABELS","year","month","day","hour","minute","dayPeriod","PAGE_STEP","SegmentGroup","Component","isEditable","args","isDisabled","isReadOnly","labelFor","type","segmentLabels","monthNames","Intl","DateTimeFormat","locale","n","prototype","cached","valueTextFor","segment","value","undefined","labels","String","format","Date","cells","parts","map","part","index","isSegment","isEmpty","text","inputMode","displaySegment","label","valueNow","valueMin","min","valueMax","max","valueText","segmentElements","from","group","closest","Array","querySelectorAll","focusSibling","delta","all","step","isRtl","next","indexOf","focus","getComputedStyle","direction","focusEdge","edge","length","replace","i","onPartsChange","handleKeyDown","event","element","target","key","preventDefault","placeholderValue","magnitude","deleteDigit","clearSegment","test","isFull","applyDigit","metaKey","ctrlKey","applyLetter","handleFocusOut","isCommitted","committed","commitSegment","handleBeforeInput","handlePaste","clipboardData","getData","parsed","parsePasted","tryRangePaste","onRangePaste","halves","splitRange","start","end","handleCopy","setData","formatForClipboard","handleCut","p","setComponentTemplate","precompileTemplate","strictMode","scope","on","fn"],"mappings":";;;;;;;;;;AA6DA,MAAMA,cAA0C,GAAI;AAClDC,EAAAA,IAAA,EAAM,MAAA;AACNC,EAAAA,KAAA,EAAO,OAAA;AACPC,EAAAA,GAAA,EAAK,KAAA;AACLC,EAAAA,IAAA,EAAM,MAAA;AACNC,EAAAA,MAAA,EAAQ,QAAA;AACRC,EAAAA,SAAA,EAAW;AACb;AAEA;AACA,MAAMC,SAAqC,GAAI;AAC7CJ,EAAAA,GAAA,EAAK,CAAA;AACLD,EAAAA,KAAA,EAAO,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IAAI,CAAC3D,IAAI,CAACsB,KAAK,CAACC,GAAG,CAAEyE,CAAA,IAAOtE,UAAUsE,CAAA,CAAA,GAAK3B,YAAA,CAAa2B,KAAKA,CAAC,CAAA,CAAA;EAElE,CAAA;AAEA,EAAA;IAAAC,oBAAA,CAAAC,kBAAA,CAAA,6/DAAA,EA2DA;MAAAC,UAAA,EAAA,IAAA;AAAAC,MAAAA,KAAA,EAAAA,OAAA;QAAAC,EAAA;AAAAC,QAAAA;AAAA,OAAA;KAAU,CAAA,EAAV,IAAW,CAAA;AAAD;AACZ;;"}
|
|
@@ -558,5 +558,5 @@ function fromDate(parts, date) {
|
|
|
558
558
|
});
|
|
559
559
|
}
|
|
560
560
|
|
|
561
|
-
export { BOUNDS, DEFAULT_FORMAT, applyDigit, applyLetter, buildParts, carryOver, clearSegment, commitSegment, daysInMonth, deleteDigit, displaySegment, emptySegment, findSegment, fromDate, hasDateChanged, hasTextualMonth, hourOfDay, hourOnCycle, isSegment, resolveSegmentFormat, resolveTwoDigitYear, step, timeOf, toDate, toNumericFormat, withTime, withValue };
|
|
561
|
+
export { BOUNDS, DEFAULT_FORMAT, applyDigit, applyLetter, buildParts, carryOver, clearSegment, commitSegment, daysInMonth, deleteDigit, displaySegment, emptySegment, findSegment, fromDate, hasDateChanged, hasTextualMonth, hourOfDay, hourOnCycle, isSegment, resolveSegmentFormat, resolveTwoDigitYear, seedFrom, step, timeOf, toDate, toNumericFormat, withTime, withValue };
|
|
562
562
|
//# sourceMappingURL=segments.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"segments.js","sources":["../../../../src/components/forms/date-input/segments.ts"],"sourcesContent":["import { warn } from '@ember/debug';\nimport type {\n HourCycle,\n Part,\n Segment,\n SegmentType,\n TimeOptions\n} from './types';\n\n/**\n * The format an editable field uses when the consumer supplies none.\n * Deliberately not `{ dateStyle: 'medium' }` -- DatePicker's button default --\n * which renders a month name and has no numeric segment to type into.\n */\nconst DEFAULT_FORMAT: Intl.DateTimeFormatOptions = {\n year: 'numeric',\n month: '2-digit',\n day: '2-digit'\n};\n\nconst BOUNDS: Record<\n SegmentType,\n { min: number; max: number; width: number; placeholder: string }\n> = {\n // Upper bound for the day is the widest any month gets; `toDate` clamps to\n // the real length of the chosen month, which is not known segment-locally.\n day: { min: 1, max: 31, width: 2, placeholder: 'dd' },\n month: { min: 1, max: 12, width: 2, placeholder: 'mm' },\n year: { min: 1, max: 9999, width: 4, placeholder: 'yyyy' },\n // A 24-hour clock's bounds; `hourBounds` gives the other cycles'.\n hour: { min: 0, max: 23, width: 2, placeholder: 'hh' },\n minute: { min: 0, max: 59, width: 2, placeholder: 'mm' },\n // AM is 0 and PM is 1. Its placeholder is the locale's AM, set by\n // `buildParts`, which is the only place the locale is known.\n dayPeriod: { min: 0, max: 1, width: 2, placeholder: 'AM' }\n};\n\nconst HOUR_BOUNDS: Record<HourCycle, { min: number; max: number }> = {\n h11: { min: 0, max: 11 },\n h12: { min: 1, max: 12 },\n h23: { min: 0, max: 23 },\n h24: { min: 1, max: 24 }\n};\n\n/** Whether a cycle counts the hours twice a day, and so needs AM/PM. */\nfunction isTwelveHour(cycle: HourCycle): boolean {\n return cycle === 'h11' || cycle === 'h12';\n}\n\nfunction isSegment(part: Part): part is Segment {\n return part.kind === 'segment';\n}\n\nfunction emptySegment(\n type: SegmentType,\n overrides: Partial<Segment> = {}\n): Segment {\n const { min, max, width, placeholder } = BOUNDS[type];\n return {\n kind: 'segment',\n type,\n value: null,\n min,\n max,\n width,\n placeholder,\n buffer: '',\n isCommitted: false,\n ...overrides\n };\n}\n\n/**\n * The format the segments are built from: the date format, plus the time\n * fields a granularity asks for. Seconds are out of scope.\n */\nfunction withTime(\n format: Intl.DateTimeFormatOptions,\n { granularity = 'day', hourCycle }: TimeOptions\n): Intl.DateTimeFormatOptions {\n if (granularity === 'day') return format;\n\n return {\n ...format,\n hour: '2-digit',\n ...(granularity === 'minute' ? { minute: '2-digit' } : {}),\n ...(hourCycle ? { hourCycle: hourCycle === 12 ? 'h12' : 'h23' } : {})\n };\n}\n\n/** The locale's names for AM and PM, in that order. */\nfunction dayPeriodLabels(locale: string): string[] {\n const formatter = new Intl.DateTimeFormat(locale, {\n hour: 'numeric',\n hourCycle: 'h12'\n });\n return [1, 13].map(\n (hour) =>\n formatter\n .formatToParts(new Date(2026, 0, 20, hour))\n .find((p) => p.type === 'dayPeriod')?.value ?? (hour < 12 ? 'AM' : 'PM')\n );\n}\n\n/**\n * Derives the segments and their separators from the locale, so `mm/dd/yyyy`,\n * `dd/mm/yyyy` and `yyyy年mm月dd日` all fall out of `Intl` rather than being\n * hardcoded.\n *\n * A format producing a textual month ('Jan') has no editable numeric\n * representation, so that part becomes a numeric month segment anyway. The\n * component warns; this function stays pure.\n */\nfunction buildParts(\n locale: string,\n formatOptions: Intl.DateTimeFormatOptions = DEFAULT_FORMAT,\n time: TimeOptions = {}\n): Part[] {\n const formatter = new Intl.DateTimeFormat(\n locale,\n withTime(formatOptions, time)\n );\n // A reference date, only ever used to make the formatter emit its parts.\n const parts = formatter.formatToParts(new Date(2026, 0, 20));\n // `Intl` settles the cycle -- the locale's, or the one asked for -- and the\n // hour's bounds, and whether there is an AM/PM at all, follow from it.\n const hourCycle = formatter.resolvedOptions().hourCycle ?? 'h23';\n\n const out: Part[] = [];\n for (const part of parts) {\n if (part.type === 'year' || part.type === 'month' || part.type === 'day') {\n out.push(emptySegment(part.type));\n } else if (part.type === 'hour') {\n out.push(emptySegment('hour', { ...HOUR_BOUNDS[hourCycle], hourCycle }));\n } else if (part.type === 'minute') {\n out.push(emptySegment('minute'));\n } else if (part.type === 'dayPeriod') {\n const labels = dayPeriodLabels(locale);\n out.push(emptySegment('dayPeriod', { labels, placeholder: labels[0] }));\n } else if (part.type === 'literal') {\n out.push({ kind: 'literal', text: part.value });\n }\n // Everything else -- era, weekday, relatedYear -- is dropped: there is no\n // segment for it.\n }\n\n return withoutDateTimeComma(out);\n}\n\nconst DATE_TYPES: SegmentType[] = ['year', 'month', 'day'];\n\n/**\n * `Intl` joins the date and the time with a comma in many locales\n * (`01/20/2026, 09:05 PM`), which reads like a sentence rather than a field.\n * The separator between the last date segment and the first time one keeps\n * whatever else the locale put there, minus the comma.\n */\nfunction withoutDateTimeComma(parts: Part[]): Part[] {\n return parts.map((part, i) => {\n if (part.kind !== 'literal') return part;\n const before = parts[i - 1];\n const after = parts[i + 1];\n const joinsDateAndTime =\n before?.kind === 'segment' &&\n DATE_TYPES.includes(before.type) &&\n after?.kind === 'segment' &&\n !DATE_TYPES.includes(after.type);\n if (!joinsDateAndTime) return part;\n const text = part.text.replace(/[,،,]/g, '').replace(/\\s+/g, ' ');\n return { kind: 'literal', text: text.trim() === '' ? ' ' : text };\n });\n}\n\n/**\n * A bare `yy` resolves into the hundred years running from 80 back to 19\n * forward -- so a birth date reaches the past while a card expiry reaches the\n * near future. Three or four digits are a year the user spelled out and are\n * taken literally.\n */\nfunction resolveTwoDigitYear(digits: string, now: Date = new Date()): number {\n const n = Number(digits);\n if (digits.length > 2) return n;\n\n const currentYear = now.getFullYear();\n const start = currentYear - 80;\n const century = Math.floor(start / 100) * 100;\n const candidate = century + n;\n return candidate < start ? candidate + 100 : candidate;\n}\n\n/**\n * The numeric value a buffer represents, or null when it represents none.\n *\n * A buffer is always its literal number, including a year's: `26` is the year\n * 26 here, not 2026. The two-digit window is applied once, by `commitSegment`,\n * at the moment the user is finished with the segment -- applying it per\n * keystroke would make the first digit of `2026` compose the year 2002 and\n * push a date nobody typed out to `@onChange` and the calendar.\n */\nfunction bufferValue(segment: Segment, buffer: string): number | null {\n if (buffer === '') return null;\n const n = Number(buffer);\n return n < segment.min ? null : n;\n}\n\n/**\n * Appends one typed digit.\n *\n * `isFull` is the signal to advance focus. It is true when the segment cannot\n * take another digit -- either it has reached its width, or any further digit\n * would exceed `max`. That is what makes typing `5` into a month jump straight\n * to the day, while typing `1` waits to see whether `12` is coming.\n */\nfunction applyDigit(\n segment: Segment,\n digit: string\n): { segment: Segment; isFull: boolean } {\n // A textual segment (AM/PM) is typed by letter; see `applyLetter`.\n if (!/^\\d$/.test(digit) || segment.labels) {\n return { segment, isFull: false };\n }\n\n let buffer = segment.buffer + digit;\n let value = bufferValue(segment, buffer);\n\n // The accumulated digits no longer fit the segment, so this keystroke starts\n // a fresh entry instead of being discarded. Width is checked as well as the\n // bound because leading zeros pile up without ever exceeding it: `00` then\n // `1` in a month is the buffer `001`, which is still only January and would\n // render three characters wide in a two-character segment.\n if (\n buffer.length > segment.width ||\n (value !== null && value > segment.max)\n ) {\n buffer = digit;\n value = bufferValue(segment, buffer);\n // A single digit that still overflows cannot be entered at all.\n if (value !== null && value > segment.max)\n return { segment, isFull: false };\n }\n\n const atWidth = buffer.length >= segment.width;\n // Would any digit 0-9 appended here still fit? If not, there is nothing\n // left to wait for. `bufferValue` returning null (below `min`) behaves like\n // 0 here, same as the original non-null-assertion-based comparison did.\n const extended = bufferValue(segment, buffer + '0') ?? 0;\n const isFull = atWidth || extended > segment.max;\n\n // A segment that can take no further digit is finished, so it commits here\n // rather than waiting for focus to leave.\n const next: Segment = { ...segment, buffer, value, isCommitted: isFull };\n\n return { segment: next, isFull };\n}\n\n/**\n * Marks a segment as the user's finished answer, expanding a one- or\n * two-digit year through the sliding window on the way: typing `26` and\n * moving on means 2026, while `0026` typed in full means the year 26.\n *\n * An empty segment has nothing to commit and stays uncommitted, so leaving a\n * blank field does not invent a value for it.\n */\nfunction commitSegment(segment: Segment): Segment {\n if (segment.value === null) return segment;\n\n if (\n segment.type === 'year' &&\n segment.buffer.length > 0 &&\n segment.buffer.length <= 2\n ) {\n return withValue(segment, resolveTwoDigitYear(segment.buffer));\n }\n\n return { ...segment, isCommitted: true };\n}\n\n/**\n * A segment holding `value` as a finished answer.\n *\n * The zero-padded buffer is the paired invariant of `displaySegment`, which\n * reads the buffer back out -- so every path that sets a value goes through\n * here rather than restating the padding and risking the two drifting.\n */\nfunction withValue(segment: Segment, value: number): Segment {\n return {\n ...segment,\n value,\n buffer: String(value).padStart(segment.width, '0'),\n isCommitted: true\n };\n}\n\n/**\n * Types into a textual segment: a letter picks the first label starting with\n * it, so `a` and `p` set AM and PM in English. A letter that starts no label\n * is ignored, and the segment is finished either way it is set.\n */\nfunction applyLetter(\n segment: Segment,\n key: string\n): { segment: Segment; isFull: boolean } {\n const letter = key.toLocaleLowerCase();\n const index = (segment.labels ?? []).findIndex((label) =>\n label.toLocaleLowerCase().startsWith(letter)\n );\n if (index === -1) return { segment, isFull: false };\n\n return { segment: withValue(segment, index), isFull: true };\n}\n\n/** Clears both the value and the digits behind it. */\nfunction clearSegment(segment: Segment): Segment {\n return { ...segment, value: null, buffer: '', isCommitted: false };\n}\n\n/** Drops the last digit typed, for Backspace. */\nfunction deleteDigit(segment: Segment): Segment {\n const buffer = segment.buffer.slice(0, -1);\n // Un-commits: a year being backspaced through is being typed again, and the\n // 202 it passes through must not compose a date.\n return {\n ...segment,\n buffer,\n value: bufferValue(segment, buffer),\n isCommitted: false\n };\n}\n\n/** A 0-23 hour as the given cycle counts it. */\nfunction hourOnCycle(hours: number, cycle: HourCycle): number {\n if (cycle === 'h11') return hours % 12;\n if (cycle === 'h12') return hours % 12 || 12;\n if (cycle === 'h24') return hours || 24;\n return hours;\n}\n\n/** The 0-23 hour an hour segment and an AM/PM (0 or 1) stand for. */\nfunction hourOfDay(hour: number, cycle: HourCycle, dayPeriod: number): number {\n if (isTwelveHour(cycle)) return (hour % 12) + (dayPeriod === 1 ? 12 : 0);\n return hour % 24;\n}\n\n/** The unit of `date` this segment holds: what it seeds from, or is set to. */\nfunction seedFrom(segment: Segment, date: Date): number {\n switch (segment.type) {\n case 'year':\n return date.getFullYear();\n case 'month':\n return date.getMonth() + 1;\n case 'day':\n return date.getDate();\n case 'hour':\n return hourOnCycle(date.getHours(), segment.hourCycle ?? 'h23');\n case 'minute':\n return date.getMinutes();\n case 'dayPeriod':\n return date.getHours() < 12 ? 0 : 1;\n }\n}\n\n/**\n * Arrow and page keys. An empty segment does not step from zero -- it adopts\n * `placeholderValue`, so ArrowUp on a blank year offers this year rather than\n * the year 1.\n */\nfunction step(\n segment: Segment,\n delta: number,\n placeholderValue: Date\n): Segment {\n if (segment.value === null) {\n return withValue(segment, seedFrom(segment, placeholderValue));\n }\n\n const span = segment.max - segment.min + 1;\n const offset = segment.value - segment.min + delta;\n // Modulo twice: JavaScript's % keeps the sign of the dividend, so a\n // decrement past the floor would otherwise land on a negative value.\n const wrapped = ((offset % span) + span) % span;\n\n return withValue(segment, wrapped + segment.min);\n}\n\n/**\n * The segment's display text: the digits behind it, or its placeholder when\n * empty. A year still being typed shows exactly what has been typed --\n * `26` on the way to `2026` -- because padding it would claim digits the\n * user has not entered. Every other segment, and a committed year, is padded\n * to its full width.\n *\n * This is the single source of truth for \"what does this segment read as\n * right now\" -- both the rendered cell text and `formatForClipboard` call\n * it, so a mid-entry copy always matches what is on screen.\n */\nfunction displaySegment(segment: Segment): string {\n if (segment.value === null) return segment.placeholder;\n if (segment.labels) return segment.labels[segment.value] ?? '';\n\n const digits = segment.buffer;\n\n return segment.type === 'year' && !segment.isCommitted\n ? digits\n : digits.padStart(segment.width, '0');\n}\n\nfunction findSegment(parts: Part[], type: SegmentType): Segment | undefined {\n return parts.find((p): p is Segment => isSegment(p) && p.type === type);\n}\n\n/** Days in a month, via the zeroth day of the next one. */\nfunction daysInMonth(year: number, month: number): number {\n return new Date(year, month, 0).getDate();\n}\n\n/** A segment holding a finished value, as opposed to one mid-entry. */\nfunction isReady(\n segment: Segment | undefined\n): segment is Segment & { value: number } {\n return segment !== undefined && segment.value !== null && segment.isCommitted;\n}\n\n/**\n * The time the time segments hold, as a 0-23 hour and a minute; midnight when\n * there are none, and `null` while any of them is empty or still being typed.\n */\nfunction timeOf(parts: Part[]): { hours: number; minutes: number } | null {\n const hour = findSegment(parts, 'hour');\n if (!hour) return { hours: 0, minutes: 0 };\n\n const minute = findSegment(parts, 'minute');\n const dayPeriod = findSegment(parts, 'dayPeriod');\n if (!isReady(hour)) return null;\n if (minute && !isReady(minute)) return null;\n if (dayPeriod && !isReady(dayPeriod)) return null;\n\n return {\n hours: hourOfDay(\n hour.value,\n hour.hourCycle ?? 'h23',\n dayPeriod?.value ?? 0\n ),\n minutes: minute?.value ?? 0\n };\n}\n\n/**\n * The composed value, or `null` while any segment is still empty or still\n * being typed. The day is clamped to the chosen month's real length: a 31 left\n * over from January must resolve to the 28th in February, not roll forward\n * into March the way the `Date` constructor would.\n */\nfunction toDate(parts: Part[]): Date | null {\n const year = findSegment(parts, 'year');\n const month = findSegment(parts, 'month');\n const day = findSegment(parts, 'day');\n\n // Uncommitted counts as empty: half a year is not a date.\n if (!isReady(year) || !isReady(month) || !isReady(day)) return null;\n\n const time = timeOf(parts);\n if (!time) return null;\n\n const clamped = Math.min(day.value, daysInMonth(year.value, month.value));\n return new Date(\n year.value,\n month.value - 1,\n clamped,\n time.hours,\n time.minutes\n );\n}\n\n/**\n * Carries the segments' state onto a freshly built list, matching by type.\n *\n * Used when the locale or the format changes under a field that is already\n * holding something. Going via `toDate` instead would discard a half-typed\n * entry, because a partial entry composes no date -- and losing the user's\n * digits to a locale switch is exactly the failure this component exists to\n * avoid. A segment the new format has no place for is simply dropped.\n */\nfunction carryOver(next: Part[], previous: Part[]): Part[] {\n return next.map((part) => {\n if (!isSegment(part)) return part;\n\n const was = findSegment(previous, part.type);\n if (!was || was.value === null) return part;\n\n return {\n ...part,\n value: was.value,\n buffer: was.buffer,\n isCommitted: was.isCommitted\n };\n });\n}\n\n/**\n * Whether a format would render a month no one can type into -- either a\n * textual month outright, or a `dateStyle` preset, which picks its own and\n * cannot be reasoned about field by field.\n */\nfunction hasTextualMonth(options: Intl.DateTimeFormatOptions): boolean {\n return (\n options.dateStyle !== undefined ||\n options.month === 'long' ||\n options.month === 'short' ||\n options.month === 'narrow'\n );\n}\n\n/**\n * The nearest typeable format to the one asked for.\n *\n * A textual month is swapped for a numeric one and *everything else is left\n * alone*: a format asking for month and day keeps exactly those two segments\n * rather than growing a year the consumer never requested. A `dateStyle`\n * preset names no fields at all, so there is nothing to preserve and the\n * default numeric format stands in for the whole thing.\n */\nfunction toNumericFormat(\n options: Intl.DateTimeFormatOptions\n): Intl.DateTimeFormatOptions {\n if (options.dateStyle !== undefined) return DEFAULT_FORMAT;\n return { ...options, month: 'numeric' };\n}\n\n/**\n * The format the segments should actually be built from, warning when that is\n * not the one asked for.\n *\n * Both hosts need the identical policy and differ only in what they call\n * themselves, so the message is passed in rather than the rule being written\n * out twice and left to drift.\n */\nfunction resolveSegmentFormat(\n given: Intl.DateTimeFormatOptions | undefined,\n warning: { message: string; id: string }\n): Intl.DateTimeFormatOptions | undefined {\n if (!given || !hasTextualMonth(given)) return given;\n\n warn(warning.message, false, { id: warning.id });\n\n return toNumericFormat(given);\n}\n\n/** Whether two composed values differ -- `null` (no date) included. */\nfunction hasDateChanged(before: Date | null, after: Date | null): boolean {\n if (before === null || after === null) return before !== after;\n return before.getTime() !== after.getTime();\n}\n\n/** Writes a value across the segments, leaving literals untouched. */\nfunction fromDate(parts: Part[], date: Date | null): Part[] {\n return parts.map((part) => {\n if (!isSegment(part)) return part;\n if (!date) return clearSegment(part);\n\n return withValue(part, seedFrom(part, date));\n });\n}\n\nexport {\n buildParts,\n withTime,\n applyLetter,\n timeOf,\n hourOnCycle,\n hourOfDay,\n isSegment,\n emptySegment,\n DEFAULT_FORMAT,\n BOUNDS,\n applyDigit,\n commitSegment,\n clearSegment,\n deleteDigit,\n step,\n toDate,\n fromDate,\n findSegment,\n resolveTwoDigitYear,\n daysInMonth,\n displaySegment,\n withValue,\n carryOver,\n hasTextualMonth,\n toNumericFormat,\n resolveSegmentFormat,\n hasDateChanged\n};\n"],"names":["DEFAULT_FORMAT","year","month","day","BOUNDS","min","max","width","placeholder","hour","minute","dayPeriod","HOUR_BOUNDS","h11","h12","h23","h24","isTwelveHour","cycle","isSegment","part","kind","emptySegment","type","overrides","value","buffer","isCommitted","withTime","format","granularity","hourCycle","dayPeriodLabels","locale","formatter","Intl","DateTimeFormat","map","formatToParts","Date","find","p","buildParts","formatOptions","time","parts","resolvedOptions","out","push","labels","text","withoutDateTimeComma","DATE_TYPES","i","before","after","joinsDateAndTime","includes","replace","trim","resolveTwoDigitYear","digits","now","n","Number","length","currentYear","getFullYear","start","century","Math","floor","candidate","bufferValue","segment","applyDigit","digit","test","isFull","atWidth","extended","next","commitSegment","withValue","String","padStart","applyLetter","key","letter","toLocaleLowerCase","index","findIndex","label","startsWith","clearSegment","deleteDigit","slice","hourOnCycle","hours","hourOfDay","seedFrom","date","getMonth","getDate","getHours","getMinutes","step","delta","placeholderValue","span","offset","wrapped","displaySegment","findSegment","daysInMonth","isReady","undefined","timeOf","minutes","toDate","clamped","carryOver","previous","was","hasTextualMonth","options","dateStyle","toNumericFormat","resolveSegmentFormat","given","warning","warn","message","id","hasDateChanged","getTime","fromDate"],"mappings":";;AASA;AACA;AACA;AACA;AACA;AACA,MAAMA,cAA0C,GAAG;AACjDC,EAAAA,IAAI,EAAE,SAAS;AACfC,EAAAA,KAAK,EAAE,SAAS;AAChBC,EAAAA,GAAG,EAAE;AACP;AAEA,MAAMC,MAGL,GAAG;AACF;AACA;AACAD,EAAAA,GAAG,EAAE;AAAEE,IAAAA,GAAG,EAAE,CAAC;AAAEC,IAAAA,GAAG,EAAE,EAAE;AAAEC,IAAAA,KAAK,EAAE,CAAC;AAAEC,IAAAA,WAAW,EAAE;GAAM;AACrDN,EAAAA,KAAK,EAAE;AAAEG,IAAAA,GAAG,EAAE,CAAC;AAAEC,IAAAA,GAAG,EAAE,EAAE;AAAEC,IAAAA,KAAK,EAAE,CAAC;AAAEC,IAAAA,WAAW,EAAE;GAAM;AACvDP,EAAAA,IAAI,EAAE;AAAEI,IAAAA,GAAG,EAAE,CAAC;AAAEC,IAAAA,GAAG,EAAE,IAAI;AAAEC,IAAAA,KAAK,EAAE,CAAC;AAAEC,IAAAA,WAAW,EAAE;GAAQ;AAC1D;AACAC,EAAAA,IAAI,EAAE;AAA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AAE,OAAOA,KAAK;AAEnDE,EAAAA,IAAI,CAACD,OAAO,CAACE,OAAO,EAAE,KAAK,EAAE;IAAEC,EAAE,EAAEH,OAAO,CAACG;AAAG,GAAC,CAAC;EAEhD,OAAON,eAAe,CAACE,KAAK,CAAC;AAC/B;;AAEA;AACA,SAASK,cAAcA,CAAChF,MAAmB,EAAEC,KAAkB,EAAW;EACxE,IAAID,MAAM,KAAK,IAAI,IAAIC,KAAK,KAAK,IAAI,EAAE,OAAOD,MAAM,KAAKC,KAAK;EAC9D,OAAOD,MAAM,CAACiF,OAAO,EAAE,KAAKhF,KAAK,CAACgF,OAAO,EAAE;AAC7C;;AAEA;AACA,SAASC,QAAQA,CAAC3F,KAAa,EAAEwD,IAAiB,EAAU;AAC1D,EAAA,OAAOxD,KAAK,CAACR,GAAG,CAAEjB,IAAI,IAAK;AACzB,IAAA,IAAI,CAACD,SAAS,CAACC,IAAI,CAAC,EAAE,OAAOA,IAAI;AACjC,IAAA,IAAI,CAACiF,IAAI,EAAE,OAAOP,YAAY,CAAC1E,IAAI,CAAC;IAEpC,OAAO+D,SAAS,CAAC/D,IAAI,EAAEgF,QAAQ,CAAChF,IAAI,EAAEiF,IAAI,CAAC,CAAC;AAC9C,EAAA,CAAC,CAAC;AACJ;;"}
|
|
1
|
+
{"version":3,"file":"segments.js","sources":["../../../../src/components/forms/date-input/segments.ts"],"sourcesContent":["import { warn } from '@ember/debug';\nimport type {\n HourCycle,\n Part,\n Segment,\n SegmentType,\n TimeOptions\n} from './types';\n\n/**\n * The format an editable field uses when the consumer supplies none.\n * Deliberately not `{ dateStyle: 'medium' }` -- DatePicker's button default --\n * which renders a month name and has no numeric segment to type into.\n */\nconst DEFAULT_FORMAT: Intl.DateTimeFormatOptions = {\n year: 'numeric',\n month: '2-digit',\n day: '2-digit'\n};\n\nconst BOUNDS: Record<\n SegmentType,\n { min: number; max: number; width: number; placeholder: string }\n> = {\n // Upper bound for the day is the widest any month gets; `toDate` clamps to\n // the real length of the chosen month, which is not known segment-locally.\n day: { min: 1, max: 31, width: 2, placeholder: 'dd' },\n month: { min: 1, max: 12, width: 2, placeholder: 'mm' },\n year: { min: 1, max: 9999, width: 4, placeholder: 'yyyy' },\n // A 24-hour clock's bounds; `hourBounds` gives the other cycles'.\n hour: { min: 0, max: 23, width: 2, placeholder: 'hh' },\n minute: { min: 0, max: 59, width: 2, placeholder: 'mm' },\n // AM is 0 and PM is 1. Its placeholder is the locale's AM, set by\n // `buildParts`, which is the only place the locale is known.\n dayPeriod: { min: 0, max: 1, width: 2, placeholder: 'AM' }\n};\n\nconst HOUR_BOUNDS: Record<HourCycle, { min: number; max: number }> = {\n h11: { min: 0, max: 11 },\n h12: { min: 1, max: 12 },\n h23: { min: 0, max: 23 },\n h24: { min: 1, max: 24 }\n};\n\n/** Whether a cycle counts the hours twice a day, and so needs AM/PM. */\nfunction isTwelveHour(cycle: HourCycle): boolean {\n return cycle === 'h11' || cycle === 'h12';\n}\n\nfunction isSegment(part: Part): part is Segment {\n return part.kind === 'segment';\n}\n\nfunction emptySegment(\n type: SegmentType,\n overrides: Partial<Segment> = {}\n): Segment {\n const { min, max, width, placeholder } = BOUNDS[type];\n return {\n kind: 'segment',\n type,\n value: null,\n min,\n max,\n width,\n placeholder,\n buffer: '',\n isCommitted: false,\n ...overrides\n };\n}\n\n/**\n * The format the segments are built from: the date format, plus the time\n * fields a granularity asks for. Seconds are out of scope.\n */\nfunction withTime(\n format: Intl.DateTimeFormatOptions,\n { granularity = 'day', hourCycle }: TimeOptions\n): Intl.DateTimeFormatOptions {\n if (granularity === 'day') return format;\n\n return {\n ...format,\n hour: '2-digit',\n ...(granularity === 'minute' ? { minute: '2-digit' } : {}),\n ...(hourCycle ? { hourCycle: hourCycle === 12 ? 'h12' : 'h23' } : {})\n };\n}\n\n/** The locale's names for AM and PM, in that order. */\nfunction dayPeriodLabels(locale: string): string[] {\n const formatter = new Intl.DateTimeFormat(locale, {\n hour: 'numeric',\n hourCycle: 'h12'\n });\n return [1, 13].map(\n (hour) =>\n formatter\n .formatToParts(new Date(2026, 0, 20, hour))\n .find((p) => p.type === 'dayPeriod')?.value ?? (hour < 12 ? 'AM' : 'PM')\n );\n}\n\n/**\n * Derives the segments and their separators from the locale, so `mm/dd/yyyy`,\n * `dd/mm/yyyy` and `yyyy年mm月dd日` all fall out of `Intl` rather than being\n * hardcoded.\n *\n * A format producing a textual month ('Jan') has no editable numeric\n * representation, so that part becomes a numeric month segment anyway. The\n * component warns; this function stays pure.\n */\nfunction buildParts(\n locale: string,\n formatOptions: Intl.DateTimeFormatOptions = DEFAULT_FORMAT,\n time: TimeOptions = {}\n): Part[] {\n const formatter = new Intl.DateTimeFormat(\n locale,\n withTime(formatOptions, time)\n );\n // A reference date, only ever used to make the formatter emit its parts.\n const parts = formatter.formatToParts(new Date(2026, 0, 20));\n // `Intl` settles the cycle -- the locale's, or the one asked for -- and the\n // hour's bounds, and whether there is an AM/PM at all, follow from it.\n const hourCycle = formatter.resolvedOptions().hourCycle ?? 'h23';\n\n const out: Part[] = [];\n for (const part of parts) {\n if (part.type === 'year' || part.type === 'month' || part.type === 'day') {\n out.push(emptySegment(part.type));\n } else if (part.type === 'hour') {\n out.push(emptySegment('hour', { ...HOUR_BOUNDS[hourCycle], hourCycle }));\n } else if (part.type === 'minute') {\n out.push(emptySegment('minute'));\n } else if (part.type === 'dayPeriod') {\n const labels = dayPeriodLabels(locale);\n out.push(emptySegment('dayPeriod', { labels, placeholder: labels[0] }));\n } else if (part.type === 'literal') {\n out.push({ kind: 'literal', text: part.value });\n }\n // Everything else -- era, weekday, relatedYear -- is dropped: there is no\n // segment for it.\n }\n\n return withoutDateTimeComma(out);\n}\n\nconst DATE_TYPES: SegmentType[] = ['year', 'month', 'day'];\n\n/**\n * `Intl` joins the date and the time with a comma in many locales\n * (`01/20/2026, 09:05 PM`), which reads like a sentence rather than a field.\n * The separator between the last date segment and the first time one keeps\n * whatever else the locale put there, minus the comma.\n */\nfunction withoutDateTimeComma(parts: Part[]): Part[] {\n return parts.map((part, i) => {\n if (part.kind !== 'literal') return part;\n const before = parts[i - 1];\n const after = parts[i + 1];\n const joinsDateAndTime =\n before?.kind === 'segment' &&\n DATE_TYPES.includes(before.type) &&\n after?.kind === 'segment' &&\n !DATE_TYPES.includes(after.type);\n if (!joinsDateAndTime) return part;\n const text = part.text.replace(/[,،,]/g, '').replace(/\\s+/g, ' ');\n return { kind: 'literal', text: text.trim() === '' ? ' ' : text };\n });\n}\n\n/**\n * A bare `yy` resolves into the hundred years running from 80 back to 19\n * forward -- so a birth date reaches the past while a card expiry reaches the\n * near future. Three or four digits are a year the user spelled out and are\n * taken literally.\n */\nfunction resolveTwoDigitYear(digits: string, now: Date = new Date()): number {\n const n = Number(digits);\n if (digits.length > 2) return n;\n\n const currentYear = now.getFullYear();\n const start = currentYear - 80;\n const century = Math.floor(start / 100) * 100;\n const candidate = century + n;\n return candidate < start ? candidate + 100 : candidate;\n}\n\n/**\n * The numeric value a buffer represents, or null when it represents none.\n *\n * A buffer is always its literal number, including a year's: `26` is the year\n * 26 here, not 2026. The two-digit window is applied once, by `commitSegment`,\n * at the moment the user is finished with the segment -- applying it per\n * keystroke would make the first digit of `2026` compose the year 2002 and\n * push a date nobody typed out to `@onChange` and the calendar.\n */\nfunction bufferValue(segment: Segment, buffer: string): number | null {\n if (buffer === '') return null;\n const n = Number(buffer);\n return n < segment.min ? null : n;\n}\n\n/**\n * Appends one typed digit.\n *\n * `isFull` is the signal to advance focus. It is true when the segment cannot\n * take another digit -- either it has reached its width, or any further digit\n * would exceed `max`. That is what makes typing `5` into a month jump straight\n * to the day, while typing `1` waits to see whether `12` is coming.\n */\nfunction applyDigit(\n segment: Segment,\n digit: string\n): { segment: Segment; isFull: boolean } {\n // A textual segment (AM/PM) is typed by letter; see `applyLetter`.\n if (!/^\\d$/.test(digit) || segment.labels) {\n return { segment, isFull: false };\n }\n\n let buffer = segment.buffer + digit;\n let value = bufferValue(segment, buffer);\n\n // The accumulated digits no longer fit the segment, so this keystroke starts\n // a fresh entry instead of being discarded. Width is checked as well as the\n // bound because leading zeros pile up without ever exceeding it: `00` then\n // `1` in a month is the buffer `001`, which is still only January and would\n // render three characters wide in a two-character segment.\n if (\n buffer.length > segment.width ||\n (value !== null && value > segment.max)\n ) {\n buffer = digit;\n value = bufferValue(segment, buffer);\n // A single digit that still overflows cannot be entered at all.\n if (value !== null && value > segment.max)\n return { segment, isFull: false };\n }\n\n const atWidth = buffer.length >= segment.width;\n // Would any digit 0-9 appended here still fit? If not, there is nothing\n // left to wait for. `bufferValue` returning null (below `min`) behaves like\n // 0 here, same as the original non-null-assertion-based comparison did.\n const extended = bufferValue(segment, buffer + '0') ?? 0;\n const isFull = atWidth || extended > segment.max;\n\n // A segment that can take no further digit is finished, so it commits here\n // rather than waiting for focus to leave.\n const next: Segment = { ...segment, buffer, value, isCommitted: isFull };\n\n return { segment: next, isFull };\n}\n\n/**\n * Marks a segment as the user's finished answer, expanding a one- or\n * two-digit year through the sliding window on the way: typing `26` and\n * moving on means 2026, while `0026` typed in full means the year 26.\n *\n * An empty segment has nothing to commit and stays uncommitted, so leaving a\n * blank field does not invent a value for it.\n */\nfunction commitSegment(segment: Segment): Segment {\n if (segment.value === null) return segment;\n\n if (\n segment.type === 'year' &&\n segment.buffer.length > 0 &&\n segment.buffer.length <= 2\n ) {\n return withValue(segment, resolveTwoDigitYear(segment.buffer));\n }\n\n return { ...segment, isCommitted: true };\n}\n\n/**\n * A segment holding `value` as a finished answer.\n *\n * The zero-padded buffer is the paired invariant of `displaySegment`, which\n * reads the buffer back out -- so every path that sets a value goes through\n * here rather than restating the padding and risking the two drifting.\n */\nfunction withValue(segment: Segment, value: number): Segment {\n return {\n ...segment,\n value,\n buffer: String(value).padStart(segment.width, '0'),\n isCommitted: true\n };\n}\n\n/**\n * Types into a textual segment: a letter picks the first label starting with\n * it, so `a` and `p` set AM and PM in English. A letter that starts no label\n * is ignored, and the segment is finished either way it is set.\n */\nfunction applyLetter(\n segment: Segment,\n key: string\n): { segment: Segment; isFull: boolean } {\n const letter = key.toLocaleLowerCase();\n const index = (segment.labels ?? []).findIndex((label) =>\n label.toLocaleLowerCase().startsWith(letter)\n );\n if (index === -1) return { segment, isFull: false };\n\n return { segment: withValue(segment, index), isFull: true };\n}\n\n/** Clears both the value and the digits behind it. */\nfunction clearSegment(segment: Segment): Segment {\n return { ...segment, value: null, buffer: '', isCommitted: false };\n}\n\n/** Drops the last digit typed, for Backspace. */\nfunction deleteDigit(segment: Segment): Segment {\n const buffer = segment.buffer.slice(0, -1);\n // Un-commits: a year being backspaced through is being typed again, and the\n // 202 it passes through must not compose a date.\n return {\n ...segment,\n buffer,\n value: bufferValue(segment, buffer),\n isCommitted: false\n };\n}\n\n/** A 0-23 hour as the given cycle counts it. */\nfunction hourOnCycle(hours: number, cycle: HourCycle): number {\n if (cycle === 'h11') return hours % 12;\n if (cycle === 'h12') return hours % 12 || 12;\n if (cycle === 'h24') return hours || 24;\n return hours;\n}\n\n/** The 0-23 hour an hour segment and an AM/PM (0 or 1) stand for. */\nfunction hourOfDay(hour: number, cycle: HourCycle, dayPeriod: number): number {\n if (isTwelveHour(cycle)) return (hour % 12) + (dayPeriod === 1 ? 12 : 0);\n return hour % 24;\n}\n\n/** The unit of `date` this segment holds: what it seeds from, or is set to. */\nfunction seedFrom(segment: Segment, date: Date): number {\n switch (segment.type) {\n case 'year':\n return date.getFullYear();\n case 'month':\n return date.getMonth() + 1;\n case 'day':\n return date.getDate();\n case 'hour':\n return hourOnCycle(date.getHours(), segment.hourCycle ?? 'h23');\n case 'minute':\n return date.getMinutes();\n case 'dayPeriod':\n return date.getHours() < 12 ? 0 : 1;\n }\n}\n\n/**\n * Arrow and page keys. An empty segment does not step from zero -- it adopts\n * `placeholderValue`, so ArrowUp on a blank year offers this year rather than\n * the year 1.\n */\nfunction step(\n segment: Segment,\n delta: number,\n placeholderValue: Date\n): Segment {\n if (segment.value === null) {\n return withValue(segment, seedFrom(segment, placeholderValue));\n }\n\n const span = segment.max - segment.min + 1;\n const offset = segment.value - segment.min + delta;\n // Modulo twice: JavaScript's % keeps the sign of the dividend, so a\n // decrement past the floor would otherwise land on a negative value.\n const wrapped = ((offset % span) + span) % span;\n\n return withValue(segment, wrapped + segment.min);\n}\n\n/**\n * The segment's display text: the digits behind it, or its placeholder when\n * empty. A year still being typed shows exactly what has been typed --\n * `26` on the way to `2026` -- because padding it would claim digits the\n * user has not entered. Every other segment, and a committed year, is padded\n * to its full width.\n *\n * This is the single source of truth for \"what does this segment read as\n * right now\" -- both the rendered cell text and `formatForClipboard` call\n * it, so a mid-entry copy always matches what is on screen.\n */\nfunction displaySegment(segment: Segment): string {\n if (segment.value === null) return segment.placeholder;\n if (segment.labels) return segment.labels[segment.value] ?? '';\n\n const digits = segment.buffer;\n\n return segment.type === 'year' && !segment.isCommitted\n ? digits\n : digits.padStart(segment.width, '0');\n}\n\nfunction findSegment(parts: Part[], type: SegmentType): Segment | undefined {\n return parts.find((p): p is Segment => isSegment(p) && p.type === type);\n}\n\n/** Days in a month, via the zeroth day of the next one. */\nfunction daysInMonth(year: number, month: number): number {\n return new Date(year, month, 0).getDate();\n}\n\n/** A segment holding a finished value, as opposed to one mid-entry. */\nfunction isReady(\n segment: Segment | undefined\n): segment is Segment & { value: number } {\n return segment !== undefined && segment.value !== null && segment.isCommitted;\n}\n\n/**\n * The time the time segments hold, as a 0-23 hour and a minute; midnight when\n * there are none, and `null` while any of them is empty or still being typed.\n */\nfunction timeOf(parts: Part[]): { hours: number; minutes: number } | null {\n const hour = findSegment(parts, 'hour');\n if (!hour) return { hours: 0, minutes: 0 };\n\n const minute = findSegment(parts, 'minute');\n const dayPeriod = findSegment(parts, 'dayPeriod');\n if (!isReady(hour)) return null;\n if (minute && !isReady(minute)) return null;\n if (dayPeriod && !isReady(dayPeriod)) return null;\n\n return {\n hours: hourOfDay(\n hour.value,\n hour.hourCycle ?? 'h23',\n dayPeriod?.value ?? 0\n ),\n minutes: minute?.value ?? 0\n };\n}\n\n/**\n * The composed value, or `null` while any segment is still empty or still\n * being typed. The day is clamped to the chosen month's real length: a 31 left\n * over from January must resolve to the 28th in February, not roll forward\n * into March the way the `Date` constructor would.\n */\nfunction toDate(parts: Part[]): Date | null {\n const year = findSegment(parts, 'year');\n const month = findSegment(parts, 'month');\n const day = findSegment(parts, 'day');\n\n // Uncommitted counts as empty: half a year is not a date.\n if (!isReady(year) || !isReady(month) || !isReady(day)) return null;\n\n const time = timeOf(parts);\n if (!time) return null;\n\n const clamped = Math.min(day.value, daysInMonth(year.value, month.value));\n return new Date(\n year.value,\n month.value - 1,\n clamped,\n time.hours,\n time.minutes\n );\n}\n\n/**\n * Carries the segments' state onto a freshly built list, matching by type.\n *\n * Used when the locale or the format changes under a field that is already\n * holding something. Going via `toDate` instead would discard a half-typed\n * entry, because a partial entry composes no date -- and losing the user's\n * digits to a locale switch is exactly the failure this component exists to\n * avoid. A segment the new format has no place for is simply dropped.\n */\nfunction carryOver(next: Part[], previous: Part[]): Part[] {\n return next.map((part) => {\n if (!isSegment(part)) return part;\n\n const was = findSegment(previous, part.type);\n if (!was || was.value === null) return part;\n\n return {\n ...part,\n value: was.value,\n buffer: was.buffer,\n isCommitted: was.isCommitted\n };\n });\n}\n\n/**\n * Whether a format would render a month no one can type into -- either a\n * textual month outright, or a `dateStyle` preset, which picks its own and\n * cannot be reasoned about field by field.\n */\nfunction hasTextualMonth(options: Intl.DateTimeFormatOptions): boolean {\n return (\n options.dateStyle !== undefined ||\n options.month === 'long' ||\n options.month === 'short' ||\n options.month === 'narrow'\n );\n}\n\n/**\n * The nearest typeable format to the one asked for.\n *\n * A textual month is swapped for a numeric one and *everything else is left\n * alone*: a format asking for month and day keeps exactly those two segments\n * rather than growing a year the consumer never requested. A `dateStyle`\n * preset names no fields at all, so there is nothing to preserve and the\n * default numeric format stands in for the whole thing.\n */\nfunction toNumericFormat(\n options: Intl.DateTimeFormatOptions\n): Intl.DateTimeFormatOptions {\n if (options.dateStyle !== undefined) return DEFAULT_FORMAT;\n return { ...options, month: 'numeric' };\n}\n\n/**\n * The format the segments should actually be built from, warning when that is\n * not the one asked for.\n *\n * Both hosts need the identical policy and differ only in what they call\n * themselves, so the message is passed in rather than the rule being written\n * out twice and left to drift.\n */\nfunction resolveSegmentFormat(\n given: Intl.DateTimeFormatOptions | undefined,\n warning: { message: string; id: string }\n): Intl.DateTimeFormatOptions | undefined {\n if (!given || !hasTextualMonth(given)) return given;\n\n warn(warning.message, false, { id: warning.id });\n\n return toNumericFormat(given);\n}\n\n/** Whether two composed values differ -- `null` (no date) included. */\nfunction hasDateChanged(before: Date | null, after: Date | null): boolean {\n if (before === null || after === null) return before !== after;\n return before.getTime() !== after.getTime();\n}\n\n/** Writes a value across the segments, leaving literals untouched. */\nfunction fromDate(parts: Part[], date: Date | null): Part[] {\n return parts.map((part) => {\n if (!isSegment(part)) return part;\n if (!date) return clearSegment(part);\n\n return withValue(part, seedFrom(part, date));\n });\n}\n\nexport {\n buildParts,\n withTime,\n applyLetter,\n timeOf,\n hourOnCycle,\n hourOfDay,\n seedFrom,\n isSegment,\n emptySegment,\n DEFAULT_FORMAT,\n BOUNDS,\n applyDigit,\n commitSegment,\n clearSegment,\n deleteDigit,\n step,\n toDate,\n fromDate,\n findSegment,\n resolveTwoDigitYear,\n daysInMonth,\n displaySegment,\n withValue,\n carryOver,\n hasTextualMonth,\n toNumericFormat,\n resolveSegmentFormat,\n hasDateChanged\n};\n"],"names":["DEFAULT_FORMAT","year","month","day","BOUNDS","min","max","width","placeholder","hour","minute","dayPeriod","HOUR_BOUNDS","h11","h12","h23","h24","isTwelveHour","cycle","isSegment","part","kind","emptySegment","type","overrides","value","buffer","isCommitted","withTime","format","granularity","hourCycle","dayPeriodLabels","locale","formatter","Intl","DateTimeFormat","map","formatToParts","Date","find","p","buildParts","formatOptions","time","parts","resolvedOptions","out","push","labels","text","withoutDateTimeComma","DATE_TYPES","i","before","after","joinsDateAndTime","includes","replace","trim","resolveTwoDigitYear","digits","now","n","Number","length","currentYear","getFullYear","start","century","Math","floor","candidate","bufferValue","segment","applyDigit","digit","test","isFull","atWidth","extended","next","commitSegment","withValue","String","padStart","applyLetter","key","letter","toLocaleLowerCase","index","findIndex","label","startsWith","clearSegment","deleteDigit","slice","hourOnCycle","hours","hourOfDay","seedFrom","date","getMonth","getDate","getHours","getMinutes","step","delta","placeholderValue","span","offset","wrapped","displaySegment","findSegment","daysInMonth","isReady","undefined","timeOf","minutes","toDate","clamped","carryOver","previous","was","hasTextualMonth","options","dateStyle","toNumericFormat","resolveSegmentFormat","given","warning","warn","message","id","hasDateChanged","getTime","fromDate"],"mappings":";;AASA;AACA;AACA;AACA;AACA;AACA,MAAMA,cAA0C,GAAG;AACjDC,EAAAA,IAAI,EAAE,SAAS;AACfC,EAAAA,KAAK,EAAE,SAAS;AAChBC,EAAAA,GAAG,EAAE;AACP;AAEA,MAAMC,MAGL,GAAG;AACF;AACA;AACAD,EAAAA,GAAG,EAAE;AAAEE,IAAAA,GAAG,EAAE,CAAC;AAAEC,IAAAA,GAAG,EAAE,EAAE;AAAEC,IAAAA,KAAK,EAAE,CAAC;AAAEC,IAAAA,WAAW,EAAE;GAAM;AACrDN,EAAAA,KAAK,EAAE;AAAEG,IAAAA,GAAG,EAAE,CAAC;AAAEC,IAAAA,GAAG,EAAE,EAAE;AAAEC,IAAAA,KAAK,EAAE,CAAC;AAAEC,IAAAA,WAAW,EAAE;GAAM;AACvDP,EAAAA,IAAI,EAAE;AAAEI,IAAAA,GAAG,EAAE,CAAC;AAAEC,IAAAA,GAAG,EAAE,IAAI;AAAEC,IAAAA,KAAK,EAAE,CAAC;AAAEC,IAAAA,WAAW,EAAE;GAAQ;AAC1D;AACAC,EAAAA,IAAI,EAAE;AAAEJ,IAAAA,GAAG,EAAE,CAAC;AAAEC,IAAAA,GAAG,EAAE,EAAE;AAAEC,IAAAA,KAAK,EAAE,CAAC;AAAEC,IAAAA,WAAW,EAAE;GAAM;AACtDE,EAAAA,MAAM,EAAE;AAA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KAAK,CAAC;AAC/B;;AAEA;AACA,SAASK,cAAcA,CAAChF,MAAmB,EAAEC,KAAkB,EAAW;EACxE,IAAID,MAAM,KAAK,IAAI,IAAIC,KAAK,KAAK,IAAI,EAAE,OAAOD,MAAM,KAAKC,KAAK;EAC9D,OAAOD,MAAM,CAACiF,OAAO,EAAE,KAAKhF,KAAK,CAACgF,OAAO,EAAE;AAC7C;;AAEA;AACA,SAASC,QAAQA,CAAC3F,KAAa,EAAEwD,IAAiB,EAAU;AAC1D,EAAA,OAAOxD,KAAK,CAACR,GAAG,CAAEjB,IAAI,IAAK;AACzB,IAAA,IAAI,CAACD,SAAS,CAACC,IAAI,CAAC,EAAE,OAAOA,IAAI;AACjC,IAAA,IAAI,CAACiF,IAAI,EAAE,OAAOP,YAAY,CAAC1E,IAAI,CAAC;IAEpC,OAAO+D,SAAS,CAAC/D,IAAI,EAAEgF,QAAQ,CAAChF,IAAI,EAAEiF,IAAI,CAAC,CAAC;AAC9C,EAAA,CAAC,CAAC;AACJ;;"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { BOUNDS, DEFAULT_FORMAT, applyDigit, applyLetter, buildParts, carryOver, clearSegment, commitSegment, daysInMonth, deleteDigit, displaySegment, emptySegment, findSegment, fromDate, hasDateChanged, hasTextualMonth, hourOfDay, hourOnCycle, isSegment, resolveSegmentFormat, resolveTwoDigitYear, step, timeOf, toDate, toNumericFormat, withTime, withValue } from './date-input/segments.js';
|
|
1
|
+
export { BOUNDS, DEFAULT_FORMAT, applyDigit, applyLetter, buildParts, carryOver, clearSegment, commitSegment, daysInMonth, deleteDigit, displaySegment, emptySegment, findSegment, fromDate, hasDateChanged, hasTextualMonth, hourOfDay, hourOnCycle, isSegment, resolveSegmentFormat, resolveTwoDigitYear, seedFrom, step, timeOf, toDate, toNumericFormat, withTime, withValue } from './date-input/segments.js';
|
|
2
2
|
export { formatForClipboard, parsePasted, splitRange } from './date-input/clipboard.js';
|
|
3
3
|
export { DateInput, DateInput as default } from './date-input/date-input.js';
|
|
4
4
|
//# sourceMappingURL=date-input.js.map
|