@solid2-aria/stately 0.0.1 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,6 +2,26 @@
2
2
 
3
3
  State management for Solid 2 accessible components.
4
4
 
5
+ ## Installation
6
+
7
+ ```sh
8
+ bun add @solid2-aria/stately solid-js@next
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ Import from the package root or a module subpath:
14
+
15
+ ```ts
16
+ import { createListState, parseColor } from "@solid2-aria/stately";
17
+ import type { ListState } from "@solid2-aria/stately";
18
+ import { createToggleState } from "@solid2-aria/stately/toggle/create-toggle-state";
19
+ ```
20
+
21
+ `@solid2-aria/stately` uses renderer-neutral `Element` types from `solid-js` and does not require `@solidjs/web`. TypeScript projects can use `moduleResolution: "bundler"` or `"NodeNext"`.
22
+
23
+ ## Development
24
+
5
25
  Install workspace dependencies from the repository root:
6
26
 
7
27
  ```bash
@@ -16,16 +36,6 @@ bun run build
16
36
 
17
37
  tsdown emits ESM JavaScript, source maps, and TypeScript declarations into `dist/`. It generates the package export map from the source files. The build includes the third-party license texts and notices in `dist/LICENSES/` and `dist/NOTICE.txt`.
18
38
 
19
- Import from the package root or a module subpath:
20
-
21
- ```ts
22
- import { createListState, parseColor } from "@solid2-aria/stately";
23
- import type { ListState } from "@solid2-aria/stately";
24
- import { createToggleState } from "@solid2-aria/stately/toggle/create-toggle-state";
25
- ```
26
-
27
- Install `solid-js` version `^2.0.0-rc.17` as a peer dependency. `@solid2-aria/stately` uses renderer-neutral `Element` types from `solid-js` and does not require `@solidjs/web`. TypeScript projects can use `moduleResolution: "bundler"` or `"NodeNext"`.
28
-
29
39
  Watch source files and rebuild:
30
40
 
31
41
  ```bash
package/dist/NOTICE.txt CHANGED
@@ -30,7 +30,7 @@ and dark CSS between Solid previews and exported configuration. Copyright (c)
30
30
  This repository contains code and translations derived from Adobe React Spectrum.
31
31
 
32
32
  Upstream: https://github.com/adobe/react-spectrum
33
- Reference revision: 261344335e54265b2d02dc57a43b911a718de707
33
+ Reference revision: 6dec77beccf0545a04318e6a01b8eb9cbe2dccc6
34
34
  License: Apache License, Version 2.0 (LICENSES/Apache-2.0.txt).
35
35
  Original copyright and attribution notices are retained in the source files.
36
36
  The upstream NOTICE.txt is reproduced in LICENSES/react-spectrum-NOTICE.txt.
@@ -44,6 +44,12 @@ type declarations, Solid 2
44
44
  reactivity, state APIs, module organization, imports, and formatting.
45
45
  These notices apply to the derived files identified by their source headers.
46
46
 
47
+ The upstream update from 261344335e54265b2d02dc57a43b911a718de707 adds
48
+ packages/@react-types/shared/src/layout.d.ts and
49
+ packages/react-aria/src/utils/typeHelpers.ts. Their Solid counterparts retain
50
+ Copyright 2026 Adobe and their Apache-2.0 notices. The update adapts shadow DOM
51
+ traversal, interaction fixes, scroll anchoring, and component behavior to Solid 2.
52
+
47
53
  The type packages packages/@solid2-aria/types-shared, packages/@solid2-aria/types-shared-web,
48
54
  and packages/solid2-aria-types distribute the original Apache-2.0 license and
49
55
  upstream NOTICE.txt verbatim in their LICENSES directories, with package-specific
@@ -345,6 +351,13 @@ The downloadable public/typeset.css retains the rules and original
345
351
  shadcn/typeset notice from apps/v4/app/(app)/(typeset)/typeset.css, with a source
346
352
  and modification header added. These files retain the shadcn/ui MIT license.
347
353
 
354
+ The Typeset customizer and src/components/tools/typeset-docs.tsx also adapt
355
+ apps/v4/app/(app)/(typeset)/components/{customizer,font-picker,option-picker,
356
+ main-menu,docs-panel,get-code-drawer}.tsx at the same revision. Solid 2 menus
357
+ provide transient previews, configuration locks, keyboard shortcuts, and a
358
+ responsive Vaul code drawer. Copyright (c) 2023 shadcn and the existing
359
+ shadcn/ui MIT license are retained.
360
+
348
361
  The JSON task and dashboard fixtures in
349
362
  apps/shadcn-solid2-aria/src/components/showcase/{tasks,dashboard}.json are copied
350
363
  from apps/v4/app/(app)/examples/tasks/data/tasks.json and
@@ -439,10 +452,16 @@ independently authored.
439
452
  The installable registry serves the existing shadcn-derived Solid component
440
453
  sources with Nova classes and omits inline license headers from installed code.
441
454
  Repository sources retain their copyright years, upstream paths, and modification
442
- notices. The shared theme dependency distributes the original shadcn MIT license
443
- verbatim and a registry-specific provenance notice containing the original
444
- per-file attribution headers. Theme metadata uses the existing
445
- apps/v4/app/globals.css-derived component theme and Solid animation adaptations.
455
+ notices. Registry installation does not create separate license or notice files.
456
+ The original shadcn MIT license remains in the repository's
457
+ apps/shadcn-solid2-aria/LICENSES/shadcn-ui-MIT.txt. The registry snapshot in
458
+ apps/shadcn-solid2-aria/src/registry/theme.json copies ARIA_STYLE.css from
459
+ apps/v4/registry/bases/aria/registry.ts and neutral.cssVars from
460
+ apps/v4/registry/themes.ts at the shadcn/ui revision above. Their keys, values,
461
+ and declaration order are unchanged. The downloadable public/theme.css is
462
+ rendered from this data using the shadcn CLI CSS transforms. It retains the
463
+ original Copyright (c) 2023 shadcn and MIT attribution. Shared variants,
464
+ animations, and utilities use the unmodified shadcn/tailwind.css import.
446
465
  Registry HTTP handlers and dependency discovery are independently authored.
447
466
 
448
467
  Drawer composition in the existing shadcn-derived wrappers preserves the
@@ -471,9 +490,10 @@ LICENSES/inter-OFL.txt and public/licenses/inter-OFL.txt.
471
490
 
472
491
  The Solid tool menu and Create welcome dialog additionally adapt
473
492
  apps/v4/app/(app)/{(create),(typeset)}/components/main-menu.tsx and
474
- apps/v4/app/(app)/(create)/components/welcome-dialog.tsx, with the logo from
475
- apps/v4/components/icons.tsx. They retain Copyright (c) 2023 shadcn and MIT
476
- attribution, replacing React state and dialogs with Solid 2 and Solid2 Aria.
493
+ apps/v4/app/(app)/(create)/components/welcome-dialog.tsx. The site logo and
494
+ favicon use an independently authored S mark. The derived components retain
495
+ Copyright (c) 2023 shadcn and MIT attribution, replacing React state and dialogs
496
+ with Solid 2 and Solid2 Aria.
477
497
 
478
498
  The dashboard SVG node data in src/components/showcase/dashboard-icons.tsx in
479
499
  apps/shadcn-solid2-aria derives from @tabler/icons-react 3.34.1, dist/esm/icons,
@@ -599,9 +619,11 @@ content/docs/{installation,dark-mode}/*.mdx adapts shadcn/ui at revision
599
619
  481d523374745e77d0cf9c53a4115ab5dd7c8481. Upstream sources are
600
620
  apps/v4/content/docs/installation/{index,vite,tanstack-router,tanstack}.mdx
601
621
  and apps/v4/content/docs/dark-mode/{index,vite,tanstack-start}.mdx.
602
- The overview cards, framework SVG paths, setup choices, numbered steps,
603
- Card and Button examples, and sun/moon mode-toggle layout retain the
604
- upstream structure. Commands use the local Solid component registry;
622
+ The overview cards, framework SVG paths, numbered steps, and sun/moon
623
+ mode-toggle layout retain the upstream structure. Framework installation
624
+ walkthroughs add official CLI scaffolding, Solid 2 migration, package imports,
625
+ Vite aliases, separate theme setup, and component installation.
626
+ Commands use the local Solid component registry;
605
627
  framework entries, providers, lifecycle, icons, and menus use Solid 2 APIs.
606
628
  The linked-card component in src/components/docs/linked-card.tsx and the
607
629
  responsive documentation steps also adapt apps/v4/mdx-components.tsx.
@@ -343,7 +343,7 @@ function createComboBoxState(props) {
343
343
  valueOnFocus = [currentInputValue, currentDisplayValue];
344
344
  if (currentMenuTrigger === "focus" && !(props.isReadOnly === true)) open(null, "focus");
345
345
  } else {
346
- if (currentShouldCloseOnBlur) commitValue();
346
+ if (currentShouldCloseOnBlur && props.isReadOnly !== true) commitValue();
347
347
  if (currentInputValue !== valueOnFocus[0] || currentDisplayValue !== valueOnFocus[1]) validation.commitValidation();
348
348
  }
349
349
  setFocusedState(localIsFocused);
@@ -1 +1 @@
1
- {"version":3,"file":"create-combo-box-state.js","names":[],"sources":["../../src/combobox/create-combo-box-state.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n/*\n * Derived from Adobe React Spectrum: packages/react-stately/src/combobox/useComboBoxState.ts.\n * Modified for Solid Aria: adapted reactive state, getters, imports, and APIs for Solid 2.\n * Licensed under Apache-2.0. See LICENSES/Apache-2.0.txt and NOTICE.txt at the repository root.\n */\n\nimport type {\n Collection,\n CollectionBase,\n CollectionStateBase,\n FocusableProps,\n FocusStrategy,\n HelpTextProps,\n InputBase,\n Key,\n LabelableProps,\n Node,\n Selection,\n TextInputBase,\n Validation,\n ValueBase,\n} from \"@solid2-aria/types-shared\";\nimport {\n createMemo,\n createSignal,\n createRenderEffect,\n untrack,\n merge,\n} from \"solid-js\";\n\nimport { getChildNodes } from \"../collections/get-child-nodes\";\nimport { createFormValidationState } from \"../form/create-form-validation-state\";\nimport type { FormValidationState } from \"../form/create-form-validation-state\";\nimport { createListState } from \"../list/create-list-state\";\nimport type { ListState } from \"../list/create-list-state\";\nimport { ListCollection } from \"../list/list-collection\";\nimport { createOverlayTriggerState } from \"../overlays/create-overlay-trigger-state\";\nimport type { OverlayTriggerState } from \"../overlays/create-overlay-trigger-state\";\nimport { createControlledSignal } from \"../utils/create-controlled-signal\";\nimport {\n getLegacyDefaultSelectedKey,\n getLegacySelectedKey,\n notifyLegacySelectionChange,\n} from \"../utils/legacy-props\";\n\nexport type MenuTriggerAction = \"focus\" | \"input\" | \"manual\";\n\nexport type SelectionMode = \"single\" | \"multiple\";\n\nexport type ValueType<M extends SelectionMode> = M extends \"single\"\n ? Key | null\n : readonly Key[];\n\nexport type ChangeValueType<M extends SelectionMode> = M extends \"single\"\n ? Key | null\n : Key[];\n\ntype ValidationType<M extends SelectionMode> = M extends \"single\"\n ? Key | null\n : Key[];\n\nexport interface ComboBoxValidationValue<M extends SelectionMode = \"single\"> {\n /**\n * The selected key in the ComboBox.\n *\n * @deprecated\n */\n selectedKey: Key | null;\n /** The keys of the currently selected items. */\n value: ValidationType<M>;\n /** The value of the ComboBox input. */\n inputValue: string;\n}\n\nexport interface ComboBoxProps<T, M extends SelectionMode = \"single\">\n extends\n CollectionBase<T>,\n InputBase,\n ValueBase<ValueType<M>, ChangeValueType<M>>,\n TextInputBase,\n Validation<ComboBoxValidationValue<M>>,\n FocusableProps<HTMLInputElement>,\n LabelableProps,\n HelpTextProps {\n /** The list of ComboBox items (uncontrolled). */\n defaultItems?: Iterable<T>;\n /** The list of ComboBox items (controlled). */\n items?: Iterable<T>;\n /**\n * Method that is called when the open state of the menu changes. Returns the new open state and\n * the action that caused the opening of the menu.\n */\n onOpenChange?: (isOpen: boolean, menuTrigger?: MenuTriggerAction) => void;\n /**\n * Whether single or multiple selection is enabled.\n *\n * @default 'single'\n */\n selectionMode?: M;\n /**\n * The currently selected key in the collection (controlled).\n *\n * @deprecated\n */\n selectedKey?: Key | null;\n /**\n * The initial selected key in the collection (uncontrolled).\n *\n * @deprecated\n */\n defaultSelectedKey?: Key | null;\n /**\n * Handler that is called when the selection changes.\n *\n * @deprecated\n */\n onSelectionChange?: (key: Key | null) => void;\n /** The value of the ComboBox input (controlled). */\n inputValue?: string;\n /** The default value of the ComboBox input (uncontrolled). */\n defaultInputValue?: string;\n /** Handler that is called when the ComboBox input value changes. */\n onInputChange?: (value: string) => void;\n /** Whether the ComboBox allows a non-item matching input value to be set. */\n allowsCustomValue?: boolean;\n // /**\n // * Whether the Combobox should only suggest matching options or autocomplete the field with the nearest matching option.\n // * @default 'suggest'\n // */\n // completionMode?: 'suggest' | 'complete',\n /**\n * The interaction required to display the ComboBox menu.\n *\n * @default 'input'\n */\n menuTrigger?: MenuTriggerAction;\n}\n\nexport interface ComboBoxState<T, M extends SelectionMode = \"single\">\n extends ListState<T>, OverlayTriggerState, FormValidationState {\n /**\n * The key for the first selected item.\n *\n * @deprecated\n */\n readonly selectedKey: Key | null;\n /**\n * The default selected key.\n *\n * @deprecated\n */\n readonly defaultSelectedKey: Key | null;\n /**\n * Sets the selected key.\n *\n * @deprecated\n */\n setSelectedKey: (key: Key | null) => void;\n /** The current combobox value. */\n readonly value: ValueType<M>;\n /** The default combobox value. */\n readonly defaultValue: ValueType<M>;\n /** Sets the combobox value. */\n setValue: (value: Key | readonly Key[] | null) => void;\n /**\n * The value of the first selected item.\n *\n * @deprecated\n */\n readonly selectedItem: Node<T> | null;\n /** The value of the selected items. */\n readonly selectedItems: Node<T>[];\n /** The current value of the combo box input. */\n inputValue: string;\n /** The default value of the combo box input. */\n defaultInputValue: string;\n /** Sets the value of the combo box input. */\n setInputValue: (value: string) => void;\n /** Selects the currently focused item and updates the input value. */\n commit: () => void;\n /** Controls which item will be auto focused when the menu opens. */\n readonly focusStrategy: FocusStrategy | null;\n /** Whether the select is currently focused. */\n readonly isFocused: boolean;\n /** Sets whether the select is focused. */\n setFocused: (isFocused: boolean) => void;\n /** Opens the menu. */\n open: (\n focusStrategy?: FocusStrategy | null,\n trigger?: MenuTriggerAction\n ) => void;\n /** Toggles the menu. */\n toggle: (\n focusStrategy?: FocusStrategy | null,\n trigger?: MenuTriggerAction\n ) => void;\n /** Resets the input value to the previously selected item's text if any and closes the menu. */\n revert: () => void;\n}\n\ntype FilterFn = (textValue: string, inputValue: string) => boolean;\n\nexport interface ComboBoxStateOptions<T, M extends SelectionMode = \"single\">\n extends Omit<ComboBoxProps<T, M>, \"children\">, CollectionStateBase<T> {\n /** The filter function used to determine if a option should be included in the combo box list. */\n defaultFilter?: FilterFn;\n /** Whether the combo box allows the menu to be open when the collection is empty. */\n allowsEmptyCollection?: boolean;\n /** Whether the combo box menu should close on blur. */\n shouldCloseOnBlur?: boolean;\n}\n\n/**\n * Provides state management for a combo box component. Handles building a collection of items from\n * props and manages the option selection state of the combo box. In addition, it tracks the input\n * value, focus state, and other properties of the combo box.\n */\nexport function createComboBoxState<\n T extends object,\n M extends SelectionMode = \"single\",\n>(props: ComboBoxStateOptions<T, M>): ComboBoxState<T, M> {\n const defaultFilter = createMemo(() => props.defaultFilter);\n const menuTrigger = createMemo(() => props.menuTrigger ?? \"input\");\n\n const allowsEmptyCollection = createMemo(\n () => props.allowsEmptyCollection ?? false\n );\n\n const allowsCustomValue = createMemo(() => props.allowsCustomValue);\n const shouldCloseOnBlur = createMemo(() => props.shouldCloseOnBlur ?? true);\n\n const selectionMode = createMemo(() => props.selectionMode ?? \"single\");\n\n const [showAllItems, setShowAllItems] = createSignal(false, {\n ownedWrite: true,\n });\n\n const [isFocused, setFocusedState] = createSignal(false, {\n ownedWrite: true,\n });\n\n const [focusStrategy, setFocusStrategy] = createSignal<FocusStrategy | null>(\n null,\n { ownedWrite: true }\n );\n\n let closedDueToEmpty = false;\n\n const defaultValue = createMemo(() => {\n const currentSelectionMode = selectionMode();\n\n return (\n props.defaultValue ??\n (currentSelectionMode === \"single\"\n ? (getLegacyDefaultSelectedKey(props) ?? null)\n : [])\n );\n });\n\n const value = createMemo(() => {\n const currentSelectionMode = selectionMode();\n\n return (\n props.value ??\n (currentSelectionMode === \"single\"\n ? getLegacySelectedKey(props)\n : undefined)\n );\n });\n\n const [controlledValue, setControlledValue] = createControlledSignal<\n Key | readonly Key[] | null\n >(\n () => value(),\n untrack(() => defaultValue()),\n (localValue) => {\n const change = isKeyArray(localValue) ? [...localValue] : localValue;\n // SAFETY: setValue normalizes changes to the active selection mode.\n // oxlint-disable-next-line typescript/no-unsafe-type-assertion\n props.onChange?.(change as ChangeValueType<M>);\n }\n );\n\n // Only display the first selected item if in single selection mode but the value is an array.\n const displayValue = createMemo(() => {\n const currentSelectionMode = selectionMode();\n const currentControlledValue = controlledValue();\n\n return currentSelectionMode === \"single\" &&\n isKeyArray(currentControlledValue)\n ? (currentControlledValue[0] ?? null)\n : currentControlledValue;\n });\n\n const setValue = (localValue: Key | readonly Key[] | null) => {\n const currentSelectionMode = selectionMode();\n const currentDisplayValue = displayValue();\n\n if (currentSelectionMode === \"single\") {\n const key = isKeyArray(localValue) ? (localValue[0] ?? null) : localValue;\n setControlledValue(key);\n\n if (key !== currentDisplayValue) {\n notifyLegacySelectionChange(props, key);\n }\n } else {\n let keys: Key[] = [];\n\n if (isKeyArray(localValue)) {\n keys = [...localValue];\n } else if (localValue !== null && localValue !== undefined) {\n keys = [localValue];\n }\n\n setControlledValue(keys);\n }\n };\n\n const derivedProperty0 = createMemo(() => {\n const currentDisplayValue = displayValue();\n\n return convertValue(currentDisplayValue);\n });\n\n const listState = createListState(\n merge(props, {\n get allowDuplicateSelectionEvents() {\n return true;\n },\n get disallowEmptySelection() {\n return selectionMode() === \"single\";\n },\n get items() {\n return props.items ?? props.defaultItems;\n },\n get onSelectionChange() {\n return (keys: Selection) => {\n const currentSelectionMode = selectionMode();\n const currentDisplayValue = displayValue();\n\n // impossible, but TS doesn't know that\n if (keys === \"all\") {\n return;\n }\n\n if (currentSelectionMode === \"single\") {\n const key = keys.values().next().value ?? null;\n\n if (key === currentDisplayValue) {\n notifyLegacySelectionChange(props, key);\n // If key is the same, reset the inputValue and close the menu\n // (scenario: user clicks on already selected option)\n resetInputValue();\n closeMenu();\n } else {\n setValue(key);\n }\n } else {\n setValue([...keys]);\n }\n };\n },\n get selectedKeys() {\n return derivedProperty0();\n },\n get selectionMode() {\n return selectionMode();\n },\n })\n );\n\n const collection = createMemo(() => listState.collection);\n const selectionManager = createMemo(() => listState.selectionManager);\n const disabledKeys = createMemo(() => listState.disabledKeys);\n\n const selectedKey = createMemo(() => {\n const currentSelectionMode = selectionMode();\n const currentSelectionManager = selectionManager();\n\n return currentSelectionMode === \"single\"\n ? currentSelectionManager.firstSelectedKey\n : null;\n });\n\n const selectedItems = createMemo(() => {\n const currentSelectionManager = selectionManager();\n\n return [...currentSelectionManager.selectedKeys].flatMap((key) => {\n const item = collection().getItem(key);\n\n return item === null || item === undefined ? [] : [item];\n });\n });\n\n const [inputValue, setInputValue] = createControlledSignal(\n () => props.inputValue,\n untrack(() => {\n const currentSelectedKey = selectedKey();\n const currentCollection = collection();\n\n return (\n getDefaultInputValue(\n props.defaultInputValue,\n currentSelectedKey,\n currentCollection\n ) ?? \"\"\n );\n }),\n (localValue) => {\n props.onInputChange?.(localValue);\n }\n );\n\n const initialValue = untrack(() => displayValue());\n const initialInputValue = untrack(() => inputValue());\n // Preserve original collection so we can show all items on demand\n const originalCollection = createMemo(() => collection());\n\n const filteredCollection = createMemo(() => {\n const currentDefaultFilter = defaultFilter();\n const currentCollection = collection();\n const currentInputValue = inputValue();\n\n return (\n // No default filter if items are controlled.\n (props.items !== null && props.items !== undefined) ||\n !currentDefaultFilter\n ? currentCollection\n : filterCollection(\n currentCollection,\n currentInputValue,\n currentDefaultFilter\n )\n );\n });\n\n const [lastCollection, setLastCollection] = createSignal(\n untrack(() => filteredCollection()),\n { ownedWrite: true }\n );\n // Track what action is attempting to open the menu\n\n let menuOpenTrigger: MenuTriggerAction | undefined = \"focus\";\n\n const onOpenChange = (open: boolean) => {\n const currentSelectionManager = selectionManager();\n\n if (props.onOpenChange) {\n props.onOpenChange(open, open ? menuOpenTrigger : undefined);\n }\n\n currentSelectionManager.setFocused(open);\n\n if (!open) {\n currentSelectionManager.setFocusedKey(null);\n }\n };\n\n const triggerState = createOverlayTriggerState(\n merge(props, {\n defaultOpen: undefined,\n isOpen: undefined,\n onOpenChange,\n })\n );\n\n const open = (\n localFocusStrategy: FocusStrategy | null = null,\n trigger?: MenuTriggerAction\n ) => {\n const currentMenuTrigger = menuTrigger();\n const currentAllowsEmptyCollection = allowsEmptyCollection();\n const currentFilteredCollection = filteredCollection();\n const currentOriginalCollection = originalCollection();\n\n const displayAllItems =\n trigger === \"manual\" ||\n (trigger === \"focus\" && currentMenuTrigger === \"focus\");\n\n // Prevent open operations from triggering if there is nothing to display\n // Also prevent open operations from triggering if items are uncontrolled but defaultItems is empty, even if displayAllItems is true.\n // This is to prevent comboboxes with empty defaultItems from opening but allow controlled items comboboxes to open even if the inital list is empty (assumption is user will provide swap the empty list with a base list via onOpenChange returning `menuTrigger` manual)\n if (\n currentAllowsEmptyCollection ||\n currentFilteredCollection.size > 0 ||\n (displayAllItems && currentOriginalCollection.size > 0) ||\n props.items\n ) {\n if (\n displayAllItems &&\n !triggerState.isOpen &&\n props.items === undefined\n ) {\n // Show all items if menu is manually opened. Only care about this if items are undefined\n setShowAllItems(true);\n }\n\n menuOpenTrigger = trigger;\n setFocusStrategy(localFocusStrategy);\n triggerState.open();\n }\n };\n\n const toggle = (\n localFocusStrategy: FocusStrategy | null = null,\n trigger?: MenuTriggerAction\n ) => {\n const currentMenuTrigger = menuTrigger();\n const currentAllowsEmptyCollection = allowsEmptyCollection();\n const currentFilteredCollection = filteredCollection();\n const currentOriginalCollection = originalCollection();\n\n const displayAllItems =\n trigger === \"manual\" ||\n (trigger === \"focus\" && currentMenuTrigger === \"focus\");\n\n // If the menu is closed and there is nothing to display, early return so toggle isn't called to prevent extraneous onOpenChange\n if (\n !currentAllowsEmptyCollection &&\n !(currentFilteredCollection.size > 0) &&\n (!displayAllItems || !(currentOriginalCollection.size > 0)) &&\n !props.items &&\n !triggerState.isOpen\n ) {\n return;\n }\n\n if (displayAllItems && !triggerState.isOpen && props.items === undefined) {\n // Show all items if menu is toggled open. Only care about this if items are undefined\n setShowAllItems(true);\n }\n\n // Only update the menuOpenTrigger if menu is currently closed\n if (!triggerState.isOpen) {\n menuOpenTrigger = trigger;\n }\n\n toggleMenu(localFocusStrategy);\n };\n\n const updateLastCollection = () => {\n const currentShowAllItems = showAllItems();\n const currentOriginalCollection = originalCollection();\n const currentFilteredCollection = filteredCollection();\n setLastCollection(\n currentShowAllItems\n ? currentOriginalCollection\n : currentFilteredCollection\n );\n };\n\n // If menu is going to close, save the current collection so we can freeze the displayed collection when the\n // user clicks outside the popover to close the menu. Prevents the menu contents from updating as the menu closes.\n function toggleMenu(localFocusStrategy: FocusStrategy | null = null) {\n if (triggerState.isOpen) {\n updateLastCollection();\n }\n\n setFocusStrategy(localFocusStrategy);\n triggerState.toggle();\n }\n\n function closeMenu() {\n if (triggerState.isOpen) {\n updateLastCollection();\n triggerState.close();\n }\n }\n\n const [lastValue, setLastValue] = createSignal(\n untrack(() => inputValue()),\n { ownedWrite: true }\n );\n\n function resetInputValue() {\n const currentSelectedKey = selectedKey();\n const currentCollection = collection();\n\n const itemText =\n currentSelectedKey === null || currentSelectedKey === undefined\n ? \"\"\n : (currentCollection.getItem(currentSelectedKey)?.textValue ?? \"\");\n\n setLastValue(itemText);\n setInputValue(itemText);\n }\n\n let previousValue: Key | readonly Key[] | null | undefined = untrack(() =>\n displayValue()\n );\n\n let lastSelectedKeyText = untrack(() => {\n const currentSelectedKey = selectedKey();\n const currentCollection = collection();\n\n return currentSelectedKey === null || currentSelectedKey === undefined\n ? \"\"\n : (currentCollection.getItem(currentSelectedKey)?.textValue ?? \"\");\n });\n\n createRenderEffect(\n () => {\n const currentSelectedKey = selectedKey();\n const currentCollection = collection();\n\n return {\n currentAllowsEmptyCollection: allowsEmptyCollection(),\n currentDisplayValue: displayValue(),\n currentFilteredCollection: filteredCollection(),\n currentInputValue: inputValue(),\n currentIsFocused: isFocused(),\n currentIsOpen: triggerState.isOpen,\n currentLastValue: lastValue(),\n currentMenuTrigger: menuTrigger(),\n currentSelectedKey,\n currentSelectedText:\n currentSelectedKey === null\n ? \"\"\n : (currentCollection.getItem(currentSelectedKey)?.textValue ?? \"\"),\n currentSelectionManager: selectionManager(),\n currentSelectionMode: selectionMode(),\n currentShowAllItems: showAllItems(),\n currentValue: value(),\n inputIsControlled: props.inputValue !== undefined,\n };\n },\n ({\n currentIsFocused,\n currentFilteredCollection,\n currentAllowsEmptyCollection,\n currentInputValue,\n currentLastValue,\n currentMenuTrigger,\n currentShowAllItems,\n currentDisplayValue,\n currentSelectionMode,\n currentSelectionManager,\n currentValue,\n currentSelectedKey,\n currentSelectedText,\n currentIsOpen,\n inputIsControlled,\n }) => {\n function synchronizeMenu() {\n // Open and close menu automatically when the input value changes if the input is focused,\n // and there are items in the collection or allowEmptyCollection is true.\n if (\n currentIsFocused &&\n (currentFilteredCollection.size > 0 ||\n currentAllowsEmptyCollection) &&\n !currentIsOpen &&\n currentInputValue !== currentLastValue &&\n currentMenuTrigger !== \"manual\"\n ) {\n open(null, \"input\");\n }\n\n // Close the menu if the collection is empty. Don't close menu if filtered collection size is 0\n // but we are currently showing all items via button press\n if (\n !currentShowAllItems &&\n !currentAllowsEmptyCollection &&\n currentIsOpen &&\n currentFilteredCollection.size === 0\n ) {\n closedDueToEmpty = true;\n closeMenu();\n }\n\n // Re-open the menu when items become non-empty after being auto-closed due to\n // an empty collection (e.g. async load completed with results after a previous empty response).\n // This works for both controlled items on ComboBox and Collection patterns\n // (where items are provided on the ListBox rather than the ComboBox).\n if (\n currentIsFocused &&\n closedDueToEmpty &&\n currentFilteredCollection.size > 0 &&\n !currentIsOpen &&\n currentMenuTrigger !== \"manual\"\n ) {\n closedDueToEmpty = false;\n open(null, \"input\");\n }\n }\n\n function synchronizeSelection() {\n // Close when an item is selected.\n if (\n currentDisplayValue !== null &&\n currentDisplayValue !== undefined &&\n currentDisplayValue !== previousValue &&\n currentSelectionMode === \"single\"\n ) {\n closeMenu();\n }\n\n // Clear focused key when input value changes and display filtered collection again.\n if (currentInputValue !== currentLastValue) {\n currentSelectionManager.setFocusedKey(null);\n setShowAllItems(false);\n\n // Set value to null when the user clears the input.\n // If controlled, this is the application developer's responsibility.\n if (\n currentSelectionMode === \"single\" &&\n currentInputValue === \"\" &&\n (!inputIsControlled || currentValue === undefined)\n ) {\n setValue(null);\n }\n }\n\n // If the value changed, update the input value.\n // Do nothing if both inputValue and value are controlled.\n // In this case, it's the user's responsibility to update inputValue in onSelectionChange.\n if (\n currentDisplayValue !== previousValue &&\n (!inputIsControlled || currentValue === undefined)\n ) {\n resetInputValue();\n } else if (currentLastValue !== currentInputValue) {\n setLastValue(currentInputValue);\n }\n }\n\n function synchronizeSelectedText() {\n // Update the inputValue if the selected item's text changes from its last tracked value.\n // This is to handle cases where a selectedKey is specified but the items aren't available (async loading) or the selected item's text value updates.\n // Only reset if the user isn't currently within the field so we don't erroneously modify user input.\n // If inputValue is controlled, it is the user's responsibility to update the inputValue when items change.\n const selectedItemText = currentSelectedText;\n\n if (\n !currentIsFocused &&\n currentSelectedKey !== null &&\n currentSelectedKey !== undefined &&\n !inputIsControlled &&\n currentSelectedKey === previousValue &&\n lastSelectedKeyText !== selectedItemText\n ) {\n setLastValue(selectedItemText);\n setInputValue(selectedItemText);\n }\n\n return selectedItemText;\n }\n\n untrack(() => {\n synchronizeMenu();\n synchronizeSelection();\n const selectedItemText = synchronizeSelectedText();\n previousValue = currentDisplayValue;\n lastSelectedKeyText = selectedItemText;\n });\n }\n );\n\n const derivedProperty1 = createMemo(() => {\n const currentDisplayValue = displayValue();\n const currentInputValue = inputValue();\n const currentSelectedKey = selectedKey();\n\n return isKeyArray(currentDisplayValue) && currentDisplayValue.length === 0\n ? null\n : {\n inputValue: currentInputValue,\n selectedKey: currentSelectedKey,\n // SAFETY: The active selection mode determines the value shape; readonly input arrays are copied for mutable callback values.\n // oxlint-disable-next-line typescript/no-unsafe-type-assertion\n value: (isKeyArray(currentDisplayValue)\n ? [...currentDisplayValue]\n : currentDisplayValue) as ComboBoxValidationValue<M>[\"value\"],\n };\n });\n\n const validation = createFormValidationState(\n merge(props, {\n get value() {\n return derivedProperty1();\n },\n })\n );\n\n // Revert input value and close menu\n const revert = () => {\n const currentAllowsCustomValue = allowsCustomValue();\n const currentSelectedKey = selectedKey();\n closedDueToEmpty = false;\n\n if (\n currentAllowsCustomValue === true &&\n (currentSelectedKey === null || currentSelectedKey === undefined)\n ) {\n commitCustomValue();\n } else {\n commitSelection();\n }\n };\n\n function commitCustomValue() {\n const currentSelectionMode = selectionMode();\n const currentInputValue = inputValue();\n\n if (currentSelectionMode === \"multiple\") {\n // In multi-select mode, the input's custom text is independent from the selected items.\n // Closing or committing the field should not clear the existing selection.\n setLastValue(currentInputValue);\n closeMenu();\n\n return;\n }\n\n const localValue = null;\n previousValue = localValue;\n setValue(localValue);\n closeMenu();\n }\n\n function commitSelection(shouldForceSelectionChange = false) {\n const currentValue = value();\n const currentSelectedKey = selectedKey();\n const currentCollection = collection();\n const currentSelectionMode = selectionMode();\n const currentInputValue = inputValue();\n const currentDisplayValue = displayValue();\n\n // If multiple things are controlled, call onSelectionChange only when selecting the focused item,\n // or when inputValue needs to be synced back to the selected item on commit/blur.\n if (currentValue !== undefined && props.inputValue !== undefined) {\n const itemText =\n currentSelectedKey === null || currentSelectedKey === undefined\n ? \"\"\n : (currentCollection.getItem(currentSelectedKey)?.textValue ?? \"\");\n\n if (\n shouldForceSelectionChange ||\n currentSelectionMode === \"multiple\" ||\n currentInputValue !== itemText\n ) {\n notifyLegacySelectionChange(props, currentSelectedKey);\n\n const change = isKeyArray(currentDisplayValue)\n ? [...currentDisplayValue]\n : currentDisplayValue;\n\n // SAFETY: the committed value has the active mode's shape and arrays are copied for callbacks.\n // oxlint-disable-next-line typescript/no-unsafe-type-assertion\n props.onChange?.(change as ChangeValueType<M>);\n }\n\n // Keep the committed input value from reopening the menu.\n setLastValue(itemText);\n } else {\n // If only a single aspect of combobox is controlled, reset input value and close menu for the user\n resetInputValue();\n }\n\n closeMenu();\n }\n\n const commitValue = () => {\n const currentAllowsCustomValue = allowsCustomValue();\n const currentSelectedKey = selectedKey();\n const currentCollection = collection();\n const currentInputValue = inputValue();\n closedDueToEmpty = false;\n\n if (currentAllowsCustomValue === true) {\n const itemText =\n currentSelectedKey === null || currentSelectedKey === undefined\n ? \"\"\n : (currentCollection.getItem(currentSelectedKey)?.textValue ?? \"\");\n\n if (currentInputValue === itemText) {\n commitSelection();\n } else {\n commitCustomValue();\n }\n } else {\n // Reset inputValue and close menu\n commitSelection();\n }\n };\n\n const commit = () => {\n const currentSelectionManager = selectionManager();\n const currentSelectionMode = selectionMode();\n\n if (\n triggerState.isOpen &&\n currentSelectionManager.focusedKey !== null &&\n currentSelectionManager.focusedKey !== undefined\n ) {\n // Reset inputValue and close menu here if the selected key is already the focused key. Otherwise\n // fire onSelectionChange to allow the application to control the closing.\n if (\n currentSelectionManager.isSelected(\n currentSelectionManager.focusedKey\n ) &&\n currentSelectionMode === \"single\"\n ) {\n commitSelection(true);\n } else {\n currentSelectionManager.select(currentSelectionManager.focusedKey);\n }\n } else {\n commitValue();\n }\n };\n\n let valueOnFocus = untrack(() => {\n const currentInputValue = inputValue();\n const currentDisplayValue = displayValue();\n\n return [currentInputValue, currentDisplayValue];\n });\n\n const setFocused = (localIsFocused: boolean) => {\n const currentInputValue = inputValue();\n const currentDisplayValue = displayValue();\n const currentMenuTrigger = menuTrigger();\n const currentShouldCloseOnBlur = shouldCloseOnBlur();\n\n if (localIsFocused) {\n valueOnFocus = [currentInputValue, currentDisplayValue];\n\n if (currentMenuTrigger === \"focus\" && !(props.isReadOnly === true)) {\n open(null, \"focus\");\n }\n } else {\n if (currentShouldCloseOnBlur) {\n commitValue();\n }\n\n // Commit validation if the input value or selected items changed.\n if (\n currentInputValue !== valueOnFocus[0] ||\n currentDisplayValue !== valueOnFocus[1]\n ) {\n validation.commitValidation();\n }\n }\n\n setFocusedState(localIsFocused);\n };\n\n const displayedCollection = createMemo(() => {\n const currentShowAllItems = showAllItems();\n const currentOriginalCollection = originalCollection();\n const currentFilteredCollection = filteredCollection();\n const currentLastCollection = lastCollection();\n\n if (triggerState.isOpen) {\n if (currentShowAllItems) {\n return currentOriginalCollection;\n }\n\n return currentFilteredCollection;\n }\n\n return currentLastCollection;\n });\n\n const defaultSelectedKey = createMemo(() => {\n const currentSelectionMode = selectionMode();\n const currentInitialValue = initialValue;\n\n return (\n getLegacyDefaultSelectedKey(props) ??\n (currentSelectionMode === \"single\" &&\n (typeof currentInitialValue === \"string\" ||\n typeof currentInitialValue === \"number\")\n ? currentInitialValue\n : null)\n );\n });\n\n return merge(validation, triggerState, {\n get close() {\n return commitValue;\n },\n get collection() {\n return displayedCollection();\n },\n commit,\n get defaultInputValue() {\n return (\n getDefaultInputValue(\n props.defaultInputValue,\n defaultSelectedKey(),\n collection()\n ) ?? initialInputValue\n );\n },\n // oxlint-disable-next-line typescript/no-deprecated -- Expose the legacy output alias for existing consumers; internal state uses its modern replacement.\n get defaultSelectedKey() {\n return defaultSelectedKey();\n },\n get defaultValue() {\n // SAFETY: the default is constructed with the same selection mode as this state.\n // oxlint-disable-next-line typescript/no-unsafe-type-assertion\n return (defaultValue() ?? initialValue) as ValueType<M>;\n },\n get disabledKeys() {\n return disabledKeys();\n },\n get focusStrategy() {\n return focusStrategy();\n },\n get inputValue() {\n return inputValue();\n },\n get isFocused() {\n return isFocused();\n },\n open,\n revert,\n // oxlint-disable-next-line typescript/no-deprecated -- Expose the legacy output alias for existing consumers; internal state uses its modern replacement.\n get selectedItem() {\n return selectedItems()[0] ?? null;\n },\n get selectedItems() {\n return selectedItems();\n },\n // oxlint-disable-next-line typescript/no-deprecated -- Expose the legacy output alias for existing consumers; internal state uses its modern replacement.\n get selectedKey() {\n return selectedKey();\n },\n get selectionManager() {\n return selectionManager();\n },\n setFocused,\n setInputValue,\n // oxlint-disable-next-line typescript/no-deprecated -- Expose the legacy output alias for existing consumers; internal state uses its modern replacement.\n get setSelectedKey() {\n return setValue;\n },\n setValue,\n toggle,\n get value() {\n // SAFETY: displayValue normalizes single mode to a key and multiple mode to an array.\n // oxlint-disable-next-line typescript/no-unsafe-type-assertion\n return displayValue() as ValueType<M>;\n },\n } satisfies Partial<ComboBoxState<T, M>>);\n}\n\nfunction filterCollection<T>(\n collection: Collection<Node<T>>,\n inputValue: string,\n filter: FilterFn\n): Collection<Node<T>> {\n return new ListCollection(\n filterNodes(collection, collection, inputValue, filter)\n );\n}\n\nfunction filterNodes<T>(\n collection: Collection<Node<T>>,\n nodes: Iterable<Node<T>>,\n inputValue: string,\n filter: FilterFn\n): Iterable<Node<T>> {\n const filteredNode: Node<T>[] = [];\n\n for (const node of nodes) {\n if (node.type === \"section\" && node.hasChildNodes) {\n const filtered = filterNodes(\n collection,\n getChildNodes(node, collection),\n inputValue,\n filter\n );\n\n if ([...filtered].some((localNode) => localNode.type === \"item\")) {\n // oxlint-disable-next-line typescript/no-deprecated -- Node-backed collection construction must populate the upstream childNodes output contract.\n filteredNode.push({ ...node, childNodes: filtered });\n }\n } else if (node.type !== \"item\" || filter(node.textValue, inputValue)) {\n filteredNode.push({ ...node });\n }\n }\n\n return filteredNode;\n}\n\nfunction getDefaultInputValue(\n defaultInputValue: string | null | undefined,\n selectedKey: Key | null,\n collection: Collection<Node<unknown>>\n) {\n if (\n (defaultInputValue === null || defaultInputValue === undefined) &&\n selectedKey !== null &&\n selectedKey !== undefined\n ) {\n return collection.getItem(selectedKey)?.textValue ?? \"\";\n }\n\n return defaultInputValue;\n}\n\nfunction convertValue(value: Key | readonly Key[] | null | undefined) {\n if (value === undefined) {\n return value;\n }\n\n if (value === null) {\n return [];\n }\n\n return isKeyArray(value) ? value : [value];\n}\n\nfunction isKeyArray(\n value: Key | readonly Key[] | null | undefined\n): value is readonly Key[] {\n return Array.isArray(value);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoOA,SAAgB,oBAGd,OAAwD;CACxD,MAAM,gBAAgB,iBAAiB,MAAM,aAAa;CAC1D,MAAM,cAAc,iBAAiB,MAAM,eAAe,OAAO;CAEjE,MAAM,wBAAwB,iBACtB,MAAM,yBAAyB,KACvC;CAEA,MAAM,oBAAoB,iBAAiB,MAAM,iBAAiB;CAClE,MAAM,oBAAoB,iBAAiB,MAAM,qBAAqB,IAAI;CAE1E,MAAM,gBAAgB,iBAAiB,MAAM,iBAAiB,QAAQ;CAEtE,MAAM,CAAC,cAAc,mBAAmB,aAAa,OAAO,EAC1D,YAAY,KACd,CAAC;CAED,MAAM,CAAC,WAAW,mBAAmB,aAAa,OAAO,EACvD,YAAY,KACd,CAAC;CAED,MAAM,CAAC,eAAe,oBAAoB,aACxC,MACA,EAAE,YAAY,KAAK,CACrB;CAEA,IAAI,mBAAmB;CAEvB,MAAM,eAAe,iBAAiB;EACpC,MAAM,uBAAuB,cAAc;EAE3C,OACE,MAAM,iBACL,yBAAyB,WACrB,4BAA4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"file":"create-combo-box-state.js","names":[],"sources":["../../src/combobox/create-combo-box-state.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n/*\n * Derived from Adobe React Spectrum: packages/react-stately/src/combobox/useComboBoxState.ts.\n * Modified for Solid Aria: adapted reactive state, getters, imports, and APIs for Solid 2.\n * Licensed under Apache-2.0. See LICENSES/Apache-2.0.txt and NOTICE.txt at the repository root.\n */\n\nimport type {\n Collection,\n CollectionBase,\n CollectionStateBase,\n FocusableProps,\n FocusStrategy,\n HelpTextProps,\n InputBase,\n Key,\n LabelableProps,\n Node,\n Selection,\n TextInputBase,\n Validation,\n ValueBase,\n} from \"@solid2-aria/types-shared\";\nimport {\n createMemo,\n createSignal,\n createRenderEffect,\n untrack,\n merge,\n} from \"solid-js\";\n\nimport { getChildNodes } from \"../collections/get-child-nodes\";\nimport { createFormValidationState } from \"../form/create-form-validation-state\";\nimport type { FormValidationState } from \"../form/create-form-validation-state\";\nimport { createListState } from \"../list/create-list-state\";\nimport type { ListState } from \"../list/create-list-state\";\nimport { ListCollection } from \"../list/list-collection\";\nimport { createOverlayTriggerState } from \"../overlays/create-overlay-trigger-state\";\nimport type { OverlayTriggerState } from \"../overlays/create-overlay-trigger-state\";\nimport { createControlledSignal } from \"../utils/create-controlled-signal\";\nimport {\n getLegacyDefaultSelectedKey,\n getLegacySelectedKey,\n notifyLegacySelectionChange,\n} from \"../utils/legacy-props\";\n\nexport type MenuTriggerAction = \"focus\" | \"input\" | \"manual\";\n\nexport type SelectionMode = \"single\" | \"multiple\";\n\nexport type ValueType<M extends SelectionMode> = M extends \"single\"\n ? Key | null\n : readonly Key[];\n\nexport type ChangeValueType<M extends SelectionMode> = M extends \"single\"\n ? Key | null\n : Key[];\n\ntype ValidationType<M extends SelectionMode> = M extends \"single\"\n ? Key | null\n : Key[];\n\nexport interface ComboBoxValidationValue<M extends SelectionMode = \"single\"> {\n /**\n * The selected key in the ComboBox.\n *\n * @deprecated\n */\n selectedKey: Key | null;\n /** The keys of the currently selected items. */\n value: ValidationType<M>;\n /** The value of the ComboBox input. */\n inputValue: string;\n}\n\nexport interface ComboBoxProps<T, M extends SelectionMode = \"single\">\n extends\n CollectionBase<T>,\n InputBase,\n ValueBase<ValueType<M>, ChangeValueType<M>>,\n TextInputBase,\n Validation<ComboBoxValidationValue<M>>,\n FocusableProps<HTMLInputElement>,\n LabelableProps,\n HelpTextProps {\n /** The list of ComboBox items (uncontrolled). */\n defaultItems?: Iterable<T>;\n /** The list of ComboBox items (controlled). */\n items?: Iterable<T>;\n /**\n * Method that is called when the open state of the menu changes. Returns the new open state and\n * the action that caused the opening of the menu.\n */\n onOpenChange?: (isOpen: boolean, menuTrigger?: MenuTriggerAction) => void;\n /**\n * Whether single or multiple selection is enabled.\n *\n * @default 'single'\n */\n selectionMode?: M;\n /**\n * The currently selected key in the collection (controlled).\n *\n * @deprecated\n */\n selectedKey?: Key | null;\n /**\n * The initial selected key in the collection (uncontrolled).\n *\n * @deprecated\n */\n defaultSelectedKey?: Key | null;\n /**\n * Handler that is called when the selection changes.\n *\n * @deprecated\n */\n onSelectionChange?: (key: Key | null) => void;\n /** The value of the ComboBox input (controlled). */\n inputValue?: string;\n /** The default value of the ComboBox input (uncontrolled). */\n defaultInputValue?: string;\n /** Handler that is called when the ComboBox input value changes. */\n onInputChange?: (value: string) => void;\n /** Whether the ComboBox allows a non-item matching input value to be set. */\n allowsCustomValue?: boolean;\n // /**\n // * Whether the Combobox should only suggest matching options or autocomplete the field with the nearest matching option.\n // * @default 'suggest'\n // */\n // completionMode?: 'suggest' | 'complete',\n /**\n * The interaction required to display the ComboBox menu.\n *\n * @default 'input'\n */\n menuTrigger?: MenuTriggerAction;\n}\n\nexport interface ComboBoxState<T, M extends SelectionMode = \"single\">\n extends ListState<T>, OverlayTriggerState, FormValidationState {\n /**\n * The key for the first selected item.\n *\n * @deprecated\n */\n readonly selectedKey: Key | null;\n /**\n * The default selected key.\n *\n * @deprecated\n */\n readonly defaultSelectedKey: Key | null;\n /**\n * Sets the selected key.\n *\n * @deprecated\n */\n setSelectedKey: (key: Key | null) => void;\n /** The current combobox value. */\n readonly value: ValueType<M>;\n /** The default combobox value. */\n readonly defaultValue: ValueType<M>;\n /** Sets the combobox value. */\n setValue: (value: Key | readonly Key[] | null) => void;\n /**\n * The value of the first selected item.\n *\n * @deprecated\n */\n readonly selectedItem: Node<T> | null;\n /** The value of the selected items. */\n readonly selectedItems: Node<T>[];\n /** The current value of the combo box input. */\n inputValue: string;\n /** The default value of the combo box input. */\n defaultInputValue: string;\n /** Sets the value of the combo box input. */\n setInputValue: (value: string) => void;\n /** Selects the currently focused item and updates the input value. */\n commit: () => void;\n /** Controls which item will be auto focused when the menu opens. */\n readonly focusStrategy: FocusStrategy | null;\n /** Whether the select is currently focused. */\n readonly isFocused: boolean;\n /** Sets whether the select is focused. */\n setFocused: (isFocused: boolean) => void;\n /** Opens the menu. */\n open: (\n focusStrategy?: FocusStrategy | null,\n trigger?: MenuTriggerAction\n ) => void;\n /** Toggles the menu. */\n toggle: (\n focusStrategy?: FocusStrategy | null,\n trigger?: MenuTriggerAction\n ) => void;\n /** Resets the input value to the previously selected item's text if any and closes the menu. */\n revert: () => void;\n}\n\ntype FilterFn = (textValue: string, inputValue: string) => boolean;\n\nexport interface ComboBoxStateOptions<T, M extends SelectionMode = \"single\">\n extends Omit<ComboBoxProps<T, M>, \"children\">, CollectionStateBase<T> {\n /** The filter function used to determine if a option should be included in the combo box list. */\n defaultFilter?: FilterFn;\n /** Whether the combo box allows the menu to be open when the collection is empty. */\n allowsEmptyCollection?: boolean;\n /** Whether the combo box menu should close on blur. */\n shouldCloseOnBlur?: boolean;\n}\n\n/**\n * Provides state management for a combo box component. Handles building a collection of items from\n * props and manages the option selection state of the combo box. In addition, it tracks the input\n * value, focus state, and other properties of the combo box.\n */\nexport function createComboBoxState<\n T extends object,\n M extends SelectionMode = \"single\",\n>(props: ComboBoxStateOptions<T, M>): ComboBoxState<T, M> {\n const defaultFilter = createMemo(() => props.defaultFilter);\n const menuTrigger = createMemo(() => props.menuTrigger ?? \"input\");\n\n const allowsEmptyCollection = createMemo(\n () => props.allowsEmptyCollection ?? false\n );\n\n const allowsCustomValue = createMemo(() => props.allowsCustomValue);\n const shouldCloseOnBlur = createMemo(() => props.shouldCloseOnBlur ?? true);\n\n const selectionMode = createMemo(() => props.selectionMode ?? \"single\");\n\n const [showAllItems, setShowAllItems] = createSignal(false, {\n ownedWrite: true,\n });\n\n const [isFocused, setFocusedState] = createSignal(false, {\n ownedWrite: true,\n });\n\n const [focusStrategy, setFocusStrategy] = createSignal<FocusStrategy | null>(\n null,\n { ownedWrite: true }\n );\n\n let closedDueToEmpty = false;\n\n const defaultValue = createMemo(() => {\n const currentSelectionMode = selectionMode();\n\n return (\n props.defaultValue ??\n (currentSelectionMode === \"single\"\n ? (getLegacyDefaultSelectedKey(props) ?? null)\n : [])\n );\n });\n\n const value = createMemo(() => {\n const currentSelectionMode = selectionMode();\n\n return (\n props.value ??\n (currentSelectionMode === \"single\"\n ? getLegacySelectedKey(props)\n : undefined)\n );\n });\n\n const [controlledValue, setControlledValue] = createControlledSignal<\n Key | readonly Key[] | null\n >(\n () => value(),\n untrack(() => defaultValue()),\n (localValue) => {\n const change = isKeyArray(localValue) ? [...localValue] : localValue;\n // SAFETY: setValue normalizes changes to the active selection mode.\n // oxlint-disable-next-line typescript/no-unsafe-type-assertion\n props.onChange?.(change as ChangeValueType<M>);\n }\n );\n\n // Only display the first selected item if in single selection mode but the value is an array.\n const displayValue = createMemo(() => {\n const currentSelectionMode = selectionMode();\n const currentControlledValue = controlledValue();\n\n return currentSelectionMode === \"single\" &&\n isKeyArray(currentControlledValue)\n ? (currentControlledValue[0] ?? null)\n : currentControlledValue;\n });\n\n const setValue = (localValue: Key | readonly Key[] | null) => {\n const currentSelectionMode = selectionMode();\n const currentDisplayValue = displayValue();\n\n if (currentSelectionMode === \"single\") {\n const key = isKeyArray(localValue) ? (localValue[0] ?? null) : localValue;\n setControlledValue(key);\n\n if (key !== currentDisplayValue) {\n notifyLegacySelectionChange(props, key);\n }\n } else {\n let keys: Key[] = [];\n\n if (isKeyArray(localValue)) {\n keys = [...localValue];\n } else if (localValue !== null && localValue !== undefined) {\n keys = [localValue];\n }\n\n setControlledValue(keys);\n }\n };\n\n const derivedProperty0 = createMemo(() => {\n const currentDisplayValue = displayValue();\n\n return convertValue(currentDisplayValue);\n });\n\n const listState = createListState(\n merge(props, {\n get allowDuplicateSelectionEvents() {\n return true;\n },\n get disallowEmptySelection() {\n return selectionMode() === \"single\";\n },\n get items() {\n return props.items ?? props.defaultItems;\n },\n get onSelectionChange() {\n return (keys: Selection) => {\n const currentSelectionMode = selectionMode();\n const currentDisplayValue = displayValue();\n\n // impossible, but TS doesn't know that\n if (keys === \"all\") {\n return;\n }\n\n if (currentSelectionMode === \"single\") {\n const key = keys.values().next().value ?? null;\n\n if (key === currentDisplayValue) {\n notifyLegacySelectionChange(props, key);\n // If key is the same, reset the inputValue and close the menu\n // (scenario: user clicks on already selected option)\n resetInputValue();\n closeMenu();\n } else {\n setValue(key);\n }\n } else {\n setValue([...keys]);\n }\n };\n },\n get selectedKeys() {\n return derivedProperty0();\n },\n get selectionMode() {\n return selectionMode();\n },\n })\n );\n\n const collection = createMemo(() => listState.collection);\n const selectionManager = createMemo(() => listState.selectionManager);\n const disabledKeys = createMemo(() => listState.disabledKeys);\n\n const selectedKey = createMemo(() => {\n const currentSelectionMode = selectionMode();\n const currentSelectionManager = selectionManager();\n\n return currentSelectionMode === \"single\"\n ? currentSelectionManager.firstSelectedKey\n : null;\n });\n\n const selectedItems = createMemo(() => {\n const currentSelectionManager = selectionManager();\n\n return [...currentSelectionManager.selectedKeys].flatMap((key) => {\n const item = collection().getItem(key);\n\n return item === null || item === undefined ? [] : [item];\n });\n });\n\n const [inputValue, setInputValue] = createControlledSignal(\n () => props.inputValue,\n untrack(() => {\n const currentSelectedKey = selectedKey();\n const currentCollection = collection();\n\n return (\n getDefaultInputValue(\n props.defaultInputValue,\n currentSelectedKey,\n currentCollection\n ) ?? \"\"\n );\n }),\n (localValue) => {\n props.onInputChange?.(localValue);\n }\n );\n\n const initialValue = untrack(() => displayValue());\n const initialInputValue = untrack(() => inputValue());\n // Preserve original collection so we can show all items on demand\n const originalCollection = createMemo(() => collection());\n\n const filteredCollection = createMemo(() => {\n const currentDefaultFilter = defaultFilter();\n const currentCollection = collection();\n const currentInputValue = inputValue();\n\n return (\n // No default filter if items are controlled.\n (props.items !== null && props.items !== undefined) ||\n !currentDefaultFilter\n ? currentCollection\n : filterCollection(\n currentCollection,\n currentInputValue,\n currentDefaultFilter\n )\n );\n });\n\n const [lastCollection, setLastCollection] = createSignal(\n untrack(() => filteredCollection()),\n { ownedWrite: true }\n );\n // Track what action is attempting to open the menu\n\n let menuOpenTrigger: MenuTriggerAction | undefined = \"focus\";\n\n const onOpenChange = (open: boolean) => {\n const currentSelectionManager = selectionManager();\n\n if (props.onOpenChange) {\n props.onOpenChange(open, open ? menuOpenTrigger : undefined);\n }\n\n currentSelectionManager.setFocused(open);\n\n if (!open) {\n currentSelectionManager.setFocusedKey(null);\n }\n };\n\n const triggerState = createOverlayTriggerState(\n merge(props, {\n defaultOpen: undefined,\n isOpen: undefined,\n onOpenChange,\n })\n );\n\n const open = (\n localFocusStrategy: FocusStrategy | null = null,\n trigger?: MenuTriggerAction\n ) => {\n const currentMenuTrigger = menuTrigger();\n const currentAllowsEmptyCollection = allowsEmptyCollection();\n const currentFilteredCollection = filteredCollection();\n const currentOriginalCollection = originalCollection();\n\n const displayAllItems =\n trigger === \"manual\" ||\n (trigger === \"focus\" && currentMenuTrigger === \"focus\");\n\n // Prevent open operations from triggering if there is nothing to display\n // Also prevent open operations from triggering if items are uncontrolled but defaultItems is empty, even if displayAllItems is true.\n // This is to prevent comboboxes with empty defaultItems from opening but allow controlled items comboboxes to open even if the inital list is empty (assumption is user will provide swap the empty list with a base list via onOpenChange returning `menuTrigger` manual)\n if (\n currentAllowsEmptyCollection ||\n currentFilteredCollection.size > 0 ||\n (displayAllItems && currentOriginalCollection.size > 0) ||\n props.items\n ) {\n if (\n displayAllItems &&\n !triggerState.isOpen &&\n props.items === undefined\n ) {\n // Show all items if menu is manually opened. Only care about this if items are undefined\n setShowAllItems(true);\n }\n\n menuOpenTrigger = trigger;\n setFocusStrategy(localFocusStrategy);\n triggerState.open();\n }\n };\n\n const toggle = (\n localFocusStrategy: FocusStrategy | null = null,\n trigger?: MenuTriggerAction\n ) => {\n const currentMenuTrigger = menuTrigger();\n const currentAllowsEmptyCollection = allowsEmptyCollection();\n const currentFilteredCollection = filteredCollection();\n const currentOriginalCollection = originalCollection();\n\n const displayAllItems =\n trigger === \"manual\" ||\n (trigger === \"focus\" && currentMenuTrigger === \"focus\");\n\n // If the menu is closed and there is nothing to display, early return so toggle isn't called to prevent extraneous onOpenChange\n if (\n !currentAllowsEmptyCollection &&\n !(currentFilteredCollection.size > 0) &&\n (!displayAllItems || !(currentOriginalCollection.size > 0)) &&\n !props.items &&\n !triggerState.isOpen\n ) {\n return;\n }\n\n if (displayAllItems && !triggerState.isOpen && props.items === undefined) {\n // Show all items if menu is toggled open. Only care about this if items are undefined\n setShowAllItems(true);\n }\n\n // Only update the menuOpenTrigger if menu is currently closed\n if (!triggerState.isOpen) {\n menuOpenTrigger = trigger;\n }\n\n toggleMenu(localFocusStrategy);\n };\n\n const updateLastCollection = () => {\n const currentShowAllItems = showAllItems();\n const currentOriginalCollection = originalCollection();\n const currentFilteredCollection = filteredCollection();\n setLastCollection(\n currentShowAllItems\n ? currentOriginalCollection\n : currentFilteredCollection\n );\n };\n\n // If menu is going to close, save the current collection so we can freeze the displayed collection when the\n // user clicks outside the popover to close the menu. Prevents the menu contents from updating as the menu closes.\n function toggleMenu(localFocusStrategy: FocusStrategy | null = null) {\n if (triggerState.isOpen) {\n updateLastCollection();\n }\n\n setFocusStrategy(localFocusStrategy);\n triggerState.toggle();\n }\n\n function closeMenu() {\n if (triggerState.isOpen) {\n updateLastCollection();\n triggerState.close();\n }\n }\n\n const [lastValue, setLastValue] = createSignal(\n untrack(() => inputValue()),\n { ownedWrite: true }\n );\n\n function resetInputValue() {\n const currentSelectedKey = selectedKey();\n const currentCollection = collection();\n\n const itemText =\n currentSelectedKey === null || currentSelectedKey === undefined\n ? \"\"\n : (currentCollection.getItem(currentSelectedKey)?.textValue ?? \"\");\n\n setLastValue(itemText);\n setInputValue(itemText);\n }\n\n let previousValue: Key | readonly Key[] | null | undefined = untrack(() =>\n displayValue()\n );\n\n let lastSelectedKeyText = untrack(() => {\n const currentSelectedKey = selectedKey();\n const currentCollection = collection();\n\n return currentSelectedKey === null || currentSelectedKey === undefined\n ? \"\"\n : (currentCollection.getItem(currentSelectedKey)?.textValue ?? \"\");\n });\n\n createRenderEffect(\n () => {\n const currentSelectedKey = selectedKey();\n const currentCollection = collection();\n\n return {\n currentAllowsEmptyCollection: allowsEmptyCollection(),\n currentDisplayValue: displayValue(),\n currentFilteredCollection: filteredCollection(),\n currentInputValue: inputValue(),\n currentIsFocused: isFocused(),\n currentIsOpen: triggerState.isOpen,\n currentLastValue: lastValue(),\n currentMenuTrigger: menuTrigger(),\n currentSelectedKey,\n currentSelectedText:\n currentSelectedKey === null\n ? \"\"\n : (currentCollection.getItem(currentSelectedKey)?.textValue ?? \"\"),\n currentSelectionManager: selectionManager(),\n currentSelectionMode: selectionMode(),\n currentShowAllItems: showAllItems(),\n currentValue: value(),\n inputIsControlled: props.inputValue !== undefined,\n };\n },\n ({\n currentIsFocused,\n currentFilteredCollection,\n currentAllowsEmptyCollection,\n currentInputValue,\n currentLastValue,\n currentMenuTrigger,\n currentShowAllItems,\n currentDisplayValue,\n currentSelectionMode,\n currentSelectionManager,\n currentValue,\n currentSelectedKey,\n currentSelectedText,\n currentIsOpen,\n inputIsControlled,\n }) => {\n function synchronizeMenu() {\n // Open and close menu automatically when the input value changes if the input is focused,\n // and there are items in the collection or allowEmptyCollection is true.\n if (\n currentIsFocused &&\n (currentFilteredCollection.size > 0 ||\n currentAllowsEmptyCollection) &&\n !currentIsOpen &&\n currentInputValue !== currentLastValue &&\n currentMenuTrigger !== \"manual\"\n ) {\n open(null, \"input\");\n }\n\n // Close the menu if the collection is empty. Don't close menu if filtered collection size is 0\n // but we are currently showing all items via button press\n if (\n !currentShowAllItems &&\n !currentAllowsEmptyCollection &&\n currentIsOpen &&\n currentFilteredCollection.size === 0\n ) {\n closedDueToEmpty = true;\n closeMenu();\n }\n\n // Re-open the menu when items become non-empty after being auto-closed due to\n // an empty collection (e.g. async load completed with results after a previous empty response).\n // This works for both controlled items on ComboBox and Collection patterns\n // (where items are provided on the ListBox rather than the ComboBox).\n if (\n currentIsFocused &&\n closedDueToEmpty &&\n currentFilteredCollection.size > 0 &&\n !currentIsOpen &&\n currentMenuTrigger !== \"manual\"\n ) {\n closedDueToEmpty = false;\n open(null, \"input\");\n }\n }\n\n function synchronizeSelection() {\n // Close when an item is selected.\n if (\n currentDisplayValue !== null &&\n currentDisplayValue !== undefined &&\n currentDisplayValue !== previousValue &&\n currentSelectionMode === \"single\"\n ) {\n closeMenu();\n }\n\n // Clear focused key when input value changes and display filtered collection again.\n if (currentInputValue !== currentLastValue) {\n currentSelectionManager.setFocusedKey(null);\n setShowAllItems(false);\n\n // Set value to null when the user clears the input.\n // If controlled, this is the application developer's responsibility.\n if (\n currentSelectionMode === \"single\" &&\n currentInputValue === \"\" &&\n (!inputIsControlled || currentValue === undefined)\n ) {\n setValue(null);\n }\n }\n\n // If the value changed, update the input value.\n // Do nothing if both inputValue and value are controlled.\n // In this case, it's the user's responsibility to update inputValue in onSelectionChange.\n if (\n currentDisplayValue !== previousValue &&\n (!inputIsControlled || currentValue === undefined)\n ) {\n resetInputValue();\n } else if (currentLastValue !== currentInputValue) {\n setLastValue(currentInputValue);\n }\n }\n\n function synchronizeSelectedText() {\n // Update the inputValue if the selected item's text changes from its last tracked value.\n // This is to handle cases where a selectedKey is specified but the items aren't available (async loading) or the selected item's text value updates.\n // Only reset if the user isn't currently within the field so we don't erroneously modify user input.\n // If inputValue is controlled, it is the user's responsibility to update the inputValue when items change.\n const selectedItemText = currentSelectedText;\n\n if (\n !currentIsFocused &&\n currentSelectedKey !== null &&\n currentSelectedKey !== undefined &&\n !inputIsControlled &&\n currentSelectedKey === previousValue &&\n lastSelectedKeyText !== selectedItemText\n ) {\n setLastValue(selectedItemText);\n setInputValue(selectedItemText);\n }\n\n return selectedItemText;\n }\n\n untrack(() => {\n synchronizeMenu();\n synchronizeSelection();\n const selectedItemText = synchronizeSelectedText();\n previousValue = currentDisplayValue;\n lastSelectedKeyText = selectedItemText;\n });\n }\n );\n\n const derivedProperty1 = createMemo(() => {\n const currentDisplayValue = displayValue();\n const currentInputValue = inputValue();\n const currentSelectedKey = selectedKey();\n\n return isKeyArray(currentDisplayValue) && currentDisplayValue.length === 0\n ? null\n : {\n inputValue: currentInputValue,\n selectedKey: currentSelectedKey,\n // SAFETY: The active selection mode determines the value shape; readonly input arrays are copied for mutable callback values.\n // oxlint-disable-next-line typescript/no-unsafe-type-assertion\n value: (isKeyArray(currentDisplayValue)\n ? [...currentDisplayValue]\n : currentDisplayValue) as ComboBoxValidationValue<M>[\"value\"],\n };\n });\n\n const validation = createFormValidationState(\n merge(props, {\n get value() {\n return derivedProperty1();\n },\n })\n );\n\n // Revert input value and close menu\n const revert = () => {\n const currentAllowsCustomValue = allowsCustomValue();\n const currentSelectedKey = selectedKey();\n closedDueToEmpty = false;\n\n if (\n currentAllowsCustomValue === true &&\n (currentSelectedKey === null || currentSelectedKey === undefined)\n ) {\n commitCustomValue();\n } else {\n commitSelection();\n }\n };\n\n function commitCustomValue() {\n const currentSelectionMode = selectionMode();\n const currentInputValue = inputValue();\n\n if (currentSelectionMode === \"multiple\") {\n // In multi-select mode, the input's custom text is independent from the selected items.\n // Closing or committing the field should not clear the existing selection.\n setLastValue(currentInputValue);\n closeMenu();\n\n return;\n }\n\n const localValue = null;\n previousValue = localValue;\n setValue(localValue);\n closeMenu();\n }\n\n function commitSelection(shouldForceSelectionChange = false) {\n const currentValue = value();\n const currentSelectedKey = selectedKey();\n const currentCollection = collection();\n const currentSelectionMode = selectionMode();\n const currentInputValue = inputValue();\n const currentDisplayValue = displayValue();\n\n // If multiple things are controlled, call onSelectionChange only when selecting the focused item,\n // or when inputValue needs to be synced back to the selected item on commit/blur.\n if (currentValue !== undefined && props.inputValue !== undefined) {\n const itemText =\n currentSelectedKey === null || currentSelectedKey === undefined\n ? \"\"\n : (currentCollection.getItem(currentSelectedKey)?.textValue ?? \"\");\n\n if (\n shouldForceSelectionChange ||\n currentSelectionMode === \"multiple\" ||\n currentInputValue !== itemText\n ) {\n notifyLegacySelectionChange(props, currentSelectedKey);\n\n const change = isKeyArray(currentDisplayValue)\n ? [...currentDisplayValue]\n : currentDisplayValue;\n\n // SAFETY: the committed value has the active mode's shape and arrays are copied for callbacks.\n // oxlint-disable-next-line typescript/no-unsafe-type-assertion\n props.onChange?.(change as ChangeValueType<M>);\n }\n\n // Keep the committed input value from reopening the menu.\n setLastValue(itemText);\n } else {\n // If only a single aspect of combobox is controlled, reset input value and close menu for the user\n resetInputValue();\n }\n\n closeMenu();\n }\n\n const commitValue = () => {\n const currentAllowsCustomValue = allowsCustomValue();\n const currentSelectedKey = selectedKey();\n const currentCollection = collection();\n const currentInputValue = inputValue();\n closedDueToEmpty = false;\n\n if (currentAllowsCustomValue === true) {\n const itemText =\n currentSelectedKey === null || currentSelectedKey === undefined\n ? \"\"\n : (currentCollection.getItem(currentSelectedKey)?.textValue ?? \"\");\n\n if (currentInputValue === itemText) {\n commitSelection();\n } else {\n commitCustomValue();\n }\n } else {\n // Reset inputValue and close menu\n commitSelection();\n }\n };\n\n const commit = () => {\n const currentSelectionManager = selectionManager();\n const currentSelectionMode = selectionMode();\n\n if (\n triggerState.isOpen &&\n currentSelectionManager.focusedKey !== null &&\n currentSelectionManager.focusedKey !== undefined\n ) {\n // Reset inputValue and close menu here if the selected key is already the focused key. Otherwise\n // fire onSelectionChange to allow the application to control the closing.\n if (\n currentSelectionManager.isSelected(\n currentSelectionManager.focusedKey\n ) &&\n currentSelectionMode === \"single\"\n ) {\n commitSelection(true);\n } else {\n currentSelectionManager.select(currentSelectionManager.focusedKey);\n }\n } else {\n commitValue();\n }\n };\n\n let valueOnFocus = untrack(() => {\n const currentInputValue = inputValue();\n const currentDisplayValue = displayValue();\n\n return [currentInputValue, currentDisplayValue];\n });\n\n const setFocused = (localIsFocused: boolean) => {\n const currentInputValue = inputValue();\n const currentDisplayValue = displayValue();\n const currentMenuTrigger = menuTrigger();\n const currentShouldCloseOnBlur = shouldCloseOnBlur();\n\n if (localIsFocused) {\n valueOnFocus = [currentInputValue, currentDisplayValue];\n\n if (currentMenuTrigger === \"focus\" && !(props.isReadOnly === true)) {\n open(null, \"focus\");\n }\n } else {\n if (currentShouldCloseOnBlur && props.isReadOnly !== true) {\n commitValue();\n }\n\n // Commit validation if the input value or selected items changed.\n if (\n currentInputValue !== valueOnFocus[0] ||\n currentDisplayValue !== valueOnFocus[1]\n ) {\n validation.commitValidation();\n }\n }\n\n setFocusedState(localIsFocused);\n };\n\n const displayedCollection = createMemo(() => {\n const currentShowAllItems = showAllItems();\n const currentOriginalCollection = originalCollection();\n const currentFilteredCollection = filteredCollection();\n const currentLastCollection = lastCollection();\n\n if (triggerState.isOpen) {\n if (currentShowAllItems) {\n return currentOriginalCollection;\n }\n\n return currentFilteredCollection;\n }\n\n return currentLastCollection;\n });\n\n const defaultSelectedKey = createMemo(() => {\n const currentSelectionMode = selectionMode();\n const currentInitialValue = initialValue;\n\n return (\n getLegacyDefaultSelectedKey(props) ??\n (currentSelectionMode === \"single\" &&\n (typeof currentInitialValue === \"string\" ||\n typeof currentInitialValue === \"number\")\n ? currentInitialValue\n : null)\n );\n });\n\n return merge(validation, triggerState, {\n get close() {\n return commitValue;\n },\n get collection() {\n return displayedCollection();\n },\n commit,\n get defaultInputValue() {\n return (\n getDefaultInputValue(\n props.defaultInputValue,\n defaultSelectedKey(),\n collection()\n ) ?? initialInputValue\n );\n },\n // oxlint-disable-next-line typescript/no-deprecated -- Expose the legacy output alias for existing consumers; internal state uses its modern replacement.\n get defaultSelectedKey() {\n return defaultSelectedKey();\n },\n get defaultValue() {\n // SAFETY: the default is constructed with the same selection mode as this state.\n // oxlint-disable-next-line typescript/no-unsafe-type-assertion\n return (defaultValue() ?? initialValue) as ValueType<M>;\n },\n get disabledKeys() {\n return disabledKeys();\n },\n get focusStrategy() {\n return focusStrategy();\n },\n get inputValue() {\n return inputValue();\n },\n get isFocused() {\n return isFocused();\n },\n open,\n revert,\n // oxlint-disable-next-line typescript/no-deprecated -- Expose the legacy output alias for existing consumers; internal state uses its modern replacement.\n get selectedItem() {\n return selectedItems()[0] ?? null;\n },\n get selectedItems() {\n return selectedItems();\n },\n // oxlint-disable-next-line typescript/no-deprecated -- Expose the legacy output alias for existing consumers; internal state uses its modern replacement.\n get selectedKey() {\n return selectedKey();\n },\n get selectionManager() {\n return selectionManager();\n },\n setFocused,\n setInputValue,\n // oxlint-disable-next-line typescript/no-deprecated -- Expose the legacy output alias for existing consumers; internal state uses its modern replacement.\n get setSelectedKey() {\n return setValue;\n },\n setValue,\n toggle,\n get value() {\n // SAFETY: displayValue normalizes single mode to a key and multiple mode to an array.\n // oxlint-disable-next-line typescript/no-unsafe-type-assertion\n return displayValue() as ValueType<M>;\n },\n } satisfies Partial<ComboBoxState<T, M>>);\n}\n\nfunction filterCollection<T>(\n collection: Collection<Node<T>>,\n inputValue: string,\n filter: FilterFn\n): Collection<Node<T>> {\n return new ListCollection(\n filterNodes(collection, collection, inputValue, filter)\n );\n}\n\nfunction filterNodes<T>(\n collection: Collection<Node<T>>,\n nodes: Iterable<Node<T>>,\n inputValue: string,\n filter: FilterFn\n): Iterable<Node<T>> {\n const filteredNode: Node<T>[] = [];\n\n for (const node of nodes) {\n if (node.type === \"section\" && node.hasChildNodes) {\n const filtered = filterNodes(\n collection,\n getChildNodes(node, collection),\n inputValue,\n filter\n );\n\n if ([...filtered].some((localNode) => localNode.type === \"item\")) {\n // oxlint-disable-next-line typescript/no-deprecated -- Node-backed collection construction must populate the upstream childNodes output contract.\n filteredNode.push({ ...node, childNodes: filtered });\n }\n } else if (node.type !== \"item\" || filter(node.textValue, inputValue)) {\n filteredNode.push({ ...node });\n }\n }\n\n return filteredNode;\n}\n\nfunction getDefaultInputValue(\n defaultInputValue: string | null | undefined,\n selectedKey: Key | null,\n collection: Collection<Node<unknown>>\n) {\n if (\n (defaultInputValue === null || defaultInputValue === undefined) &&\n selectedKey !== null &&\n selectedKey !== undefined\n ) {\n return collection.getItem(selectedKey)?.textValue ?? \"\";\n }\n\n return defaultInputValue;\n}\n\nfunction convertValue(value: Key | readonly Key[] | null | undefined) {\n if (value === undefined) {\n return value;\n }\n\n if (value === null) {\n return [];\n }\n\n return isKeyArray(value) ? value : [value];\n}\n\nfunction isKeyArray(\n value: Key | readonly Key[] | null | undefined\n): value is readonly Key[] {\n return Array.isArray(value);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoOA,SAAgB,oBAGd,OAAwD;CACxD,MAAM,gBAAgB,iBAAiB,MAAM,aAAa;CAC1D,MAAM,cAAc,iBAAiB,MAAM,eAAe,OAAO;CAEjE,MAAM,wBAAwB,iBACtB,MAAM,yBAAyB,KACvC;CAEA,MAAM,oBAAoB,iBAAiB,MAAM,iBAAiB;CAClE,MAAM,oBAAoB,iBAAiB,MAAM,qBAAqB,IAAI;CAE1E,MAAM,gBAAgB,iBAAiB,MAAM,iBAAiB,QAAQ;CAEtE,MAAM,CAAC,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gB,QAChB,gBAAgB,KAAA,GAEhB,OAAO,WAAW,QAAQ,WAAW,CAAC,EAAE,aAAa;CAGvD,OAAO;AACT;AAEA,SAAS,aAAa,OAAgD;CACpE,IAAI,UAAU,KAAA,GACZ,OAAO;CAGT,IAAI,UAAU,MACZ,OAAO,CAAC;CAGV,OAAO,WAAW,KAAK,IAAI,QAAQ,CAAC,KAAK;AAC3C;AAEA,SAAS,WACP,OACyB;CACzB,OAAO,MAAM,QAAQ,KAAK;AAC5B"}
@@ -37,6 +37,8 @@ export interface ScrollAnchorInfo {
37
37
  * selected as the anchor. Defaults to allowing any layoutInfo.
38
38
  */
39
39
  isAnchorable?: (layoutInfo: LayoutInfo) => boolean;
40
+ /** Whether an item's resize should follow the anchored edge. Defaults to allowing any key. */
41
+ isEdgeContent?: (key: Key) => boolean;
40
42
  }
41
43
  /**
42
44
  * Given a previously-captured anchor, computes the new viewport coordinate (along `axis`) needed
@@ -61,19 +63,18 @@ export declare function isNearEdge(visibleRect: Rect, contentSize: Size, edge: S
61
63
  * item where it was. If that doesn't apply, sticks the view to the edge instead, but
62
64
  * only if the user was already near the edge and didn't just scroll away on their own.
63
65
  */
64
- export declare function resolveScrollAdjustment(edge: ScrollAnchorEdge, axis: ScrollAnchorAxis, anchor: ScrollAnchor | null, wasNearAnchorEdge: boolean, isScrolling: boolean, itemSizeChanged: boolean, contentSizeDelta: number, getLayoutInfo: (key: Key) => LayoutInfo | null, previousVisibleRect: Rect, contentSize: Size): Rect | null;
66
+ export declare function resolveScrollAdjustment(edge: ScrollAnchorEdge, axis: ScrollAnchorAxis, anchor: ScrollAnchor | null, wasNearAnchorEdge: boolean, itemSizeChanged: boolean, contentSizeDelta: number, getLayoutInfo: (key: Key) => LayoutInfo | null, previousVisibleRect: Rect, contentSize: Size, changeIsAtEdge?: boolean): Rect | null;
65
67
  export interface ResolveAfterLayoutOptions {
66
68
  anchorInfo: ScrollAnchorInfo | null;
67
69
  /** The anchor captured by `captureBeforeLayout` before this pass's `layout.update()` ran. */
68
70
  anchor: ScrollAnchor | null;
69
- /** The full post-layout visible layout infos, i.e. `virtualizer.getVisibleLayoutInfos()`. */
70
- postLayoutInfos: Map<Key, LayoutInfo>;
71
71
  previousVisibleRect: Rect;
72
72
  previousContentSize: Size;
73
73
  contentSize: Size;
74
74
  itemSizeChanged: boolean;
75
- isScrolling: boolean;
76
75
  getLayoutInfo: (key: Key) => LayoutInfo | null;
76
+ /** Whether this pass changed content at the anchored edge. Defaults to true. */
77
+ changeIsAtEdge?: boolean;
77
78
  }
78
79
  /**
79
80
  * Tracks the cross-pass state needed to keep the viewport anchored to a layout's edge across
@@ -81,9 +82,7 @@ export interface ResolveAfterLayoutOptions {
81
82
  */
82
83
  export declare class ScrollAnchorTracker {
83
84
  private hasSnappedToEdge;
84
- private hadEstimatedVisibleItems;
85
- private wasNearAnchorEdge;
86
- /** Resets all tracked state, e.g. when the virtualizer's layout instance changes. */
85
+ /** Resets the first-layout flag, e.g. when the virtualizer's layout instance changes. */
87
86
  reset(): void;
88
87
  /**
89
88
  * Captures the anchor from pre-layout view positions.
@@ -16,13 +16,6 @@
16
16
  */
17
17
  import { Rect } from "./rect.js";
18
18
  // src/virtualizer/scroll-anchor.ts
19
- /**
20
- * Minimum overlap an item must have with the viewport, along the scroll axis,
21
- * to be eligible as a scroll anchor. Without this, an item that only overlaps the viewport
22
- * by a sliver (e.g. 1px, essentially scrolled out of view) can still "win" the anchor
23
- * tie-break over a substantially visible item.
24
- */
25
- const MIN_ANCHOR_OVERLAP = 4;
26
19
  function dimensionForAxis(axis) {
27
20
  return axis === "x" ? "width" : "height";
28
21
  }
@@ -48,21 +41,29 @@ function computeScrollAnchorTarget(anchor, axis, getLayoutInfo, visibleRect, con
48
41
  */
49
42
  function captureScrollAnchor(edge, axis, visibleRect, visibleLayoutInfos, isAnchorable = () => true) {
50
43
  const dimension = dimensionForAxis(axis);
44
+ let corner = "topLeft";
45
+ if (edge === "start") corner = axis === "x" ? "topRight" : "bottomLeft";
46
+ const viewportExtent = visibleRect[dimension];
51
47
  let best = null;
48
+ let fallback = null;
52
49
  for (const [key, layoutInfo] of visibleLayoutInfos) {
53
50
  if (!isAnchorable(layoutInfo)) continue;
54
51
  const overlap = layoutInfo.rect.intersection(visibleRect)[dimension];
55
- if (layoutInfo.rect.area > 0 && overlap >= MIN_ANCHOR_OVERLAP) {
56
- const corner = layoutInfo.rect.getCornerInRect(visibleRect) ?? "topLeft";
57
- const offset = layoutInfo.rect[corner][axis] - visibleRect[axis];
52
+ if (layoutInfo.rect.area <= 0 || overlap <= 0) continue;
53
+ const offset = layoutInfo.rect[corner][axis] - visibleRect[axis];
54
+ if (edge === "end" ? offset >= 0 : offset <= viewportExtent) {
58
55
  if (!best || (edge === "end" ? offset < best.offset : offset > best.offset)) best = {
59
56
  corner,
60
57
  key,
61
58
  offset
62
59
  };
63
- }
60
+ } else if (!fallback || (edge === "end" ? offset > fallback.offset : offset < fallback.offset)) fallback = {
61
+ corner,
62
+ key,
63
+ offset
64
+ };
64
65
  }
65
- return best;
66
+ return best ?? fallback;
66
67
  }
67
68
  /** Returns the viewport coordinate (along `axis`) that pins the viewport to `edge` of the content. */
68
69
  function getEdgeSnapTarget(edge, axis, contentSize, previousVisibleRect) {
@@ -84,13 +85,13 @@ function isNearEdge(visibleRect, contentSize, edge, axis, threshold) {
84
85
  * item where it was. If that doesn't apply, sticks the view to the edge instead, but
85
86
  * only if the user was already near the edge and didn't just scroll away on their own.
86
87
  */
87
- function resolveScrollAdjustment(edge, axis, anchor, wasNearAnchorEdge, isScrolling, itemSizeChanged, contentSizeDelta, getLayoutInfo, previousVisibleRect, contentSize) {
88
+ function resolveScrollAdjustment(edge, axis, anchor, wasNearAnchorEdge, itemSizeChanged, contentSizeDelta, getLayoutInfo, previousVisibleRect, contentSize, changeIsAtEdge = true) {
88
89
  const withTarget = (target) => axis === "x" ? new Rect(target, previousVisibleRect.y, previousVisibleRect.width, previousVisibleRect.height) : new Rect(previousVisibleRect.x, target, previousVisibleRect.width, previousVisibleRect.height);
89
- if (anchor) {
90
+ if (anchor && !(wasNearAnchorEdge && itemSizeChanged && contentSizeDelta !== 0 && changeIsAtEdge)) {
90
91
  const target = computeScrollAnchorTarget(anchor, axis, getLayoutInfo, previousVisibleRect, contentSize);
91
92
  if (target !== null && target !== void 0) return withTarget(target);
92
93
  }
93
- if (wasNearAnchorEdge && !isScrolling && (!itemSizeChanged || contentSizeDelta > 0)) {
94
+ if (wasNearAnchorEdge && (!itemSizeChanged || contentSizeDelta !== 0) && changeIsAtEdge) {
94
95
  const target = withTarget(getEdgeSnapTarget(edge, axis, contentSize, previousVisibleRect));
95
96
  return target.equals(previousVisibleRect) ? null : target;
96
97
  }
@@ -102,13 +103,9 @@ function resolveScrollAdjustment(edge, axis, anchor, wasNearAnchorEdge, isScroll
102
103
  */
103
104
  var ScrollAnchorTracker = class {
104
105
  hasSnappedToEdge = false;
105
- hadEstimatedVisibleItems = false;
106
- wasNearAnchorEdge = false;
107
- /** Resets all tracked state, e.g. when the virtualizer's layout instance changes. */
106
+ /** Resets the first-layout flag, e.g. when the virtualizer's layout instance changes. */
108
107
  reset() {
109
108
  this.hasSnappedToEdge = false;
110
- this.hadEstimatedVisibleItems = false;
111
- this.wasNearAnchorEdge = false;
112
109
  }
113
110
  /**
114
111
  * Captures the anchor from pre-layout view positions.
@@ -122,27 +119,18 @@ var ScrollAnchorTracker = class {
122
119
  * returns the resolved scroll target, or null if nothing should change.
123
120
  */
124
121
  resolveAfterLayout(options) {
125
- const { anchorInfo, anchor, postLayoutInfos, previousVisibleRect, previousContentSize, contentSize, itemSizeChanged, isScrolling, getLayoutInfo } = options;
122
+ const { anchorInfo, anchor, previousVisibleRect, previousContentSize, contentSize, itemSizeChanged, getLayoutInfo, changeIsAtEdge = true } = options;
126
123
  if (!anchorInfo) return null;
127
- const wasSettlingLastPass = this.hadEstimatedVisibleItems;
128
- const wasNearAnchorEdgeLastPass = this.wasNearAnchorEdge;
129
- let hasEstimated = false;
130
- for (const layoutInfo of postLayoutInfos.values()) if (layoutInfo.estimatedSize) {
131
- hasEstimated = true;
132
- break;
133
- }
134
- this.hadEstimatedVisibleItems = hasEstimated;
135
- if (!wasSettlingLastPass) this.wasNearAnchorEdge = isNearEdge(previousVisibleRect, previousContentSize, anchorInfo.edge, anchorInfo.axis, anchorInfo.threshold);
136
124
  if (previousVisibleRect.area === 0) return null;
137
125
  const dimension = anchorInfo.axis === "x" ? "width" : "height";
138
126
  const contentSizeDelta = contentSize[dimension] - previousContentSize[dimension];
139
127
  const isFirstAnchoredLayout = !this.hasSnappedToEdge;
140
128
  this.hasSnappedToEdge = true;
141
129
  if (!isFirstAnchoredLayout && contentSizeDelta === 0 && !itemSizeChanged) return null;
142
- const wasNearAnchorEdge = isFirstAnchoredLayout || wasSettlingLastPass && wasNearAnchorEdgeLastPass || isNearEdge(previousVisibleRect, previousContentSize, anchorInfo.edge, anchorInfo.axis, anchorInfo.threshold);
143
- if (!wasSettlingLastPass) this.wasNearAnchorEdge = wasNearAnchorEdge;
144
- const effectiveAnchor = isFirstAnchoredLayout || wasSettlingLastPass && wasNearAnchorEdgeLastPass ? null : anchor;
145
- return resolveScrollAdjustment(anchorInfo.edge, anchorInfo.axis, effectiveAnchor, wasNearAnchorEdge, isScrolling, itemSizeChanged, contentSizeDelta, getLayoutInfo, previousVisibleRect, contentSize);
130
+ const wasNearAnchorEdge = isFirstAnchoredLayout || isNearEdge(previousVisibleRect, previousContentSize, anchorInfo.edge, anchorInfo.axis, anchorInfo.threshold);
131
+ const effectiveAnchor = isFirstAnchoredLayout ? null : anchor;
132
+ const effectiveChangeIsAtEdge = isFirstAnchoredLayout || changeIsAtEdge;
133
+ return resolveScrollAdjustment(anchorInfo.edge, anchorInfo.axis, effectiveAnchor, wasNearAnchorEdge, itemSizeChanged, contentSizeDelta, getLayoutInfo, previousVisibleRect, contentSize, effectiveChangeIsAtEdge);
146
134
  }
147
135
  };
148
136
  export { ScrollAnchorTracker, captureScrollAnchor, computeScrollAnchorTarget, getEdgeSnapTarget, isNearEdge, resolveScrollAdjustment };
@@ -1 +1 @@
1
- {"version":3,"file":"scroll-anchor.js","names":[],"sources":["../../src/virtualizer/scroll-anchor.ts"],"sourcesContent":["/*\n * Copyright 2026 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n/*\n * Derived from Adobe React Spectrum: packages/react-stately/src/virtualizer/ScrollAnchor.ts.\n * Modified for Solid Aria: adapted imports, collection descriptors, and reactive state APIs for Solid 2.\n * Licensed under Apache-2.0. See LICENSES/Apache-2.0.txt and NOTICE.txt at the repository root.\n */\n\nimport type { Key } from \"@solid2-aria/types-shared\";\n\nimport type { LayoutInfo } from \"./layout-info\";\nimport { Rect } from \"./rect\";\nimport type { RectCorner } from \"./rect\";\nimport type { Size } from \"./size\";\n\nexport type ScrollAnchorAxis = \"x\" | \"y\";\n\nexport type ScrollAnchorEdge = \"start\" | \"end\";\n\nexport interface ScrollAnchor {\n key: Key;\n corner: RectCorner;\n offset: number;\n}\n\nexport interface ScrollAnchorInfo {\n /** Which edge of the content the viewport should stay anchored to. */\n edge: \"start\" | \"end\";\n /** Which axis `edge` refers to — 'y' for vertical lists, 'x' for horizontal. */\n axis: \"x\" | \"y\";\n /** Distance (px) from `edge` within which the viewport is considered \"following\" it. */\n threshold: number;\n /**\n * Optional classifier excluding structural/ephemeral layout infos (e.g. loaders) from being\n * selected as the anchor. Defaults to allowing any layoutInfo.\n */\n isAnchorable?: (layoutInfo: LayoutInfo) => boolean;\n}\n\n/**\n * Minimum overlap an item must have with the viewport, along the scroll axis,\n * to be eligible as a scroll anchor. Without this, an item that only overlaps the viewport\n * by a sliver (e.g. 1px, essentially scrolled out of view) can still \"win\" the anchor\n * tie-break over a substantially visible item.\n */\nconst MIN_ANCHOR_OVERLAP = 4;\n\nfunction dimensionForAxis(axis: ScrollAnchorAxis): \"width\" | \"height\" {\n return axis === \"x\" ? \"width\" : \"height\";\n}\n\n/**\n * Given a previously-captured anchor, computes the new viewport coordinate (along `axis`) needed\n * to keep it at the same offset from the viewport's start.\n */\nexport function computeScrollAnchorTarget(\n anchor: ScrollAnchor,\n axis: ScrollAnchorAxis,\n getLayoutInfo: (key: Key) => LayoutInfo | null,\n visibleRect: Rect,\n contentSize: Size\n): number | null {\n const finalInfo = getLayoutInfo(anchor.key);\n\n if (!finalInfo) {\n return null;\n }\n\n const adjustment =\n finalInfo.rect[anchor.corner][axis] - visibleRect[axis] - anchor.offset;\n\n if (adjustment === 0) {\n return null;\n }\n\n const target = visibleRect[axis] + adjustment;\n const dimension = dimensionForAxis(axis);\n const max = Math.max(0, contentSize[dimension] - visibleRect[dimension]);\n const clamped = Math.max(0, Math.min(max, target));\n\n return clamped === visibleRect[axis] ? null : clamped;\n}\n\n/**\n * Picks the item to anchor scroll to: the one nearest the top of the viewport when\n * anchoring to 'end', or nearest the bottom when anchoring to 'start'. Callers can\n * exclude certain items (like loaders) with `isAnchorable`.\n */\nexport function captureScrollAnchor(\n edge: ScrollAnchorEdge,\n axis: ScrollAnchorAxis,\n visibleRect: Rect,\n visibleLayoutInfos: Iterable<[Key, LayoutInfo]>,\n isAnchorable: (layoutInfo: LayoutInfo) => boolean = () => true\n): ScrollAnchor | null {\n const dimension = dimensionForAxis(axis);\n let best: ScrollAnchor | null = null;\n\n for (const [key, layoutInfo] of visibleLayoutInfos) {\n if (!isAnchorable(layoutInfo)) {\n continue;\n }\n\n const overlap = layoutInfo.rect.intersection(visibleRect)[dimension];\n\n if (layoutInfo.rect.area > 0 && overlap >= MIN_ANCHOR_OVERLAP) {\n const corner = layoutInfo.rect.getCornerInRect(visibleRect) ?? \"topLeft\";\n const offset = layoutInfo.rect[corner][axis] - visibleRect[axis];\n\n const isBetter =\n !best || (edge === \"end\" ? offset < best.offset : offset > best.offset);\n\n if (isBetter) {\n best = { corner, key, offset };\n }\n }\n }\n\n return best;\n}\n\n/** Returns the viewport coordinate (along `axis`) that pins the viewport to `edge` of the content. */\nexport function getEdgeSnapTarget(\n edge: ScrollAnchorEdge,\n axis: ScrollAnchorAxis,\n contentSize: Size,\n previousVisibleRect: Rect\n): number {\n if (edge === \"start\") {\n return 0;\n }\n\n const dimension = dimensionForAxis(axis);\n\n return Math.max(0, contentSize[dimension] - previousVisibleRect[dimension]);\n}\n\n/**\n * Whether the viewport is currently within `threshold` px of the anchored edge — used by\n * Virtualizer to compute wasNearAnchorEdge generically, without any layout-specific state.\n */\nexport function isNearEdge(\n visibleRect: Rect,\n contentSize: Size,\n edge: ScrollAnchorEdge,\n axis: ScrollAnchorAxis,\n threshold: number\n): boolean {\n if (edge === \"start\") {\n return visibleRect[axis] <= threshold;\n }\n\n const dimension = dimensionForAxis(axis);\n\n const distanceFromEnd =\n contentSize[dimension] - (visibleRect[axis] + visibleRect[dimension]);\n\n return distanceFromEnd <= threshold;\n}\n\n/**\n * Works out the new scroll position after content changes. Tries to keep the anchor\n * item where it was. If that doesn't apply, sticks the view to the edge instead, but\n * only if the user was already near the edge and didn't just scroll away on their own.\n */\nexport function resolveScrollAdjustment(\n edge: ScrollAnchorEdge,\n axis: ScrollAnchorAxis,\n anchor: ScrollAnchor | null,\n wasNearAnchorEdge: boolean,\n isScrolling: boolean,\n itemSizeChanged: boolean,\n contentSizeDelta: number,\n getLayoutInfo: (key: Key) => LayoutInfo | null,\n previousVisibleRect: Rect,\n contentSize: Size\n): Rect | null {\n const withTarget = (target: number): Rect =>\n axis === \"x\"\n ? new Rect(\n target,\n previousVisibleRect.y,\n previousVisibleRect.width,\n previousVisibleRect.height\n )\n : new Rect(\n previousVisibleRect.x,\n target,\n previousVisibleRect.width,\n previousVisibleRect.height\n );\n\n if (anchor) {\n const target = computeScrollAnchorTarget(\n anchor,\n axis,\n getLayoutInfo,\n previousVisibleRect,\n contentSize\n );\n\n if (target !== null && target !== undefined) {\n return withTarget(target);\n }\n }\n\n if (\n wasNearAnchorEdge &&\n !isScrolling &&\n (!itemSizeChanged || contentSizeDelta > 0)\n ) {\n const target = withTarget(\n getEdgeSnapTarget(edge, axis, contentSize, previousVisibleRect)\n );\n\n return target.equals(previousVisibleRect) ? null : target;\n }\n\n return null;\n}\n\nexport interface ResolveAfterLayoutOptions {\n anchorInfo: ScrollAnchorInfo | null;\n /** The anchor captured by `captureBeforeLayout` before this pass's `layout.update()` ran. */\n anchor: ScrollAnchor | null;\n /** The full post-layout visible layout infos, i.e. `virtualizer.getVisibleLayoutInfos()`. */\n postLayoutInfos: Map<Key, LayoutInfo>;\n previousVisibleRect: Rect;\n previousContentSize: Size;\n contentSize: Size;\n itemSizeChanged: boolean;\n isScrolling: boolean;\n getLayoutInfo: (key: Key) => LayoutInfo | null;\n}\n\n/**\n * Tracks the cross-pass state needed to keep the viewport anchored to a layout's edge across\n * relayouts.\n */\nexport class ScrollAnchorTracker {\n private hasSnappedToEdge = false;\n private hadEstimatedVisibleItems = false;\n private wasNearAnchorEdge = false;\n /** Resets all tracked state, e.g. when the virtualizer's layout instance changes. */\n reset(): void {\n this.hasSnappedToEdge = false;\n this.hadEstimatedVisibleItems = false;\n this.wasNearAnchorEdge = false;\n }\n /**\n * Captures the anchor from pre-layout view positions.\n */\n captureBeforeLayout(\n anchorInfo: ScrollAnchorInfo | null,\n preLayoutInfos: Iterable<[Key, LayoutInfo]>,\n visibleRect: Rect\n ): ScrollAnchor | null {\n if (!anchorInfo) {\n return null;\n }\n\n return captureScrollAnchor(\n anchorInfo.edge,\n anchorInfo.axis,\n visibleRect,\n preLayoutInfos,\n anchorInfo.isAnchorable\n );\n }\n /**\n * Runs the full post-layout decision: updates the tracked state for the next pass, and\n * returns the resolved scroll target, or null if nothing should change.\n */\n resolveAfterLayout(options: ResolveAfterLayoutOptions): Rect | null {\n const {\n anchorInfo,\n anchor,\n postLayoutInfos,\n previousVisibleRect,\n previousContentSize,\n contentSize,\n itemSizeChanged,\n isScrolling,\n getLayoutInfo,\n } = options;\n\n if (!anchorInfo) {\n return null;\n }\n\n // Read the previous pass's state into locals before any writes below overwrite it.\n const wasSettlingLastPass = this.hadEstimatedVisibleItems;\n const wasNearAnchorEdgeLastPass = this.wasNearAnchorEdge;\n let hasEstimated = false;\n\n for (const layoutInfo of postLayoutInfos.values()) {\n if (layoutInfo.estimatedSize) {\n hasEstimated = true;\n break;\n }\n }\n\n this.hadEstimatedVisibleItems = hasEstimated;\n\n // Don't recheck \"near edge?\" mid-resize because it could look like a scroll that never happened.\n // Reuse the answer from before the resizing started.\n if (!wasSettlingLastPass) {\n this.wasNearAnchorEdge = isNearEdge(\n previousVisibleRect,\n previousContentSize,\n anchorInfo.edge,\n anchorInfo.axis,\n anchorInfo.threshold\n );\n }\n\n if (previousVisibleRect.area === 0) {\n return null;\n }\n\n const dimension: \"width\" | \"height\" =\n anchorInfo.axis === \"x\" ? \"width\" : \"height\";\n\n const contentSizeDelta =\n contentSize[dimension] - previousContentSize[dimension];\n\n const isFirstAnchoredLayout = !this.hasSnappedToEdge;\n this.hasSnappedToEdge = true;\n\n // Only modify scroll when content actually changed (or this is the first layout, which always snaps)\n if (!isFirstAnchoredLayout && contentSizeDelta === 0 && !itemSizeChanged) {\n return null;\n }\n\n const wasNearAnchorEdge =\n isFirstAnchoredLayout ||\n (wasSettlingLastPass && wasNearAnchorEdgeLastPass) ||\n isNearEdge(\n previousVisibleRect,\n previousContentSize,\n anchorInfo.edge,\n anchorInfo.axis,\n anchorInfo.threshold\n );\n\n // A first-ever layout always snaps to the edge, even if the raw distance check says\n // otherwise. Save that real decision here so later passes in this cascade reuse it.\n if (!wasSettlingLastPass) {\n this.wasNearAnchorEdge = wasNearAnchorEdge;\n }\n\n // Skip restoring to the captured anchor while still resizing because items above it are also still growing,\n // and following it would fall short of the edge.\n const effectiveAnchor =\n isFirstAnchoredLayout ||\n (wasSettlingLastPass && wasNearAnchorEdgeLastPass)\n ? null\n : anchor;\n\n return resolveScrollAdjustment(\n anchorInfo.edge,\n anchorInfo.axis,\n effectiveAnchor,\n wasNearAnchorEdge,\n isScrolling,\n itemSizeChanged,\n contentSizeDelta,\n getLayoutInfo,\n previousVisibleRect,\n contentSize\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAsDA,MAAM,qBAAqB;AAE3B,SAAS,iBAAiB,MAA4C;CACpE,OAAO,SAAS,MAAM,UAAU;AAClC;;;;;AAMA,SAAgB,0BACd,QACA,MACA,eACA,aACA,aACe;CACf,MAAM,YAAY,cAAc,OAAO,GAAG;CAE1C,IAAI,CAAC,WACH,OAAO;CAGT,MAAM,aACJ,UAAU,KAAK,OAAO,OAAO,CAAC,QAAQ,YAAY,QAAQ,OAAO;CAEnE,IAAI,eAAe,GACjB,OAAO;CAGT,MAAM,SAAS,YAAY,QAAQ;CACnC,MAAM,YAAY,iBAAiB,IAAI;CACvC,MAAM,MAAM,KAAK,IAAI,GAAG,YAAY,aAAa,YAAY,UAAU;CACvE,MAAM,UAAU,KAAK,IAAI,GAAG,KAAK,IAAI,KAAK,MAAM,CAAC;CAEjD,OAAO,YAAY,YAAY,QAAQ,OAAO;AAChD;;;;;;AAOA,SAAgB,oBACd,MACA,MACA,aACA,oBACA,qBAA0D,MACrC;CACrB,MAAM,YAAY,iBAAiB,IAAI;CACvC,IAAI,OAA4B;CAEhC,KAAK,MAAM,CAAC,KAAK,eAAe,oBAAoB;EAClD,IAAI,CAAC,aAAa,UAAU,GAC1B;EAGF,MAAM,UAAU,WAAW,KAAK,aAAa,WAAW,CAAC,CAAC;EAE1D,IAAI,WAAW,KAAK,OAAO,KAAK,WAAW,oBAAoB;GAC7D,MAAM,SAAS,WAAW,KAAK,gBAAgB,WAAW,KAAK;GAC/D,MAAM,SAAS,WAAW,KAAK,OAAO,CAAC,Q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,gBACA,aACqB;EACrB,IAAI,CAAC,YACH,OAAO;EAGT,OAAO,oBACL,WAAW,MACX,WAAW,MACX,aACA,gBACA,WAAW,YACb;CACF;;;;;CAKA,mBAAmB,SAAiD;EAClE,MAAM,EACJ,YACA,QACA,iBACA,qBACA,qBACA,aACA,iBACA,aACA,kBACE;EAEJ,IAAI,CAAC,YACH,OAAO;EAIT,MAAM,sBAAsB,KAAK;EACjC,MAAM,4BAA4B,KAAK;EACvC,IAAI,eAAe;EAEnB,KAAK,MAAM,cAAc,gBAAgB,OAAO,GAC9C,IAAI,WAAW,eAAe;GAC5B,eAAe;GACf;EACF;EAGF,KAAK,2BAA2B;EAIhC,IAAI,CAAC,qBACH,KAAK,oBAAoB,WACvB,qBACA,qBACA,WAAW,MACX,WAAW,MACX,WAAW,SACb;EAGF,IAAI,oBAAoB,SAAS,GAC/B,OAAO;EAGT,MAAM,YACJ,WAAW,SAAS,MAAM,UAAU;EAEtC,MAAM,mBACJ,YAAY,aAAa,oBAAoB;EAE/C,MAAM,wBAAwB,CAAC,KAAK;EACpC,KAAK,mBAAmB;EAGxB,IAAI,CAAC,yBAAyB,qBAAqB,KAAK,CAAC,iBACvD,OAAO;EAGT,MAAM,oBACJ,yBACC,uBAAuB,6BACxB,WACE,qBACA,qBACA,WAAW,MACX,WAAW,MACX,WAAW,SACb;EAIF,IAAI,CAAC,qBACH,KAAK,oBAAoB;EAK3B,MAAM,kBACJ,yBACC,uBAAuB,4BACpB,OACA;EAEN,OAAO,wBACL,WAAW,MACX,WAAW,MACX,iBACA,mBACA,aACA,iBACA,kBACA,eACA,qBACA,WACF;CACF;AACF"}
1
+ {"version":3,"file":"scroll-anchor.js","names":[],"sources":["../../src/virtualizer/scroll-anchor.ts"],"sourcesContent":["/*\n * Copyright 2026 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n/*\n * Derived from Adobe React Spectrum: packages/react-stately/src/virtualizer/ScrollAnchor.ts.\n * Modified for Solid Aria: adapted imports, collection descriptors, and reactive state APIs for Solid 2.\n * Licensed under Apache-2.0. See LICENSES/Apache-2.0.txt and NOTICE.txt at the repository root.\n */\n\nimport type { Key } from \"@solid2-aria/types-shared\";\n\nimport type { LayoutInfo } from \"./layout-info\";\nimport { Rect } from \"./rect\";\nimport type { RectCorner } from \"./rect\";\nimport type { Size } from \"./size\";\n\nexport type ScrollAnchorAxis = \"x\" | \"y\";\n\nexport type ScrollAnchorEdge = \"start\" | \"end\";\n\nexport interface ScrollAnchor {\n key: Key;\n corner: RectCorner;\n offset: number;\n}\n\nexport interface ScrollAnchorInfo {\n /** Which edge of the content the viewport should stay anchored to. */\n edge: \"start\" | \"end\";\n /** Which axis `edge` refers to — 'y' for vertical lists, 'x' for horizontal. */\n axis: \"x\" | \"y\";\n /** Distance (px) from `edge` within which the viewport is considered \"following\" it. */\n threshold: number;\n /**\n * Optional classifier excluding structural/ephemeral layout infos (e.g. loaders) from being\n * selected as the anchor. Defaults to allowing any layoutInfo.\n */\n isAnchorable?: (layoutInfo: LayoutInfo) => boolean;\n /** Whether an item's resize should follow the anchored edge. Defaults to allowing any key. */\n isEdgeContent?: (key: Key) => boolean;\n}\n\nfunction dimensionForAxis(axis: ScrollAnchorAxis): \"width\" | \"height\" {\n return axis === \"x\" ? \"width\" : \"height\";\n}\n\n/**\n * Given a previously-captured anchor, computes the new viewport coordinate (along `axis`) needed\n * to keep it at the same offset from the viewport's start.\n */\nexport function computeScrollAnchorTarget(\n anchor: ScrollAnchor,\n axis: ScrollAnchorAxis,\n getLayoutInfo: (key: Key) => LayoutInfo | null,\n visibleRect: Rect,\n contentSize: Size\n): number | null {\n const finalInfo = getLayoutInfo(anchor.key);\n\n if (!finalInfo) {\n return null;\n }\n\n const adjustment =\n finalInfo.rect[anchor.corner][axis] - visibleRect[axis] - anchor.offset;\n\n if (adjustment === 0) {\n return null;\n }\n\n const target = visibleRect[axis] + adjustment;\n const dimension = dimensionForAxis(axis);\n const max = Math.max(0, contentSize[dimension] - visibleRect[dimension]);\n const clamped = Math.max(0, Math.min(max, target));\n\n return clamped === visibleRect[axis] ? null : clamped;\n}\n\n/**\n * Picks the item to anchor scroll to: the one nearest the top of the viewport when\n * anchoring to 'end', or nearest the bottom when anchoring to 'start'. Callers can\n * exclude certain items (like loaders) with `isAnchorable`.\n */\nexport function captureScrollAnchor(\n edge: ScrollAnchorEdge,\n axis: ScrollAnchorAxis,\n visibleRect: Rect,\n visibleLayoutInfos: Iterable<[Key, LayoutInfo]>,\n isAnchorable: (layoutInfo: LayoutInfo) => boolean = () => true\n): ScrollAnchor | null {\n const dimension = dimensionForAxis(axis);\n // Preserve the edge facing away from the anchored content edge.\n let corner: RectCorner = \"topLeft\";\n\n if (edge === \"start\") {\n corner = axis === \"x\" ? \"topRight\" : \"bottomLeft\";\n }\n\n const viewportExtent = visibleRect[dimension];\n let best: ScrollAnchor | null = null;\n let fallback: ScrollAnchor | null = null;\n\n for (const [key, layoutInfo] of visibleLayoutInfos) {\n if (!isAnchorable(layoutInfo)) {\n continue;\n }\n\n const overlap = layoutInfo.rect.intersection(visibleRect)[dimension];\n\n if (layoutInfo.rect.area <= 0 || overlap <= 0) {\n continue;\n }\n\n const offset = layoutInfo.rect[corner][axis] - visibleRect[axis];\n\n const leadingEdgeVisible =\n edge === \"end\" ? offset >= 0 : offset <= viewportExtent;\n\n if (leadingEdgeVisible) {\n const isBetter =\n !best || (edge === \"end\" ? offset < best.offset : offset > best.offset);\n\n if (isBetter) {\n best = { corner, key, offset };\n }\n } else {\n // When every candidate is clipped, keep the least-clipped item in place.\n const isBetter =\n !fallback ||\n (edge === \"end\" ? offset > fallback.offset : offset < fallback.offset);\n\n if (isBetter) {\n fallback = { corner, key, offset };\n }\n }\n }\n\n return best ?? fallback;\n}\n\n/** Returns the viewport coordinate (along `axis`) that pins the viewport to `edge` of the content. */\nexport function getEdgeSnapTarget(\n edge: ScrollAnchorEdge,\n axis: ScrollAnchorAxis,\n contentSize: Size,\n previousVisibleRect: Rect\n): number {\n if (edge === \"start\") {\n return 0;\n }\n\n const dimension = dimensionForAxis(axis);\n\n return Math.max(0, contentSize[dimension] - previousVisibleRect[dimension]);\n}\n\n/**\n * Whether the viewport is currently within `threshold` px of the anchored edge — used by\n * Virtualizer to compute wasNearAnchorEdge generically, without any layout-specific state.\n */\nexport function isNearEdge(\n visibleRect: Rect,\n contentSize: Size,\n edge: ScrollAnchorEdge,\n axis: ScrollAnchorAxis,\n threshold: number\n): boolean {\n if (edge === \"start\") {\n return visibleRect[axis] <= threshold;\n }\n\n const dimension = dimensionForAxis(axis);\n\n const distanceFromEnd =\n contentSize[dimension] - (visibleRect[axis] + visibleRect[dimension]);\n\n return distanceFromEnd <= threshold;\n}\n\n/**\n * Works out the new scroll position after content changes. Tries to keep the anchor\n * item where it was. If that doesn't apply, sticks the view to the edge instead, but\n * only if the user was already near the edge and didn't just scroll away on their own.\n */\nexport function resolveScrollAdjustment(\n edge: ScrollAnchorEdge,\n axis: ScrollAnchorAxis,\n anchor: ScrollAnchor | null,\n wasNearAnchorEdge: boolean,\n itemSizeChanged: boolean,\n contentSizeDelta: number,\n getLayoutInfo: (key: Key) => LayoutInfo | null,\n previousVisibleRect: Rect,\n contentSize: Size,\n changeIsAtEdge = true\n): Rect | null {\n const withTarget = (target: number): Rect =>\n axis === \"x\"\n ? new Rect(\n target,\n previousVisibleRect.y,\n previousVisibleRect.width,\n previousVisibleRect.height\n )\n : new Rect(\n previousVisibleRect.x,\n target,\n previousVisibleRect.width,\n previousVisibleRect.height\n );\n\n const followEdge =\n wasNearAnchorEdge &&\n itemSizeChanged &&\n contentSizeDelta !== 0 &&\n changeIsAtEdge;\n\n if (anchor && !followEdge) {\n const target = computeScrollAnchorTarget(\n anchor,\n axis,\n getLayoutInfo,\n previousVisibleRect,\n contentSize\n );\n\n if (target !== null && target !== undefined) {\n return withTarget(target);\n }\n }\n\n if (\n wasNearAnchorEdge &&\n (!itemSizeChanged || contentSizeDelta !== 0) &&\n changeIsAtEdge\n ) {\n const target = withTarget(\n getEdgeSnapTarget(edge, axis, contentSize, previousVisibleRect)\n );\n\n return target.equals(previousVisibleRect) ? null : target;\n }\n\n return null;\n}\n\nexport interface ResolveAfterLayoutOptions {\n anchorInfo: ScrollAnchorInfo | null;\n /** The anchor captured by `captureBeforeLayout` before this pass's `layout.update()` ran. */\n anchor: ScrollAnchor | null;\n previousVisibleRect: Rect;\n previousContentSize: Size;\n contentSize: Size;\n itemSizeChanged: boolean;\n getLayoutInfo: (key: Key) => LayoutInfo | null;\n /** Whether this pass changed content at the anchored edge. Defaults to true. */\n changeIsAtEdge?: boolean;\n}\n\n/**\n * Tracks the cross-pass state needed to keep the viewport anchored to a layout's edge across\n * relayouts.\n */\nexport class ScrollAnchorTracker {\n private hasSnappedToEdge = false;\n /** Resets the first-layout flag, e.g. when the virtualizer's layout instance changes. */\n reset(): void {\n this.hasSnappedToEdge = false;\n }\n /**\n * Captures the anchor from pre-layout view positions.\n */\n captureBeforeLayout(\n anchorInfo: ScrollAnchorInfo | null,\n preLayoutInfos: Iterable<[Key, LayoutInfo]>,\n visibleRect: Rect\n ): ScrollAnchor | null {\n if (!anchorInfo) {\n return null;\n }\n\n return captureScrollAnchor(\n anchorInfo.edge,\n anchorInfo.axis,\n visibleRect,\n preLayoutInfos,\n anchorInfo.isAnchorable\n );\n }\n /**\n * Runs the full post-layout decision: updates the tracked state for the next pass, and\n * returns the resolved scroll target, or null if nothing should change.\n */\n resolveAfterLayout(options: ResolveAfterLayoutOptions): Rect | null {\n const {\n anchorInfo,\n anchor,\n previousVisibleRect,\n previousContentSize,\n contentSize,\n itemSizeChanged,\n getLayoutInfo,\n changeIsAtEdge = true,\n } = options;\n\n if (!anchorInfo) {\n return null;\n }\n\n if (previousVisibleRect.area === 0) {\n return null;\n }\n\n const dimension: \"width\" | \"height\" =\n anchorInfo.axis === \"x\" ? \"width\" : \"height\";\n\n const contentSizeDelta =\n contentSize[dimension] - previousContentSize[dimension];\n\n const isFirstAnchoredLayout = !this.hasSnappedToEdge;\n this.hasSnappedToEdge = true;\n\n // Only modify scroll when content actually changed (or this is the first layout, which always snaps)\n if (!isFirstAnchoredLayout && contentSizeDelta === 0 && !itemSizeChanged) {\n return null;\n }\n\n const wasNearAnchorEdge =\n isFirstAnchoredLayout ||\n isNearEdge(\n previousVisibleRect,\n previousContentSize,\n anchorInfo.edge,\n anchorInfo.axis,\n anchorInfo.threshold\n );\n\n const effectiveAnchor = isFirstAnchoredLayout ? null : anchor;\n const effectiveChangeIsAtEdge = isFirstAnchoredLayout || changeIsAtEdge;\n\n return resolveScrollAdjustment(\n anchorInfo.edge,\n anchorInfo.axis,\n effectiveAnchor,\n wasNearAnchorEdge,\n itemSizeChanged,\n contentSizeDelta,\n getLayoutInfo,\n previousVisibleRect,\n contentSize,\n effectiveChangeIsAtEdge\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAkDA,SAAS,iBAAiB,MAA4C;CACpE,OAAO,SAAS,MAAM,UAAU;AAClC;;;;;AAMA,SAAgB,0BACd,QACA,MACA,eACA,aACA,aACe;CACf,MAAM,YAAY,cAAc,OAAO,GAAG;CAE1C,IAAI,CAAC,WACH,OAAO;CAGT,MAAM,aACJ,UAAU,KAAK,OAAO,OAAO,CAAC,QAAQ,YAAY,QAAQ,OAAO;CAEnE,IAAI,eAAe,GACjB,OAAO;CAGT,MAAM,SAAS,YAAY,QAAQ;CACnC,MAAM,YAAY,iBAAiB,IAAI;CACvC,MAAM,MAAM,KAAK,IAAI,GAAG,YAAY,aAAa,YAAY,UAAU;CACvE,MAAM,UAAU,KAAK,IAAI,GAAG,KAAK,IAAI,KAAK,MAAM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vD,MAAM,0BAA0B,yBAAyB;EAEzD,OAAO,wBACL,WAAW,MACX,WAAW,MACX,iBACA,mBACA,iBACA,kBACA,eACA,qBACA,aACA,uBACF;CACF;AACF"}
@@ -75,6 +75,8 @@ export declare class Virtualizer<T extends object, V> {
75
75
  private _invalidationContext;
76
76
  private readonly _overscanManager;
77
77
  private readonly _scrollAnchor;
78
+ private _hadItemResize;
79
+ private _batchIncludedEdgeContent;
78
80
  constructor(options: VirtualizerOptions<T, V>);
79
81
  /** Returns whether the given key, or an ancestor, is persisted. */
80
82
  isPersistedKey(key: Key): boolean;
@@ -94,6 +96,7 @@ export declare class Virtualizer<T extends object, V> {
94
96
  getVisibleView(key: Key): ReusableView<T, V> | undefined;
95
97
  invalidate(context: InvalidationContext): void;
96
98
  updateItemSize(key: Key, size: Size): void;
99
+ private isEdgeContent;
97
100
  }
98
101
  export {};
99
102
  //# sourceMappingURL=virtualizer.d.ts.map
@@ -82,6 +82,8 @@ var Virtualizer = class {
82
82
  _invalidationContext;
83
83
  _overscanManager;
84
84
  _scrollAnchor;
85
+ _hadItemResize = false;
86
+ _batchIncludedEdgeContent = false;
85
87
  constructor(options) {
86
88
  this.delegate = options.delegate;
87
89
  this._collection = options.collection;
@@ -161,14 +163,15 @@ var Virtualizer = class {
161
163
  const target = this._scrollAnchor.resolveAfterLayout({
162
164
  anchor,
163
165
  anchorInfo,
166
+ changeIsAtEdge: !this._hadItemResize || this._batchIncludedEdgeContent,
164
167
  contentSize: this.contentSize,
165
168
  getLayoutInfo: (key) => this.layout.getLayoutInfo(key),
166
- isScrolling: this._isScrolling,
167
169
  itemSizeChanged: context.itemSizeChanged ?? false,
168
- postLayoutInfos: anchorInfo ? this.getVisibleLayoutInfos() : /* @__PURE__ */ new Map(),
169
170
  previousContentSize,
170
171
  previousVisibleRect
171
172
  });
173
+ this._hadItemResize = false;
174
+ this._batchIncludedEdgeContent = false;
172
175
  if (target) {
173
176
  this.delegate.setVisibleRect(target);
174
177
  return;
@@ -306,7 +309,14 @@ var Virtualizer = class {
306
309
  }
307
310
  updateItemSize(key, size) {
308
311
  if (!this.layout.updateItemSize) return;
309
- if (this.layout.updateItemSize(key, size)) this.invalidate({ itemSizeChanged: true });
312
+ if (this.layout.updateItemSize(key, size)) {
313
+ this._hadItemResize = true;
314
+ this._batchIncludedEdgeContent ||= this.isEdgeContent(key);
315
+ this.invalidate({ itemSizeChanged: true });
316
+ }
317
+ }
318
+ isEdgeContent(key) {
319
+ return (this.layout.UNSTABLE_getScrollAnchorInfo?.(this._invalidationContext.layoutOptions))?.isEdgeContent?.(key) ?? true;
310
320
  }
311
321
  };
312
322
  export { Virtualizer };
@@ -1 +1 @@
1
- {"version":3,"file":"virtualizer.js","names":["generatedContent"],"sources":["../../src/virtualizer/virtualizer.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n/*\n * Derived from Adobe React Spectrum: packages/react-stately/src/virtualizer/Virtualizer.ts.\n * Modified for Solid Aria: adapted imports, collection descriptors, and reactive state APIs for Solid 2.\n * Licensed under Apache-2.0. See LICENSES/Apache-2.0.txt and NOTICE.txt at the repository root.\n */\n\nimport type { Collection, Key } from \"@solid2-aria/types-shared\";\n\nimport { requireValue } from \"../utils/require-value\";\nimport type { Layout } from \"./layout\";\nimport type { LayoutInfo } from \"./layout-info\";\nimport { OverscanManager } from \"./overscan-manager\";\nimport type { Point } from \"./point\";\nimport { Rect } from \"./rect\";\nimport type { ChildView, ReusableView } from \"./reusable-view\";\nimport { RootView } from \"./reusable-view\";\nimport { ScrollAnchorTracker } from \"./scroll-anchor\";\nimport type { ScrollAnchor } from \"./scroll-anchor\";\nimport { Size } from \"./size\";\nimport type {\n InvalidationContext,\n VirtualizerDelegate,\n VirtualizerRenderOptions,\n} from \"./types\";\nimport { isSetEqual } from \"./utils\";\n\ninterface VirtualizerOptions<T extends object, V> {\n delegate: VirtualizerDelegate<T, V>;\n collection: Collection<T>;\n layout: Layout<T>;\n}\n\n/**\n * The Virtualizer class renders a scrollable collection of data using customizable layouts.\n * It supports very large collections by only rendering visible views to the DOM, reusing\n * them as you scroll. Virtualizer can present any type of view, including non-item views\n * such as section headers and footers.\n *\n * Virtualizer uses `Layout` objects to compute what views should be visible, and how\n * to position and style them. This means that virtualizer can have its items arranged in\n * a stack, a grid, a circle, or any other layout you can think of. The layout can be changed\n * dynamically at runtime as well.\n *\n * Layouts produce information on what views should appear in the virtualizer, but do not create the\n * views themselves directly. It is the responsibility of the `VirtualizerDelegate` object to render\n * elements for each layout info. The virtualizer manages a set of `ReusableView` objects, which are\n * reused as the user scrolls by swapping their content with cached elements returned by the\n * delegate.\n */\nexport class Virtualizer<T extends object, V> {\n /**\n * The virtualizer delegate. The delegate is used by the virtualizer\n * to create and configure views.\n */\n delegate: VirtualizerDelegate<T, V>;\n /** The current content of the virtualizer. */\n private _collection: Collection<T>;\n get collection(): Collection<T> {\n return this._collection;\n }\n /** The layout object that determines the visible views. */\n private _layout: Layout<T>;\n get layout(): Layout<T> {\n return this._layout;\n }\n /** The size of the scrollable content. */\n private _contentSize: Size;\n get contentSize(): Size {\n return this._contentSize;\n }\n /** The currently visible rectangle. */\n private _visibleRect: Rect;\n get visibleRect(): Rect {\n return this._visibleRect;\n }\n /** The size of the virtualizer scroll view. */\n private _size: Size;\n get size(): Size {\n return this._size;\n }\n /** The set of persisted keys that are always present in the DOM, even if not currently in view. */\n private _persistedKeys: Set<Key>;\n get persistedKeys(): Set<Key> {\n return this._persistedKeys;\n }\n private readonly _visibleViews: Map<Key, ChildView<T, V>>;\n private readonly _renderedContent: WeakMap<T, V>;\n private readonly _rootView: RootView<T, V>;\n private _isScrolling: boolean;\n private _invalidationContext: InvalidationContext;\n private readonly _overscanManager: OverscanManager;\n private readonly _scrollAnchor: ScrollAnchorTracker;\n constructor(options: VirtualizerOptions<T, V>) {\n this.delegate = options.delegate;\n this._collection = options.collection;\n this._layout = options.layout;\n this._contentSize = new Size();\n this._visibleRect = new Rect();\n this._size = new Size();\n this._persistedKeys = new Set();\n this._visibleViews = new Map();\n this._renderedContent = new WeakMap();\n this._rootView = new RootView(this);\n this._isScrolling = false;\n this._invalidationContext = {};\n this._overscanManager = new OverscanManager();\n this._scrollAnchor = new ScrollAnchorTracker();\n }\n /** Returns whether the given key, or an ancestor, is persisted. */\n isPersistedKey(key: Key): boolean {\n // Quick check if the key is directly in the set of persisted keys.\n if (this.persistedKeys.has(key)) {\n return true;\n }\n\n // If not, check if the key is an ancestor of any of the persisted keys.\n for (let k of this.persistedKeys) {\n while (k !== null && k !== undefined) {\n const layoutInfo = this.layout.getLayoutInfo(k);\n\n if (\n !layoutInfo ||\n layoutInfo.parentKey === null ||\n layoutInfo.parentKey === undefined\n ) {\n break;\n }\n\n k = layoutInfo.parentKey;\n\n if (k === key) {\n return true;\n }\n }\n }\n\n return false;\n }\n private getParentView(\n layoutInfo: LayoutInfo\n ): ReusableView<T, V> | undefined {\n return layoutInfo.parentKey === null || layoutInfo.parentKey === undefined\n ? this._rootView\n : this._visibleViews.get(layoutInfo.parentKey);\n }\n private getReusableView(layoutInfo: LayoutInfo): ChildView<T, V> {\n const parentView = this.getParentView(layoutInfo);\n\n const view = requireValue(\n parentView,\n \"Expected parentView to exist.\"\n ).getReusableView(layoutInfo.type);\n\n view.layoutInfo = layoutInfo;\n this._renderView(view);\n\n return view;\n }\n private _renderView(reusableView: ReusableView<T, V>) {\n if (reusableView.layoutInfo) {\n const { type, key, content } = reusableView.layoutInfo;\n // SAFETY: layouts synthesize content with the attached collection's item type.\n // oxlint-disable-next-line typescript/no-unsafe-type-assertion\n const generatedContent = content as T | null;\n reusableView.content = generatedContent ?? this.collection.getItem(key);\n reusableView.rendered = this._renderContent(type, reusableView.content);\n }\n }\n private _renderContent(type: string, content: T | null) {\n const cached =\n content === null || content === undefined\n ? null\n : this._renderedContent.get(content);\n\n if (cached !== null && cached !== undefined) {\n return cached;\n }\n\n const rendered = this.delegate.renderView(type, content);\n\n if (content) {\n this._renderedContent.set(content, rendered);\n }\n\n return rendered;\n }\n /**\n * Returns the key for the item view currently at the given point.\n */\n keyAtPoint(point: Point): Key | null {\n const rect = new Rect(point.x, point.y, 1, 1);\n\n const layoutInfos =\n rect.area === 0 ? [] : this.layout.getVisibleLayoutInfos(rect);\n\n // Layout may return multiple layout infos in the case of\n // persisted keys, so find the first one that actually intersects.\n for (const layoutInfo of layoutInfos) {\n if (layoutInfo.rect.intersects(rect)) {\n return layoutInfo.key;\n }\n }\n\n return null;\n }\n private relayout(context: InvalidationContext = {}) {\n const anchorInfo =\n this.layout.UNSTABLE_getScrollAnchorInfo?.(context.layoutOptions) ?? null;\n\n // Capture scroll anchor from current (pre-layout) view positions.\n // On first render _visibleViews is empty so no anchor will be found.\n let anchor: ScrollAnchor | null = null;\n\n if (anchorInfo) {\n const preLayoutInfos: [Key, LayoutInfo][] = [];\n\n for (const [key, view] of this._visibleViews) {\n const layoutInfo = this.layout.getLayoutInfo(key) ?? view.layoutInfo;\n\n if (layoutInfo) {\n preLayoutInfos.push([key, layoutInfo]);\n }\n }\n\n anchor = this._scrollAnchor.captureBeforeLayout(\n anchorInfo,\n preLayoutInfos,\n this.visibleRect\n );\n }\n\n const previousContentSize = this.contentSize;\n const previousVisibleRect = this.visibleRect;\n // Update the layout\n this.layout.update(context);\n const rawContentSize = this.layout.getContentSize();\n this._contentSize = new Size(rawContentSize.width, rawContentSize.height);\n\n const target = this._scrollAnchor.resolveAfterLayout({\n anchor,\n anchorInfo,\n contentSize: this.contentSize,\n getLayoutInfo: (key: Key) => this.layout.getLayoutInfo(key),\n isScrolling: this._isScrolling,\n itemSizeChanged: context.itemSizeChanged ?? false,\n postLayoutInfos: anchorInfo\n ? this.getVisibleLayoutInfos()\n : new Map<Key, LayoutInfo>(),\n previousContentSize,\n previousVisibleRect,\n });\n\n if (target) {\n // Queues a new render cycle. Return early to skip updateSubviews — running it now\n // would position views against the old visibleRect, causing a flash before the\n // incoming relayout corrects them.\n this.delegate.setVisibleRect(target);\n\n return;\n }\n\n // Constrain scroll position.\n // If the content changed, scroll to the top.\n const { visibleRect } = this;\n let contentOffsetX = context.contentChanged === true ? 0 : visibleRect.x;\n let contentOffsetY = context.contentChanged === true ? 0 : visibleRect.y;\n contentOffsetX = Math.max(\n 0,\n Math.min(this.contentSize.width - visibleRect.width, contentOffsetX)\n );\n contentOffsetY = Math.max(\n 0,\n Math.min(this.contentSize.height - visibleRect.height, contentOffsetY)\n );\n\n if (contentOffsetX !== visibleRect.x || contentOffsetY !== visibleRect.y) {\n // If the offset changed, trigger a new re-render.\n const rect = new Rect(\n contentOffsetX,\n contentOffsetY,\n visibleRect.width,\n visibleRect.height\n );\n\n this.delegate.setVisibleRect(rect);\n } else {\n this.updateSubviews();\n }\n }\n getVisibleLayoutInfos(): Map<Key, LayoutInfo> {\n const isTestEnv =\n process.env.NODE_ENV === \"test\" &&\n (process.env.VIRT_ON === undefined || process.env.VIRT_ON === \"\");\n\n const isClientWidthMocked =\n isTestEnv &&\n typeof HTMLElement !== \"undefined\" &&\n Object.getOwnPropertyNames(HTMLElement.prototype).includes(\"clientWidth\");\n\n const isClientHeightMocked =\n isTestEnv &&\n typeof HTMLElement !== \"undefined\" &&\n Object.getOwnPropertyNames(HTMLElement.prototype).includes(\n \"clientHeight\"\n );\n\n const rect =\n isTestEnv && (!isClientWidthMocked || !isClientHeightMocked)\n ? new Rect(0, 0, this.contentSize.width, this.contentSize.height)\n : this._overscanManager.getOverscannedRect();\n\n const layoutInfos = this.layout.getVisibleLayoutInfos(rect);\n const map = new Map<Key, LayoutInfo>();\n\n for (const layoutInfo of layoutInfos) {\n map.set(layoutInfo.key, layoutInfo);\n }\n\n return map;\n }\n private updateSubviews() {\n const visibleLayoutInfos = this.getVisibleLayoutInfos();\n const removed = new Set<ChildView<T, V>>();\n\n for (const [key, view] of this._visibleViews) {\n const layoutInfo = visibleLayoutInfos.get(key);\n\n // If a view's parent changed, treat it as a delete and re-create in the new parent.\n if (!layoutInfo || view.parent !== this.getParentView(layoutInfo)) {\n this._visibleViews.delete(key);\n view.parent.reuseChild(view);\n // Defer removing in case we reuse this view.\n removed.add(view);\n }\n }\n\n for (const [key, layoutInfo] of visibleLayoutInfos) {\n let view = this._visibleViews.get(key);\n\n if (view) {\n view.layoutInfo = layoutInfo;\n const item = this.collection.getItem(layoutInfo.key);\n\n if (view.content !== item) {\n if (view.content !== null && view.content !== undefined) {\n this._renderedContent.delete(view.content);\n }\n\n this._renderView(view);\n }\n } else {\n view = this.getReusableView(layoutInfo);\n view.parent.children.add(view);\n this._visibleViews.set(key, view);\n removed.delete(view);\n }\n }\n\n // The remaining views in `removed` were not reused to render new items.\n // They should be removed from the DOM. We also clear the reusable view queue\n // here since there's no point holding onto views that have been removed.\n // Doing so hurts performance in the future when reusing elements due to FIFO order.\n for (const view of removed) {\n view.parent.children.delete(view);\n view.parent.reusableViews.clear();\n }\n\n // Reordering DOM nodes is costly, so we defer this until scrolling stops.\n // DOM order does not affect visual order (due to absolute positioning),\n // but does matter for assistive technology users.\n if (!this._isScrolling) {\n // Layout infos must be in topological order (parents before children).\n for (const key of visibleLayoutInfos.keys()) {\n const view = requireValue(\n this._visibleViews.get(key),\n \"Visible layout keys must have rendered views.\"\n );\n\n view.parent.children.delete(view);\n view.parent.children.add(view);\n }\n }\n }\n /** Performs layout and updates visible views as needed. */\n render(opts: VirtualizerRenderOptions<T>): ReusableView<T, V>[] {\n let needsLayout = false;\n let offsetChanged = false;\n let sizeChanged = false;\n let widthChanged = false;\n let heightChanged = false;\n let itemSizeChanged = false;\n let layoutOptionsChanged = false;\n let needsUpdate = false;\n\n if (opts.collection !== this.collection) {\n this._collection = opts.collection;\n needsLayout = true;\n }\n\n if (opts.layout !== this.layout || this.layout.virtualizer !== this) {\n this.layout.virtualizer = null;\n\n opts.layout.virtualizer = this;\n this._layout = opts.layout;\n this._scrollAnchor.reset();\n needsLayout = true;\n }\n\n if (\n opts.persistedKeys &&\n !isSetEqual(opts.persistedKeys, this.persistedKeys)\n ) {\n this._persistedKeys = opts.persistedKeys;\n needsUpdate = true;\n }\n\n if (\n !this.visibleRect.equals(opts.visibleRect) ||\n !this.size.equals(opts.size)\n ) {\n this._overscanManager.setVisibleRect(opts.visibleRect);\n\n // Create a rectangle using the scroll position and layout size of the scroll view. This is not the same\n // as the visibleRect, whose width and height may change during window scrolling.\n const oldRect = new Rect(\n this.visibleRect.x,\n this.visibleRect.y,\n this.size.width,\n this.size.height\n );\n\n const newRect = new Rect(\n opts.visibleRect.x,\n opts.visibleRect.y,\n opts.size.width,\n opts.size.height\n );\n\n const shouldInvalidate = this.layout.shouldInvalidate(newRect, oldRect);\n\n if (shouldInvalidate) {\n offsetChanged = !opts.visibleRect.pointEquals(this.visibleRect);\n sizeChanged = !this.size.equals(opts.size);\n widthChanged = this.size.width !== opts.size.width;\n heightChanged = this.size.height !== opts.size.height;\n needsLayout = true;\n } else {\n needsUpdate = true;\n }\n\n this._visibleRect = opts.visibleRect;\n this._size = opts.size;\n }\n\n const applyInvalidationContext = () => {\n if (opts.invalidationContext !== this._invalidationContext) {\n sizeChanged ||= opts.invalidationContext.sizeChanged === true;\n widthChanged ||= opts.invalidationContext.widthChanged === true;\n heightChanged ||= opts.invalidationContext.heightChanged === true;\n offsetChanged ||= opts.invalidationContext.offsetChanged === true;\n itemSizeChanged ||= opts.invalidationContext.itemSizeChanged === true;\n layoutOptionsChanged ||=\n opts.invalidationContext.layoutOptions !== null &&\n opts.invalidationContext.layoutOptions !== undefined &&\n this._invalidationContext.layoutOptions !== null &&\n this._invalidationContext.layoutOptions !== undefined &&\n opts.invalidationContext.layoutOptions !==\n this._invalidationContext.layoutOptions &&\n this.layout.shouldInvalidateLayoutOptions(\n opts.invalidationContext.layoutOptions,\n this._invalidationContext.layoutOptions\n );\n needsLayout ||=\n itemSizeChanged ||\n sizeChanged ||\n offsetChanged ||\n layoutOptionsChanged;\n\n this._invalidationContext = opts.invalidationContext;\n }\n };\n\n applyInvalidationContext();\n\n if (opts.isScrolling !== this._isScrolling) {\n this._isScrolling = opts.isScrolling;\n\n if (!opts.isScrolling) {\n // Update to fix the DOM order after scrolling.\n needsUpdate = true;\n }\n }\n\n if (needsLayout) {\n this.relayout({\n heightChanged,\n itemSizeChanged,\n layoutOptions: this._invalidationContext.layoutOptions,\n layoutOptionsChanged,\n offsetChanged,\n sizeChanged,\n widthChanged,\n });\n } else if (needsUpdate) {\n this.updateSubviews();\n }\n\n return [...this._rootView.children];\n }\n getVisibleView(key: Key): ReusableView<T, V> | undefined {\n return this._visibleViews.get(key);\n }\n invalidate(context: InvalidationContext): void {\n this.delegate.invalidate(context);\n }\n updateItemSize(key: Key, size: Size): void {\n if (!this.layout.updateItemSize) {\n return;\n }\n\n const changed = this.layout.updateItemSize(key, size);\n\n if (changed) {\n this.invalidate({\n itemSizeChanged: true,\n });\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4DA,IAAa,cAAb,MAA8C;;;;;CAK5C;;CAEA;CACA,IAAI,aAA4B;EAC9B,OAAO,KAAK;CACd;;CAEA;CACA,IAAI,SAAoB;EACtB,OAAO,KAAK;CACd;;CAEA;CACA,IAAI,cAAoB;EACtB,OAAO,KAAK;CACd;;CAEA;CACA,IAAI,cAAoB;EACtB,OAAO,KAAK;CACd;;CAEA;CACA,IAAI,OAAa;EACf,OAAO,KAAK;CACd;;CAEA;CACA,IAAI,gBAA0B;EAC5B,OAAO,KAAK;CACd;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA,YAAY,SAAmC;EAC7C,KAAK,WAAW,QAAQ;EACxB,KAAK,cAAc,QAA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kBAAkB,KAAK,oBAAoB,kBAAkB;IAC7D,kBAAkB,KAAK,oBAAoB,kBAAkB;IAC7D,oBAAoB,KAAK,oBAAoB,oBAAoB;IACjE,yBACE,KAAK,oBAAoB,kBAAkB,QAC3C,KAAK,oBAAoB,kBAAkB,KAAA,KAC3C,KAAK,qBAAqB,kBAAkB,QAC5C,KAAK,qBAAqB,kBAAkB,KAAA,KAC5C,KAAK,oBAAoB,kBACvB,KAAK,qBAAqB,iBAC5B,KAAK,OAAO,8BACV,KAAK,oBAAoB,eACzB,KAAK,qBAAqB,aAC5B;IACF,gBACE,mBACA,eACA,iBACA;IAEF,KAAK,uBAAuB,KAAK;GACnC;EACF;EAEA,yBAAyB;EAEzB,IAAI,KAAK,gBAAgB,KAAK,cAAc;GAC1C,KAAK,eAAe,KAAK;GAEzB,IAAI,CAAC,KAAK,aAER,cAAc;EAElB;EAEA,IAAI,aACF,KAAK,SAAS;GACZ;GACA;GACA,eAAe,KAAK,qBAAqB;GACzC;GACA;GACA;GACA;EACF,CAAC;OACI,IAAI,aACT,KAAK,eAAe;EAGtB,OAAO,CAAC,GAAG,KAAK,UAAU,QAAQ;CACpC;CACA,eAAe,KAA0C;EACvD,OAAO,KAAK,cAAc,IAAI,GAAG;CACnC;CACA,WAAW,SAAoC;EAC7C,KAAK,SAAS,WAAW,OAAO;CAClC;CACA,eAAe,KAAU,MAAkB;EACzC,IAAI,CAAC,KAAK,OAAO,gBACf;EAKF,IAFgB,KAAK,OAAO,eAAe,KAAK,IAEtC,GACR,KAAK,WAAW,EACd,iBAAiB,KACnB,CAAC;CAEL;AACF"}
1
+ {"version":3,"file":"virtualizer.js","names":["generatedContent"],"sources":["../../src/virtualizer/virtualizer.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n/*\n * Derived from Adobe React Spectrum: packages/react-stately/src/virtualizer/Virtualizer.ts.\n * Modified for Solid Aria: adapted imports, collection descriptors, and reactive state APIs for Solid 2.\n * Licensed under Apache-2.0. See LICENSES/Apache-2.0.txt and NOTICE.txt at the repository root.\n */\n\nimport type { Collection, Key } from \"@solid2-aria/types-shared\";\n\nimport { requireValue } from \"../utils/require-value\";\nimport type { Layout } from \"./layout\";\nimport type { LayoutInfo } from \"./layout-info\";\nimport { OverscanManager } from \"./overscan-manager\";\nimport type { Point } from \"./point\";\nimport { Rect } from \"./rect\";\nimport type { ChildView, ReusableView } from \"./reusable-view\";\nimport { RootView } from \"./reusable-view\";\nimport { ScrollAnchorTracker } from \"./scroll-anchor\";\nimport type { ScrollAnchor } from \"./scroll-anchor\";\nimport { Size } from \"./size\";\nimport type {\n InvalidationContext,\n VirtualizerDelegate,\n VirtualizerRenderOptions,\n} from \"./types\";\nimport { isSetEqual } from \"./utils\";\n\ninterface VirtualizerOptions<T extends object, V> {\n delegate: VirtualizerDelegate<T, V>;\n collection: Collection<T>;\n layout: Layout<T>;\n}\n\n/**\n * The Virtualizer class renders a scrollable collection of data using customizable layouts.\n * It supports very large collections by only rendering visible views to the DOM, reusing\n * them as you scroll. Virtualizer can present any type of view, including non-item views\n * such as section headers and footers.\n *\n * Virtualizer uses `Layout` objects to compute what views should be visible, and how\n * to position and style them. This means that virtualizer can have its items arranged in\n * a stack, a grid, a circle, or any other layout you can think of. The layout can be changed\n * dynamically at runtime as well.\n *\n * Layouts produce information on what views should appear in the virtualizer, but do not create the\n * views themselves directly. It is the responsibility of the `VirtualizerDelegate` object to render\n * elements for each layout info. The virtualizer manages a set of `ReusableView` objects, which are\n * reused as the user scrolls by swapping their content with cached elements returned by the\n * delegate.\n */\nexport class Virtualizer<T extends object, V> {\n /**\n * The virtualizer delegate. The delegate is used by the virtualizer\n * to create and configure views.\n */\n delegate: VirtualizerDelegate<T, V>;\n /** The current content of the virtualizer. */\n private _collection: Collection<T>;\n get collection(): Collection<T> {\n return this._collection;\n }\n /** The layout object that determines the visible views. */\n private _layout: Layout<T>;\n get layout(): Layout<T> {\n return this._layout;\n }\n /** The size of the scrollable content. */\n private _contentSize: Size;\n get contentSize(): Size {\n return this._contentSize;\n }\n /** The currently visible rectangle. */\n private _visibleRect: Rect;\n get visibleRect(): Rect {\n return this._visibleRect;\n }\n /** The size of the virtualizer scroll view. */\n private _size: Size;\n get size(): Size {\n return this._size;\n }\n /** The set of persisted keys that are always present in the DOM, even if not currently in view. */\n private _persistedKeys: Set<Key>;\n get persistedKeys(): Set<Key> {\n return this._persistedKeys;\n }\n private readonly _visibleViews: Map<Key, ChildView<T, V>>;\n private readonly _renderedContent: WeakMap<T, V>;\n private readonly _rootView: RootView<T, V>;\n private _isScrolling: boolean;\n private _invalidationContext: InvalidationContext;\n private readonly _overscanManager: OverscanManager;\n private readonly _scrollAnchor: ScrollAnchorTracker;\n private _hadItemResize = false;\n private _batchIncludedEdgeContent = false;\n constructor(options: VirtualizerOptions<T, V>) {\n this.delegate = options.delegate;\n this._collection = options.collection;\n this._layout = options.layout;\n this._contentSize = new Size();\n this._visibleRect = new Rect();\n this._size = new Size();\n this._persistedKeys = new Set();\n this._visibleViews = new Map();\n this._renderedContent = new WeakMap();\n this._rootView = new RootView(this);\n this._isScrolling = false;\n this._invalidationContext = {};\n this._overscanManager = new OverscanManager();\n this._scrollAnchor = new ScrollAnchorTracker();\n }\n /** Returns whether the given key, or an ancestor, is persisted. */\n isPersistedKey(key: Key): boolean {\n // Quick check if the key is directly in the set of persisted keys.\n if (this.persistedKeys.has(key)) {\n return true;\n }\n\n // If not, check if the key is an ancestor of any of the persisted keys.\n for (let k of this.persistedKeys) {\n while (k !== null && k !== undefined) {\n const layoutInfo = this.layout.getLayoutInfo(k);\n\n if (\n !layoutInfo ||\n layoutInfo.parentKey === null ||\n layoutInfo.parentKey === undefined\n ) {\n break;\n }\n\n k = layoutInfo.parentKey;\n\n if (k === key) {\n return true;\n }\n }\n }\n\n return false;\n }\n private getParentView(\n layoutInfo: LayoutInfo\n ): ReusableView<T, V> | undefined {\n return layoutInfo.parentKey === null || layoutInfo.parentKey === undefined\n ? this._rootView\n : this._visibleViews.get(layoutInfo.parentKey);\n }\n private getReusableView(layoutInfo: LayoutInfo): ChildView<T, V> {\n const parentView = this.getParentView(layoutInfo);\n\n const view = requireValue(\n parentView,\n \"Expected parentView to exist.\"\n ).getReusableView(layoutInfo.type);\n\n view.layoutInfo = layoutInfo;\n this._renderView(view);\n\n return view;\n }\n private _renderView(reusableView: ReusableView<T, V>) {\n if (reusableView.layoutInfo) {\n const { type, key, content } = reusableView.layoutInfo;\n // SAFETY: layouts synthesize content with the attached collection's item type.\n // oxlint-disable-next-line typescript/no-unsafe-type-assertion\n const generatedContent = content as T | null;\n reusableView.content = generatedContent ?? this.collection.getItem(key);\n reusableView.rendered = this._renderContent(type, reusableView.content);\n }\n }\n private _renderContent(type: string, content: T | null) {\n const cached =\n content === null || content === undefined\n ? null\n : this._renderedContent.get(content);\n\n if (cached !== null && cached !== undefined) {\n return cached;\n }\n\n const rendered = this.delegate.renderView(type, content);\n\n if (content) {\n this._renderedContent.set(content, rendered);\n }\n\n return rendered;\n }\n /**\n * Returns the key for the item view currently at the given point.\n */\n keyAtPoint(point: Point): Key | null {\n const rect = new Rect(point.x, point.y, 1, 1);\n\n const layoutInfos =\n rect.area === 0 ? [] : this.layout.getVisibleLayoutInfos(rect);\n\n // Layout may return multiple layout infos in the case of\n // persisted keys, so find the first one that actually intersects.\n for (const layoutInfo of layoutInfos) {\n if (layoutInfo.rect.intersects(rect)) {\n return layoutInfo.key;\n }\n }\n\n return null;\n }\n private relayout(context: InvalidationContext = {}) {\n const anchorInfo =\n this.layout.UNSTABLE_getScrollAnchorInfo?.(context.layoutOptions) ?? null;\n\n // Capture scroll anchor from current (pre-layout) view positions.\n // On first render _visibleViews is empty so no anchor will be found.\n let anchor: ScrollAnchor | null = null;\n\n if (anchorInfo) {\n const preLayoutInfos: [Key, LayoutInfo][] = [];\n\n for (const [key, view] of this._visibleViews) {\n const layoutInfo = this.layout.getLayoutInfo(key) ?? view.layoutInfo;\n\n if (layoutInfo) {\n preLayoutInfos.push([key, layoutInfo]);\n }\n }\n\n anchor = this._scrollAnchor.captureBeforeLayout(\n anchorInfo,\n preLayoutInfos,\n this.visibleRect\n );\n }\n\n const previousContentSize = this.contentSize;\n const previousVisibleRect = this.visibleRect;\n // Update the layout\n this.layout.update(context);\n const rawContentSize = this.layout.getContentSize();\n this._contentSize = new Size(rawContentSize.width, rawContentSize.height);\n\n const target = this._scrollAnchor.resolveAfterLayout({\n anchor,\n anchorInfo,\n changeIsAtEdge: !this._hadItemResize || this._batchIncludedEdgeContent,\n contentSize: this.contentSize,\n getLayoutInfo: (key: Key) => this.layout.getLayoutInfo(key),\n itemSizeChanged: context.itemSizeChanged ?? false,\n previousContentSize,\n previousVisibleRect,\n });\n\n // Resize classification only applies to this layout pass.\n this._hadItemResize = false;\n this._batchIncludedEdgeContent = false;\n\n if (target) {\n // Queues a new render cycle. Return early to skip updateSubviews — running it now\n // would position views against the old visibleRect, causing a flash before the\n // incoming relayout corrects them.\n this.delegate.setVisibleRect(target);\n\n return;\n }\n\n // Constrain scroll position.\n // If the content changed, scroll to the top.\n const { visibleRect } = this;\n let contentOffsetX = context.contentChanged === true ? 0 : visibleRect.x;\n let contentOffsetY = context.contentChanged === true ? 0 : visibleRect.y;\n contentOffsetX = Math.max(\n 0,\n Math.min(this.contentSize.width - visibleRect.width, contentOffsetX)\n );\n contentOffsetY = Math.max(\n 0,\n Math.min(this.contentSize.height - visibleRect.height, contentOffsetY)\n );\n\n if (contentOffsetX !== visibleRect.x || contentOffsetY !== visibleRect.y) {\n // If the offset changed, trigger a new re-render.\n const rect = new Rect(\n contentOffsetX,\n contentOffsetY,\n visibleRect.width,\n visibleRect.height\n );\n\n this.delegate.setVisibleRect(rect);\n } else {\n this.updateSubviews();\n }\n }\n getVisibleLayoutInfos(): Map<Key, LayoutInfo> {\n const isTestEnv =\n process.env.NODE_ENV === \"test\" &&\n (process.env.VIRT_ON === undefined || process.env.VIRT_ON === \"\");\n\n const isClientWidthMocked =\n isTestEnv &&\n typeof HTMLElement !== \"undefined\" &&\n Object.getOwnPropertyNames(HTMLElement.prototype).includes(\"clientWidth\");\n\n const isClientHeightMocked =\n isTestEnv &&\n typeof HTMLElement !== \"undefined\" &&\n Object.getOwnPropertyNames(HTMLElement.prototype).includes(\n \"clientHeight\"\n );\n\n const rect =\n isTestEnv && (!isClientWidthMocked || !isClientHeightMocked)\n ? new Rect(0, 0, this.contentSize.width, this.contentSize.height)\n : this._overscanManager.getOverscannedRect();\n\n const layoutInfos = this.layout.getVisibleLayoutInfos(rect);\n const map = new Map<Key, LayoutInfo>();\n\n for (const layoutInfo of layoutInfos) {\n map.set(layoutInfo.key, layoutInfo);\n }\n\n return map;\n }\n private updateSubviews() {\n const visibleLayoutInfos = this.getVisibleLayoutInfos();\n const removed = new Set<ChildView<T, V>>();\n\n for (const [key, view] of this._visibleViews) {\n const layoutInfo = visibleLayoutInfos.get(key);\n\n // If a view's parent changed, treat it as a delete and re-create in the new parent.\n if (!layoutInfo || view.parent !== this.getParentView(layoutInfo)) {\n this._visibleViews.delete(key);\n view.parent.reuseChild(view);\n // Defer removing in case we reuse this view.\n removed.add(view);\n }\n }\n\n for (const [key, layoutInfo] of visibleLayoutInfos) {\n let view = this._visibleViews.get(key);\n\n if (view) {\n view.layoutInfo = layoutInfo;\n const item = this.collection.getItem(layoutInfo.key);\n\n if (view.content !== item) {\n if (view.content !== null && view.content !== undefined) {\n this._renderedContent.delete(view.content);\n }\n\n this._renderView(view);\n }\n } else {\n view = this.getReusableView(layoutInfo);\n view.parent.children.add(view);\n this._visibleViews.set(key, view);\n removed.delete(view);\n }\n }\n\n // The remaining views in `removed` were not reused to render new items.\n // They should be removed from the DOM. We also clear the reusable view queue\n // here since there's no point holding onto views that have been removed.\n // Doing so hurts performance in the future when reusing elements due to FIFO order.\n for (const view of removed) {\n view.parent.children.delete(view);\n view.parent.reusableViews.clear();\n }\n\n // Reordering DOM nodes is costly, so we defer this until scrolling stops.\n // DOM order does not affect visual order (due to absolute positioning),\n // but does matter for assistive technology users.\n if (!this._isScrolling) {\n // Layout infos must be in topological order (parents before children).\n for (const key of visibleLayoutInfos.keys()) {\n const view = requireValue(\n this._visibleViews.get(key),\n \"Visible layout keys must have rendered views.\"\n );\n\n view.parent.children.delete(view);\n view.parent.children.add(view);\n }\n }\n }\n /** Performs layout and updates visible views as needed. */\n render(opts: VirtualizerRenderOptions<T>): ReusableView<T, V>[] {\n let needsLayout = false;\n let offsetChanged = false;\n let sizeChanged = false;\n let widthChanged = false;\n let heightChanged = false;\n let itemSizeChanged = false;\n let layoutOptionsChanged = false;\n let needsUpdate = false;\n\n if (opts.collection !== this.collection) {\n this._collection = opts.collection;\n needsLayout = true;\n }\n\n if (opts.layout !== this.layout || this.layout.virtualizer !== this) {\n this.layout.virtualizer = null;\n\n opts.layout.virtualizer = this;\n this._layout = opts.layout;\n this._scrollAnchor.reset();\n needsLayout = true;\n }\n\n if (\n opts.persistedKeys &&\n !isSetEqual(opts.persistedKeys, this.persistedKeys)\n ) {\n this._persistedKeys = opts.persistedKeys;\n needsUpdate = true;\n }\n\n if (\n !this.visibleRect.equals(opts.visibleRect) ||\n !this.size.equals(opts.size)\n ) {\n this._overscanManager.setVisibleRect(opts.visibleRect);\n\n // Create a rectangle using the scroll position and layout size of the scroll view. This is not the same\n // as the visibleRect, whose width and height may change during window scrolling.\n const oldRect = new Rect(\n this.visibleRect.x,\n this.visibleRect.y,\n this.size.width,\n this.size.height\n );\n\n const newRect = new Rect(\n opts.visibleRect.x,\n opts.visibleRect.y,\n opts.size.width,\n opts.size.height\n );\n\n const shouldInvalidate = this.layout.shouldInvalidate(newRect, oldRect);\n\n if (shouldInvalidate) {\n offsetChanged = !opts.visibleRect.pointEquals(this.visibleRect);\n sizeChanged = !this.size.equals(opts.size);\n widthChanged = this.size.width !== opts.size.width;\n heightChanged = this.size.height !== opts.size.height;\n needsLayout = true;\n } else {\n needsUpdate = true;\n }\n\n this._visibleRect = opts.visibleRect;\n this._size = opts.size;\n }\n\n const applyInvalidationContext = () => {\n if (opts.invalidationContext !== this._invalidationContext) {\n sizeChanged ||= opts.invalidationContext.sizeChanged === true;\n widthChanged ||= opts.invalidationContext.widthChanged === true;\n heightChanged ||= opts.invalidationContext.heightChanged === true;\n offsetChanged ||= opts.invalidationContext.offsetChanged === true;\n itemSizeChanged ||= opts.invalidationContext.itemSizeChanged === true;\n layoutOptionsChanged ||=\n opts.invalidationContext.layoutOptions !== null &&\n opts.invalidationContext.layoutOptions !== undefined &&\n this._invalidationContext.layoutOptions !== null &&\n this._invalidationContext.layoutOptions !== undefined &&\n opts.invalidationContext.layoutOptions !==\n this._invalidationContext.layoutOptions &&\n this.layout.shouldInvalidateLayoutOptions(\n opts.invalidationContext.layoutOptions,\n this._invalidationContext.layoutOptions\n );\n needsLayout ||=\n itemSizeChanged ||\n sizeChanged ||\n offsetChanged ||\n layoutOptionsChanged;\n\n this._invalidationContext = opts.invalidationContext;\n }\n };\n\n applyInvalidationContext();\n\n if (opts.isScrolling !== this._isScrolling) {\n this._isScrolling = opts.isScrolling;\n\n if (!opts.isScrolling) {\n // Update to fix the DOM order after scrolling.\n needsUpdate = true;\n }\n }\n\n if (needsLayout) {\n this.relayout({\n heightChanged,\n itemSizeChanged,\n layoutOptions: this._invalidationContext.layoutOptions,\n layoutOptionsChanged,\n offsetChanged,\n sizeChanged,\n widthChanged,\n });\n } else if (needsUpdate) {\n this.updateSubviews();\n }\n\n return [...this._rootView.children];\n }\n getVisibleView(key: Key): ReusableView<T, V> | undefined {\n return this._visibleViews.get(key);\n }\n invalidate(context: InvalidationContext): void {\n this.delegate.invalidate(context);\n }\n updateItemSize(key: Key, size: Size): void {\n if (!this.layout.updateItemSize) {\n return;\n }\n\n const changed = this.layout.updateItemSize(key, size);\n\n if (changed) {\n this._hadItemResize = true;\n this._batchIncludedEdgeContent ||= this.isEdgeContent(key);\n this.invalidate({\n itemSizeChanged: true,\n });\n }\n }\n\n private isEdgeContent(key: Key): boolean {\n const anchorInfo = this.layout.UNSTABLE_getScrollAnchorInfo?.(\n this._invalidationContext.layoutOptions\n );\n\n return anchorInfo?.isEdgeContent?.(key) ?? true;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4DA,IAAa,cAAb,MAA8C;;;;;CAK5C;;CAEA;CACA,IAAI,aAA4B;EAC9B,OAAO,KAAK;CACd;;CAEA;CACA,IAAI,SAAoB;EACtB,OAAO,KAAK;CACd;;CAEA;CACA,IAAI,cAAoB;EACtB,OAAO,KAAK;CACd;;CAEA;CACA,IAAI,cAAoB;EACtB,OAAO,KAAK;CACd;;CAEA;CACA,IAAI,OAAa;EACf,OAAO,KAAK;CACd;;CAEA;CACA,IAAI,gBAA0B;EAC5B,OAAO,KAAK;CACd;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA,iBAAyB;CACzB,4BAAoC;CACpC,YAAY,SAAmC;EAC7C,KAAK,WAAW,QAAQ;EACxB,KAAK,cAAc,QAAQ;EAC3B,KAAK,UAAU,QAAQ;EACvB,KAAK,eAAe,IAAI,KAAK;EAC7B,KAAK,eAAe,IAAI,KAAK;EAC7B,KAAK,QAAQ,IAAI,KAAK;EACtB,KAAK,iCAAiB,IAAI,IAAI;EAC9B,KAAK,gCAAgB,IAAI,IAAI;EAC7B,KAAK,mCAAmB,IAAI,QAAQ;EACpC,KAAK,YAAY,IAAI,SAAS,IAAI;EAClC,KAAK,eAAe;EACpB,KAAK,uBAAuB,CAAC;EAC7B,KAAK,mBAAmB,IAAI,gBAAgB;EAC5C,KAAK,gBAAgB,IAAI,oBAAoB;CAC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ACA,eACA,iBACA;IAEF,KAAK,uBAAuB,KAAK;GACnC;EACF;EAEA,yBAAyB;EAEzB,IAAI,KAAK,gBAAgB,KAAK,cAAc;GAC1C,KAAK,eAAe,KAAK;GAEzB,IAAI,CAAC,KAAK,aAER,cAAc;EAElB;EAEA,IAAI,aACF,KAAK,SAAS;GACZ;GACA;GACA,eAAe,KAAK,qBAAqB;GACzC;GACA;GACA;GACA;EACF,CAAC;OACI,IAAI,aACT,KAAK,eAAe;EAGtB,OAAO,CAAC,GAAG,KAAK,UAAU,QAAQ;CACpC;CACA,eAAe,KAA0C;EACvD,OAAO,KAAK,cAAc,IAAI,GAAG;CACnC;CACA,WAAW,SAAoC;EAC7C,KAAK,SAAS,WAAW,OAAO;CAClC;CACA,eAAe,KAAU,MAAkB;EACzC,IAAI,CAAC,KAAK,OAAO,gBACf;EAKF,IAFgB,KAAK,OAAO,eAAe,KAAK,IAEtC,GAAG;GACX,KAAK,iBAAiB;GACtB,KAAK,8BAA8B,KAAK,cAAc,GAAG;GACzD,KAAK,WAAW,EACd,iBAAiB,KACnB,CAAC;EACH;CACF;CAEA,cAAsB,KAAmB;EAKvC,QAJmB,KAAK,OAAO,+BAC7B,KAAK,qBAAqB,aAC5B,EAAA,EAEmB,gBAAgB,GAAG,KAAK;CAC7C;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solid2-aria/stately",
3
- "version": "0.0.1",
3
+ "version": "0.1.0",
4
4
  "private": false,
5
5
  "keywords": [
6
6
  "solid",
@@ -162,15 +162,15 @@
162
162
  "@internationalized/date": "^3.12.4",
163
163
  "@internationalized/number": "^3.6.9",
164
164
  "@internationalized/string": "^3.2.10",
165
- "@solid2-aria/types-shared": "^0.0.1"
165
+ "@solid2-aria/types-shared": "^0.1.0"
166
166
  },
167
167
  "devDependencies": {
168
168
  "@types/bun": "^1.4.4",
169
169
  "tsdown": "^0.23.2",
170
- "tsrs": "^0.20.0-ts7.1.0-beta",
170
+ "tsrs": "^7.1.0-beta.tsrs3",
171
171
  "typescript": "^7.1.0-beta"
172
172
  },
173
173
  "peerDependencies": {
174
- "solid-js": "^2.0.0-rc.17"
174
+ "solid-js": "^2.0.0"
175
175
  }
176
176
  }