@solid2-aria/stately 0.0.0-stage → 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +45 -2
- package/dist/LICENSES/Apache-2.0.txt +201 -0
- package/dist/LICENSES/react-spectrum-NOTICE.txt +242 -0
- package/dist/NOTICE.txt +636 -0
- package/dist/autocomplete/create-autocomplete-state.d.ts +46 -0
- package/dist/autocomplete/create-autocomplete-state.js +41 -0
- package/dist/autocomplete/create-autocomplete-state.js.map +1 -0
- package/dist/calendar/create-calendar-state.d.ts +62 -0
- package/dist/calendar/create-calendar-state.js +357 -0
- package/dist/calendar/create-calendar-state.js.map +1 -0
- package/dist/calendar/create-range-calendar-state.d.ts +63 -0
- package/dist/calendar/create-range-calendar-state.js +204 -0
- package/dist/calendar/create-range-calendar-state.js.map +1 -0
- package/dist/calendar/types.d.ts +222 -0
- package/dist/calendar/types.js +16 -0
- package/dist/calendar/utils.d.ts +27 -0
- package/dist/calendar/utils.js +81 -0
- package/dist/calendar/utils.js.map +1 -0
- package/dist/checkbox/create-checkbox-group-state.d.ts +60 -0
- package/dist/checkbox/create-checkbox-group-state.js +88 -0
- package/dist/checkbox/create-checkbox-group-state.js.map +1 -0
- package/dist/collections/collection-builder.d.ts +28 -0
- package/dist/collections/collection-builder.js +164 -0
- package/dist/collections/collection-builder.js.map +1 -0
- package/dist/collections/create-collection.d.ts +24 -0
- package/dist/collections/create-collection.js +35 -0
- package/dist/collections/create-collection.js.map +1 -0
- package/dist/collections/get-child-nodes.d.ts +25 -0
- package/dist/collections/get-child-nodes.js +67 -0
- package/dist/collections/get-child-nodes.js.map +1 -0
- package/dist/collections/get-item-count.d.ts +19 -0
- package/dist/collections/get-item-count.js +34 -0
- package/dist/collections/get-item-count.js.map +1 -0
- package/dist/collections/item.d.ts +29 -0
- package/dist/collections/item.js +68 -0
- package/dist/collections/item.js.map +1 -0
- package/dist/collections/section.d.ts +29 -0
- package/dist/collections/section.js +60 -0
- package/dist/collections/section.js.map +1 -0
- package/dist/collections/types.d.ts +46 -0
- package/dist/collections/types.js +29 -0
- package/dist/collections/types.js.map +1 -0
- package/dist/color/color/base-color.d.ts +40 -0
- package/dist/color/color/base-color.js +122 -0
- package/dist/color/color/base-color.js.map +1 -0
- package/dist/color/color/color-classes.d.ts +27 -0
- package/dist/color/color/color-classes.js +29 -0
- package/dist/color/color/color-classes.js.map +1 -0
- package/dist/color/color/color-constructors.d.ts +23 -0
- package/dist/color/color/color-constructors.js +16 -0
- package/dist/color/color/color.d.ts +3 -0
- package/dist/color/color/color.js +2 -0
- package/dist/color/color/hsb-color.d.ts +24 -0
- package/dist/color/color/hsb-color.js +183 -0
- package/dist/color/color/hsb-color.js.map +1 -0
- package/dist/color/color/hsl-color.d.ts +24 -0
- package/dist/color/color/hsl-color.js +184 -0
- package/dist/color/color/hsl-color.js.map +1 -0
- package/dist/color/color/normalize-hue.d.ts +18 -0
- package/dist/color/color/normalize-hue.js +24 -0
- package/dist/color/color/normalize-hue.js.map +1 -0
- package/dist/color/color/oklch.d.ts +19 -0
- package/dist/color/color/oklch.js +97 -0
- package/dist/color/color/oklch.js.map +1 -0
- package/dist/color/color/rgb-color.d.ts +24 -0
- package/dist/color/color/rgb-color.js +230 -0
- package/dist/color/color/rgb-color.js.map +1 -0
- package/dist/color/color.d.ts +25 -0
- package/dist/color/color.js +41 -0
- package/dist/color/color.js.map +1 -0
- package/dist/color/create-color-area-state.d.ts +105 -0
- package/dist/color/create-color-area-state.js +138 -0
- package/dist/color/create-color-area-state.js.map +1 -0
- package/dist/color/create-color-channel-field-state.d.ts +29 -0
- package/dist/color/create-color-channel-field-state.js +69 -0
- package/dist/color/create-color-channel-field-state.js.map +1 -0
- package/dist/color/create-color-field-state.d.ts +61 -0
- package/dist/color/create-color-field-state.js +113 -0
- package/dist/color/create-color-field-state.js.map +1 -0
- package/dist/color/create-color-picker-state.d.ts +16 -0
- package/dist/color/create-color-picker-state.js +26 -0
- package/dist/color/create-color-picker-state.js.map +1 -0
- package/dist/color/create-color-slider-state.d.ts +50 -0
- package/dist/color/create-color-slider-state.js +93 -0
- package/dist/color/create-color-slider-state.js.map +1 -0
- package/dist/color/create-color-wheel-state.d.ts +76 -0
- package/dist/color/create-color-wheel-state.js +130 -0
- package/dist/color/create-color-wheel-state.js.map +1 -0
- package/dist/color/create-color.d.ts +20 -0
- package/dist/color/create-color.js +33 -0
- package/dist/color/create-color.js.map +1 -0
- package/dist/color/types.d.ts +87 -0
- package/dist/color/types.js +5 -0
- package/dist/combobox/create-combo-box-state.d.ts +157 -0
- package/dist/combobox/create-combo-box-state.js +450 -0
- package/dist/combobox/create-combo-box-state.js.map +1 -0
- package/dist/data/create-async-list.d.ts +88 -0
- package/dist/data/create-async-list.js +276 -0
- package/dist/data/create-async-list.js.map +1 -0
- package/dist/data/create-list-data.d.ts +140 -0
- package/dist/data/create-list-data.js +250 -0
- package/dist/data/create-list-data.js.map +1 -0
- package/dist/data/create-tree-data.d.ts +134 -0
- package/dist/data/create-tree-data.js +364 -0
- package/dist/data/create-tree-data.js.map +1 -0
- package/dist/datepicker/create-date-field-state.d.ts +138 -0
- package/dist/datepicker/create-date-field-state.js +449 -0
- package/dist/datepicker/create-date-field-state.js.map +1 -0
- package/dist/datepicker/create-date-picker-state.d.ts +82 -0
- package/dist/datepicker/create-date-picker-state.js +191 -0
- package/dist/datepicker/create-date-picker-state.js.map +1 -0
- package/dist/datepicker/create-date-range-picker-state.d.ts +97 -0
- package/dist/datepicker/create-date-range-picker-state.js +305 -0
- package/dist/datepicker/create-date-range-picker-state.js.map +1 -0
- package/dist/datepicker/create-time-field-state.d.ts +34 -0
- package/dist/datepicker/create-time-field-state.js +128 -0
- package/dist/datepicker/create-time-field-state.js.map +1 -0
- package/dist/datepicker/incomplete-date.d.ts +71 -0
- package/dist/datepicker/incomplete-date.js +324 -0
- package/dist/datepicker/incomplete-date.js.map +1 -0
- package/dist/datepicker/placeholders.d.ts +18 -0
- package/dist/datepicker/placeholders.js +418 -0
- package/dist/datepicker/placeholders.js.map +1 -0
- package/dist/datepicker/types.d.ts +131 -0
- package/dist/datepicker/types.js +16 -0
- package/dist/datepicker/utils.d.ts +37 -0
- package/dist/datepicker/utils.js +168 -0
- package/dist/datepicker/utils.js.map +1 -0
- package/dist/disclosure/create-disclosure-group-state.d.ts +47 -0
- package/dist/disclosure/create-disclosure-group-state.js +62 -0
- package/dist/disclosure/create-disclosure-group-state.js.map +1 -0
- package/dist/disclosure/create-disclosure-state.d.ts +42 -0
- package/dist/disclosure/create-disclosure-state.js +49 -0
- package/dist/disclosure/create-disclosure-state.js.map +1 -0
- package/dist/dnd/create-draggable-collection-state.d.ts +63 -0
- package/dist/dnd/create-draggable-collection-state.js +136 -0
- package/dist/dnd/create-draggable-collection-state.js.map +1 -0
- package/dist/dnd/create-droppable-collection-state.d.ts +55 -0
- package/dist/dnd/create-droppable-collection-state.js +155 -0
- package/dist/dnd/create-droppable-collection-state.js.map +1 -0
- package/dist/flags/flags.d.ts +21 -0
- package/dist/flags/flags.js +34 -0
- package/dist/flags/flags.js.map +1 -0
- package/dist/form/create-form-validation-state.d.ts +37 -0
- package/dist/form/create-form-validation-state.js +152 -0
- package/dist/form/create-form-validation-state.js.map +1 -0
- package/dist/grid/create-grid-state.d.ts +38 -0
- package/dist/grid/create-grid-state.js +85 -0
- package/dist/grid/create-grid-state.js.map +1 -0
- package/dist/grid/grid-collection.d.ts +68 -0
- package/dist/grid/grid-collection.js +133 -0
- package/dist/grid/grid-collection.js.map +1 -0
- package/dist/index.d.ts +91 -0
- package/dist/index.js +86 -0
- package/dist/intl/color/ar-AE.js +44 -0
- package/dist/intl/color/ar-AE.js.map +1 -0
- package/dist/intl/color/bg-BG.js +44 -0
- package/dist/intl/color/bg-BG.js.map +1 -0
- package/dist/intl/color/cs-CZ.js +44 -0
- package/dist/intl/color/cs-CZ.js.map +1 -0
- package/dist/intl/color/da-DK.js +44 -0
- package/dist/intl/color/da-DK.js.map +1 -0
- package/dist/intl/color/de-DE.js +44 -0
- package/dist/intl/color/de-DE.js.map +1 -0
- package/dist/intl/color/el-GR.js +44 -0
- package/dist/intl/color/el-GR.js.map +1 -0
- package/dist/intl/color/en-US.js +44 -0
- package/dist/intl/color/en-US.js.map +1 -0
- package/dist/intl/color/es-ES.js +44 -0
- package/dist/intl/color/es-ES.js.map +1 -0
- package/dist/intl/color/et-EE.js +44 -0
- package/dist/intl/color/et-EE.js.map +1 -0
- package/dist/intl/color/fi-FI.js +44 -0
- package/dist/intl/color/fi-FI.js.map +1 -0
- package/dist/intl/color/fr-FR.js +44 -0
- package/dist/intl/color/fr-FR.js.map +1 -0
- package/dist/intl/color/he-IL.js +44 -0
- package/dist/intl/color/he-IL.js.map +1 -0
- package/dist/intl/color/hr-HR.js +44 -0
- package/dist/intl/color/hr-HR.js.map +1 -0
- package/dist/intl/color/hu-HU.js +44 -0
- package/dist/intl/color/hu-HU.js.map +1 -0
- package/dist/intl/color/index.js +75 -0
- package/dist/intl/color/index.js.map +1 -0
- package/dist/intl/color/it-IT.js +44 -0
- package/dist/intl/color/it-IT.js.map +1 -0
- package/dist/intl/color/ja-JP.js +44 -0
- package/dist/intl/color/ja-JP.js.map +1 -0
- package/dist/intl/color/ko-KR.js +44 -0
- package/dist/intl/color/ko-KR.js.map +1 -0
- package/dist/intl/color/lt-LT.js +44 -0
- package/dist/intl/color/lt-LT.js.map +1 -0
- package/dist/intl/color/lv-LV.js +44 -0
- package/dist/intl/color/lv-LV.js.map +1 -0
- package/dist/intl/color/nb-NO.js +44 -0
- package/dist/intl/color/nb-NO.js.map +1 -0
- package/dist/intl/color/nl-NL.js +44 -0
- package/dist/intl/color/nl-NL.js.map +1 -0
- package/dist/intl/color/pl-PL.js +44 -0
- package/dist/intl/color/pl-PL.js.map +1 -0
- package/dist/intl/color/pt-BR.js +44 -0
- package/dist/intl/color/pt-BR.js.map +1 -0
- package/dist/intl/color/pt-PT.js +44 -0
- package/dist/intl/color/pt-PT.js.map +1 -0
- package/dist/intl/color/ro-RO.js +44 -0
- package/dist/intl/color/ro-RO.js.map +1 -0
- package/dist/intl/color/ru-RU.js +44 -0
- package/dist/intl/color/ru-RU.js.map +1 -0
- package/dist/intl/color/sk-SK.js +44 -0
- package/dist/intl/color/sk-SK.js.map +1 -0
- package/dist/intl/color/sl-SI.js +44 -0
- package/dist/intl/color/sl-SI.js.map +1 -0
- package/dist/intl/color/sr-SP.js +44 -0
- package/dist/intl/color/sr-SP.js.map +1 -0
- package/dist/intl/color/sv-SE.js +44 -0
- package/dist/intl/color/sv-SE.js.map +1 -0
- package/dist/intl/color/tr-TR.js +44 -0
- package/dist/intl/color/tr-TR.js.map +1 -0
- package/dist/intl/color/uk-UA.js +44 -0
- package/dist/intl/color/uk-UA.js.map +1 -0
- package/dist/intl/color/zh-CN.js +44 -0
- package/dist/intl/color/zh-CN.js.map +1 -0
- package/dist/intl/color/zh-TW.js +44 -0
- package/dist/intl/color/zh-TW.js.map +1 -0
- package/dist/intl/datepicker/ar-AE.js +11 -0
- package/dist/intl/datepicker/ar-AE.js.map +1 -0
- package/dist/intl/datepicker/bg-BG.js +11 -0
- package/dist/intl/datepicker/bg-BG.js.map +1 -0
- package/dist/intl/datepicker/cs-CZ.js +11 -0
- package/dist/intl/datepicker/cs-CZ.js.map +1 -0
- package/dist/intl/datepicker/da-DK.js +11 -0
- package/dist/intl/datepicker/da-DK.js.map +1 -0
- package/dist/intl/datepicker/de-DE.js +11 -0
- package/dist/intl/datepicker/de-DE.js.map +1 -0
- package/dist/intl/datepicker/el-GR.js +11 -0
- package/dist/intl/datepicker/el-GR.js.map +1 -0
- package/dist/intl/datepicker/en-US.js +11 -0
- package/dist/intl/datepicker/en-US.js.map +1 -0
- package/dist/intl/datepicker/es-ES.js +11 -0
- package/dist/intl/datepicker/es-ES.js.map +1 -0
- package/dist/intl/datepicker/et-EE.js +11 -0
- package/dist/intl/datepicker/et-EE.js.map +1 -0
- package/dist/intl/datepicker/fi-FI.js +11 -0
- package/dist/intl/datepicker/fi-FI.js.map +1 -0
- package/dist/intl/datepicker/fr-FR.js +11 -0
- package/dist/intl/datepicker/fr-FR.js.map +1 -0
- package/dist/intl/datepicker/he-IL.js +11 -0
- package/dist/intl/datepicker/he-IL.js.map +1 -0
- package/dist/intl/datepicker/hr-HR.js +11 -0
- package/dist/intl/datepicker/hr-HR.js.map +1 -0
- package/dist/intl/datepicker/hu-HU.js +11 -0
- package/dist/intl/datepicker/hu-HU.js.map +1 -0
- package/dist/intl/datepicker/index.js +75 -0
- package/dist/intl/datepicker/index.js.map +1 -0
- package/dist/intl/datepicker/it-IT.js +11 -0
- package/dist/intl/datepicker/it-IT.js.map +1 -0
- package/dist/intl/datepicker/ja-JP.js +11 -0
- package/dist/intl/datepicker/ja-JP.js.map +1 -0
- package/dist/intl/datepicker/ko-KR.js +11 -0
- package/dist/intl/datepicker/ko-KR.js.map +1 -0
- package/dist/intl/datepicker/lt-LT.js +11 -0
- package/dist/intl/datepicker/lt-LT.js.map +1 -0
- package/dist/intl/datepicker/lv-LV.js +11 -0
- package/dist/intl/datepicker/lv-LV.js.map +1 -0
- package/dist/intl/datepicker/nb-NO.js +11 -0
- package/dist/intl/datepicker/nb-NO.js.map +1 -0
- package/dist/intl/datepicker/nl-NL.js +11 -0
- package/dist/intl/datepicker/nl-NL.js.map +1 -0
- package/dist/intl/datepicker/pl-PL.js +11 -0
- package/dist/intl/datepicker/pl-PL.js.map +1 -0
- package/dist/intl/datepicker/pt-BR.js +11 -0
- package/dist/intl/datepicker/pt-BR.js.map +1 -0
- package/dist/intl/datepicker/pt-PT.js +11 -0
- package/dist/intl/datepicker/pt-PT.js.map +1 -0
- package/dist/intl/datepicker/ro-RO.js +11 -0
- package/dist/intl/datepicker/ro-RO.js.map +1 -0
- package/dist/intl/datepicker/ru-RU.js +11 -0
- package/dist/intl/datepicker/ru-RU.js.map +1 -0
- package/dist/intl/datepicker/sk-SK.js +11 -0
- package/dist/intl/datepicker/sk-SK.js.map +1 -0
- package/dist/intl/datepicker/sl-SI.js +11 -0
- package/dist/intl/datepicker/sl-SI.js.map +1 -0
- package/dist/intl/datepicker/sr-SP.js +11 -0
- package/dist/intl/datepicker/sr-SP.js.map +1 -0
- package/dist/intl/datepicker/sv-SE.js +11 -0
- package/dist/intl/datepicker/sv-SE.js.map +1 -0
- package/dist/intl/datepicker/tr-TR.js +11 -0
- package/dist/intl/datepicker/tr-TR.js.map +1 -0
- package/dist/intl/datepicker/uk-UA.js +11 -0
- package/dist/intl/datepicker/uk-UA.js.map +1 -0
- package/dist/intl/datepicker/zh-CN.js +11 -0
- package/dist/intl/datepicker/zh-CN.js.map +1 -0
- package/dist/intl/datepicker/zh-TW.js +11 -0
- package/dist/intl/datepicker/zh-TW.js.map +1 -0
- package/dist/layout/grid-layout.d.ts +107 -0
- package/dist/layout/grid-layout.js +253 -0
- package/dist/layout/grid-layout.js.map +1 -0
- package/dist/layout/list-layout.d.ts +187 -0
- package/dist/layout/list-layout.js +488 -0
- package/dist/layout/list-layout.js.map +1 -0
- package/dist/layout/table-layout.d.ts +98 -0
- package/dist/layout/table-layout.js +476 -0
- package/dist/layout/table-layout.js.map +1 -0
- package/dist/layout/waterfall-layout.d.ts +85 -0
- package/dist/layout/waterfall-layout.js +225 -0
- package/dist/layout/waterfall-layout.js.map +1 -0
- package/dist/list/create-list-state.d.ts +48 -0
- package/dist/list/create-list-state.js +123 -0
- package/dist/list/create-list-state.js.map +1 -0
- package/dist/list/create-single-select-list-state.d.ts +38 -0
- package/dist/list/create-single-select-list-state.js +55 -0
- package/dist/list/create-single-select-list-state.js.map +1 -0
- package/dist/list/list-collection.d.ts +36 -0
- package/dist/list/list-collection.js +91 -0
- package/dist/list/list-collection.js.map +1 -0
- package/dist/menu/create-menu-trigger-state.d.ts +55 -0
- package/dist/menu/create-menu-trigger-state.js +58 -0
- package/dist/menu/create-menu-trigger-state.js.map +1 -0
- package/dist/menu/create-submenu-trigger-state.d.ts +47 -0
- package/dist/menu/create-submenu-trigger-state.js +59 -0
- package/dist/menu/create-submenu-trigger-state.js.map +1 -0
- package/dist/numberfield/create-number-field-state.d.ts +93 -0
- package/dist/numberfield/create-number-field-state.js +139 -0
- package/dist/numberfield/create-number-field-state.js.map +1 -0
- package/dist/overlays/create-overlay-trigger-state.d.ts +51 -0
- package/dist/overlays/create-overlay-trigger-state.js +56 -0
- package/dist/overlays/create-overlay-trigger-state.js.map +1 -0
- package/dist/radio/create-radio-group-state.d.ts +61 -0
- package/dist/radio/create-radio-group-state.js +71 -0
- package/dist/radio/create-radio-group-state.js.map +1 -0
- package/dist/searchfield/create-search-field-state.d.ts +35 -0
- package/dist/searchfield/create-search-field-state.js +34 -0
- package/dist/searchfield/create-search-field-state.js.map +1 -0
- package/dist/select/create-select-state.d.ts +116 -0
- package/dist/select/create-select-state.js +151 -0
- package/dist/select/create-select-state.js.map +1 -0
- package/dist/selection/create-multiple-selection-state.d.ts +39 -0
- package/dist/selection/create-multiple-selection-state.js +114 -0
- package/dist/selection/create-multiple-selection-state.js.map +1 -0
- package/dist/selection/selection-manager.d.ts +139 -0
- package/dist/selection/selection-manager.js +334 -0
- package/dist/selection/selection-manager.js.map +1 -0
- package/dist/selection/selection.d.ts +27 -0
- package/dist/selection/selection.js +38 -0
- package/dist/selection/selection.js.map +1 -0
- package/dist/selection/types.d.ts +116 -0
- package/dist/selection/types.js +16 -0
- package/dist/slider/create-slider-state.d.ts +182 -0
- package/dist/slider/create-slider-state.js +131 -0
- package/dist/slider/create-slider-state.js.map +1 -0
- package/dist/steplist/create-step-list-state.d.ts +40 -0
- package/dist/steplist/create-step-list-state.js +132 -0
- package/dist/steplist/create-step-list-state.js.map +1 -0
- package/dist/table/cell.d.ts +37 -0
- package/dist/table/cell.js +47 -0
- package/dist/table/cell.js.map +1 -0
- package/dist/table/collection-context.d.ts +4 -0
- package/dist/table/collection-context.js +8 -0
- package/dist/table/collection-context.js.map +1 -0
- package/dist/table/column.d.ts +66 -0
- package/dist/table/column.js +71 -0
- package/dist/table/column.js.map +1 -0
- package/dist/table/create-table-column-resize-state.d.ts +65 -0
- package/dist/table/create-table-column-resize-state.js +100 -0
- package/dist/table/create-table-column-resize-state.js.map +1 -0
- package/dist/table/create-table-state.d.ts +112 -0
- package/dist/table/create-table-state.js +122 -0
- package/dist/table/create-table-state.js.map +1 -0
- package/dist/table/create-tree-grid-state.d.ts +44 -0
- package/dist/table/create-tree-grid-state.js +145 -0
- package/dist/table/create-tree-grid-state.js.map +1 -0
- package/dist/table/row.d.ts +44 -0
- package/dist/table/row.js +91 -0
- package/dist/table/row.js.map +1 -0
- package/dist/table/table-body.d.ts +36 -0
- package/dist/table/table-body.js +57 -0
- package/dist/table/table-body.js.map +1 -0
- package/dist/table/table-collection.d.ts +62 -0
- package/dist/table/table-collection.js +274 -0
- package/dist/table/table-collection.js.map +1 -0
- package/dist/table/table-column-layout.d.ts +47 -0
- package/dist/table/table-column-layout.js +94 -0
- package/dist/table/table-column-layout.js.map +1 -0
- package/dist/table/table-header.d.ts +37 -0
- package/dist/table/table-header.js +52 -0
- package/dist/table/table-header.js.map +1 -0
- package/dist/table/table-utils.d.ts +60 -0
- package/dist/table/table-utils.js +203 -0
- package/dist/table/table-utils.js.map +1 -0
- package/dist/tabs/create-tab-list-state.d.ts +42 -0
- package/dist/tabs/create-tab-list-state.js +78 -0
- package/dist/tabs/create-tab-list-state.js.map +1 -0
- package/dist/toast/create-toast-state.d.ts +97 -0
- package/dist/toast/create-toast-state.js +166 -0
- package/dist/toast/create-toast-state.js.map +1 -0
- package/dist/toggle/create-toggle-group-state.d.ts +55 -0
- package/dist/toggle/create-toggle-group-state.js +62 -0
- package/dist/toggle/create-toggle-group-state.js.map +1 -0
- package/dist/toggle/create-toggle-state.d.ts +58 -0
- package/dist/toggle/create-toggle-state.js +43 -0
- package/dist/toggle/create-toggle-state.js.map +1 -0
- package/dist/tokenfield/create-token-field-state.d.ts +39 -0
- package/dist/tokenfield/create-token-field-state.js +44 -0
- package/dist/tokenfield/create-token-field-state.js.map +1 -0
- package/dist/tokenfield/token-field-value.d.ts +111 -0
- package/dist/tokenfield/token-field-value.js +327 -0
- package/dist/tokenfield/token-field-value.js.map +1 -0
- package/dist/tooltip/create-tooltip-trigger-state.d.ts +73 -0
- package/dist/tooltip/create-tooltip-trigger-state.js +136 -0
- package/dist/tooltip/create-tooltip-trigger-state.js.map +1 -0
- package/dist/tree/create-tree-state.d.ts +42 -0
- package/dist/tree/create-tree-state.js +75 -0
- package/dist/tree/create-tree-state.js.map +1 -0
- package/dist/tree/tree-collection.d.ts +36 -0
- package/dist/tree/tree-collection.js +84 -0
- package/dist/tree/tree-collection.js.map +1 -0
- package/dist/utils/create-controlled-signal.d.ts +23 -0
- package/dist/utils/create-controlled-signal.js +54 -0
- package/dist/utils/create-controlled-signal.js.map +1 -0
- package/dist/utils/get-item-key.d.ts +5 -0
- package/dist/utils/get-item-key.js +12 -0
- package/dist/utils/get-item-key.js.map +1 -0
- package/dist/utils/get-node-props.d.ts +23 -0
- package/dist/utils/get-node-props.js +38 -0
- package/dist/utils/get-node-props.js.map +1 -0
- package/dist/utils/has-content.d.ts +5 -0
- package/dist/utils/has-content.js +7 -0
- package/dist/utils/has-content.js.map +1 -0
- package/dist/utils/legacy-props.d.ts +10 -0
- package/dist/utils/legacy-props.js +17 -0
- package/dist/utils/legacy-props.js.map +1 -0
- package/dist/utils/number.d.ts +25 -0
- package/dist/utils/number.js +59 -0
- package/dist/utils/number.js.map +1 -0
- package/dist/utils/parse-calendar-identifier.d.ts +5 -0
- package/dist/utils/parse-calendar-identifier.js +31 -0
- package/dist/utils/parse-calendar-identifier.js.map +1 -0
- package/dist/utils/require-value.d.ts +4 -0
- package/dist/utils/require-value.js +10 -0
- package/dist/utils/require-value.js.map +1 -0
- package/dist/virtualizer/create-virtualizer-state.d.ts +44 -0
- package/dist/virtualizer/create-virtualizer-state.js +92 -0
- package/dist/virtualizer/create-virtualizer-state.js.map +1 -0
- package/dist/virtualizer/layout-info.d.ts +94 -0
- package/dist/virtualizer/layout-info.js +118 -0
- package/dist/virtualizer/layout-info.js.map +1 -0
- package/dist/virtualizer/layout.d.ts +91 -0
- package/dist/virtualizer/layout.js +71 -0
- package/dist/virtualizer/layout.js.map +1 -0
- package/dist/virtualizer/overscan-manager.d.ts +25 -0
- package/dist/virtualizer/overscan-manager.js +46 -0
- package/dist/virtualizer/overscan-manager.js.map +1 -0
- package/dist/virtualizer/point.d.ts +36 -0
- package/dist/virtualizer/point.js +48 -0
- package/dist/virtualizer/point.js.map +1 -0
- package/dist/virtualizer/rect.d.ts +103 -0
- package/dist/virtualizer/rect.js +156 -0
- package/dist/virtualizer/rect.js.map +1 -0
- package/dist/virtualizer/reusable-view.d.ts +51 -0
- package/dist/virtualizer/reusable-view.js +81 -0
- package/dist/virtualizer/reusable-view.js.map +1 -0
- package/dist/virtualizer/scroll-anchor.d.ts +98 -0
- package/dist/virtualizer/scroll-anchor.js +150 -0
- package/dist/virtualizer/scroll-anchor.js.map +1 -0
- package/dist/virtualizer/size.d.ts +34 -0
- package/dist/virtualizer/size.js +46 -0
- package/dist/virtualizer/size.js.map +1 -0
- package/dist/virtualizer/types.d.ts +47 -0
- package/dist/virtualizer/types.js +16 -0
- package/dist/virtualizer/utils.d.ts +19 -0
- package/dist/virtualizer/utils.js +27 -0
- package/dist/virtualizer/utils.js.map +1 -0
- package/dist/virtualizer/virtualizer.d.ts +99 -0
- package/dist/virtualizer/virtualizer.js +314 -0
- package/dist/virtualizer/virtualizer.js.map +1 -0
- package/package.json +174 -4
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2022 Adobe. All rights reserved.
|
|
3
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
*
|
|
7
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
* governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
/*
|
|
13
|
+
* Derived from Adobe React Spectrum: packages/react-stately/src/table/TableUtils.ts.
|
|
14
|
+
* Modified for Solid Aria: adapted imports, collection descriptors, and reactive state APIs for Solid 2.
|
|
15
|
+
* Licensed under Apache-2.0. See LICENSES/Apache-2.0.txt and NOTICE.txt at the repository root.
|
|
16
|
+
*/
|
|
17
|
+
import { requireValue } from "../utils/require-value.js";
|
|
18
|
+
// src/table/table-utils.ts
|
|
19
|
+
function isStatic(width) {
|
|
20
|
+
return width !== null && width !== void 0 && (!Number.isNaN(Number(width)) || /^(?<amount>\d+)(?=%$)/u.exec(String(width)) !== null);
|
|
21
|
+
}
|
|
22
|
+
function parseFractionalUnit(width) {
|
|
23
|
+
if (width === null || width === void 0 || width === "" || typeof width === "number") return 1;
|
|
24
|
+
const match = /^(?<amount>.+)(?=fr$)/u.exec(width);
|
|
25
|
+
if (!match) {
|
|
26
|
+
if (process.env.NODE_ENV !== "production") console.warn(`width: ${width} is not a supported format, width should be a number (ex. 150), percentage (ex. '50%') or fr unit (ex. '2fr')`, "defaulting to '1fr'");
|
|
27
|
+
return 1;
|
|
28
|
+
}
|
|
29
|
+
return Number(match[0]);
|
|
30
|
+
}
|
|
31
|
+
function parseStaticWidth(width, tableWidth) {
|
|
32
|
+
if (typeof width === "string") {
|
|
33
|
+
const match = /^(?<amount>\d+)(?=%$)/u.exec(width);
|
|
34
|
+
if (!match) throw new Error("Only percentages or numbers are supported for static column widths");
|
|
35
|
+
return tableWidth * (Number(match[0]) / 100);
|
|
36
|
+
}
|
|
37
|
+
return width;
|
|
38
|
+
}
|
|
39
|
+
function getMaxWidth(maxWidth, tableWidth) {
|
|
40
|
+
return maxWidth === null || maxWidth === void 0 ? Number.MAX_SAFE_INTEGER : parseStaticWidth(maxWidth, tableWidth);
|
|
41
|
+
}
|
|
42
|
+
function getMinWidth(minWidth, tableWidth) {
|
|
43
|
+
return minWidth === null || minWidth === void 0 ? 0 : parseStaticWidth(minWidth, tableWidth);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Implements the flex algorithm described in https://www.w3.org/TR/css-flexbox-1/#layout-algorithm
|
|
47
|
+
* It makes a few constraint/assumptions: 1. All basis values are 0 unless it is a static width,
|
|
48
|
+
* then the basis is the static width 2. All flex grow and shrink values are equal to the FR
|
|
49
|
+
* specified on the column, grow and shrink for the same column are equal 3. We only have one row An
|
|
50
|
+
* example of the setup can be seen here https://jsfiddle.net/snowystinger/wv0ymjaf/61/ where I let
|
|
51
|
+
* the browser figure out the flex of the columns. Note: We differ in one key aspect, all of our
|
|
52
|
+
* column widths must be whole numbers, so we avoid browser sub pixel rounding errors. To do this,
|
|
53
|
+
* we use a cascading rounding algorithm to ensure that the sum of the widths is maintained while
|
|
54
|
+
* distributing the rounding remainder across the columns.
|
|
55
|
+
*
|
|
56
|
+
* As noted in the chrome source code, this algorithm is very accurate, but has the potential to be
|
|
57
|
+
* quadratic. They have deemed this to be acceptable because the number of elements is usually small
|
|
58
|
+
* and the flex factors are usually not high variance. I believe we can make the same assumptions.
|
|
59
|
+
* Particularly once resizing is started, it will convert all columns to the left to static widths,
|
|
60
|
+
* so it will cut down on the number of FR columns.
|
|
61
|
+
*
|
|
62
|
+
* There are likely faster ways to do this, I've chosen to stick to the spec as closely as possible
|
|
63
|
+
* for readability, accuracy, and for the note that this behaving quadratically is unlikely to be a
|
|
64
|
+
* problem.
|
|
65
|
+
*
|
|
66
|
+
* @param availableWidth - The visible width of the table.
|
|
67
|
+
* @param columns - The table defined columns.
|
|
68
|
+
* @param changedColumns - Any columns we want to override, for example, during resizing.
|
|
69
|
+
* @param getDefaultWidth - A function that returns the default width of a column by its index.
|
|
70
|
+
* @param getDefaultMinWidth - A function that returns the default min width of a column by its
|
|
71
|
+
* index.
|
|
72
|
+
*/
|
|
73
|
+
function calculateColumnSizes(initialAvailableWidth, columns, changedColumns, getDefaultWidth, getDefaultMinWidth) {
|
|
74
|
+
let availableWidth = initialAvailableWidth;
|
|
75
|
+
const originalWidth = availableWidth;
|
|
76
|
+
const flooredWidth = Math.floor(availableWidth);
|
|
77
|
+
const hasFractionalWidth = availableWidth - flooredWidth > 0;
|
|
78
|
+
availableWidth = flooredWidth;
|
|
79
|
+
let hasNonFrozenItems = false;
|
|
80
|
+
const flexItems = columns.map((column, index) => {
|
|
81
|
+
const width = changedColumns.get(column.key) === null || changedColumns.get(column.key) === void 0 ? column.width ?? column.defaultWidth ?? getDefaultWidth?.(index) ?? "1fr" : changedColumns.get(column.key) ?? "1fr";
|
|
82
|
+
let frozen = false;
|
|
83
|
+
let baseSize = 0;
|
|
84
|
+
let flex = 0;
|
|
85
|
+
let targetMainSize = 0;
|
|
86
|
+
if (isStatic(width)) {
|
|
87
|
+
baseSize = parseStaticWidth(width, availableWidth);
|
|
88
|
+
frozen = true;
|
|
89
|
+
} else {
|
|
90
|
+
flex = parseFractionalUnit(width);
|
|
91
|
+
if (flex <= 0) frozen = true;
|
|
92
|
+
}
|
|
93
|
+
const min = getMinWidth(column.minWidth ?? getDefaultMinWidth?.(index) ?? 0, availableWidth);
|
|
94
|
+
const max = getMaxWidth(column.maxWidth, availableWidth);
|
|
95
|
+
const hypotheticalMainSize = Math.max(min, Math.min(baseSize, max));
|
|
96
|
+
if (frozen) targetMainSize = hypotheticalMainSize;
|
|
97
|
+
else if (baseSize > hypotheticalMainSize) {
|
|
98
|
+
frozen = true;
|
|
99
|
+
targetMainSize = hypotheticalMainSize;
|
|
100
|
+
}
|
|
101
|
+
if (!frozen) hasNonFrozenItems = true;
|
|
102
|
+
return {
|
|
103
|
+
baseSize,
|
|
104
|
+
flex,
|
|
105
|
+
frozen,
|
|
106
|
+
hypotheticalMainSize,
|
|
107
|
+
max,
|
|
108
|
+
min,
|
|
109
|
+
targetMainSize,
|
|
110
|
+
violation: 0
|
|
111
|
+
};
|
|
112
|
+
});
|
|
113
|
+
while (hasNonFrozenItems) {
|
|
114
|
+
/**
|
|
115
|
+
* Calculate the remaining free space as for initial free space,
|
|
116
|
+
* above (9.7.3). If the sum of the unfrozen flex items’ flex factors is
|
|
117
|
+
* less than one, multiply the initial free space by this sum (of flex factors).
|
|
118
|
+
* If the magnitude of this value is less than the magnitude of
|
|
119
|
+
* the remaining free space, use this as the remaining free space.
|
|
120
|
+
*/
|
|
121
|
+
let usedWidth = 0;
|
|
122
|
+
let flexFactors = 0;
|
|
123
|
+
for (const item of flexItems) if (item.frozen) usedWidth += item.targetMainSize;
|
|
124
|
+
else {
|
|
125
|
+
usedWidth += item.baseSize;
|
|
126
|
+
flexFactors += item.flex;
|
|
127
|
+
}
|
|
128
|
+
const remainingFreeSpace = availableWidth - usedWidth;
|
|
129
|
+
/**
|
|
130
|
+
* If the remaining free space is zero
|
|
131
|
+
* - Do nothing.
|
|
132
|
+
* Else // remember, we're always in grow mode
|
|
133
|
+
* - Find the ratio of the item’s flex grow factor to the
|
|
134
|
+
* sum of the flex grow factors of all unfrozen items on
|
|
135
|
+
* the line. Set the item’s target main size to its flex
|
|
136
|
+
* base size plus a fraction of the remaining free space
|
|
137
|
+
* proportional to the ratio.
|
|
138
|
+
*/
|
|
139
|
+
if (remainingFreeSpace > 0) {
|
|
140
|
+
for (const item of flexItems) if (!item.frozen) {
|
|
141
|
+
const ratio = item.flex / flexFactors;
|
|
142
|
+
item.targetMainSize = item.baseSize + ratio * remainingFreeSpace;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Fix min/max violations. Clamp each non-frozen item’s
|
|
147
|
+
* target main size by its used min and max main sizes
|
|
148
|
+
* and floor its content-box size at zero. If the item’s
|
|
149
|
+
* target main size was made smaller by this, it’s a max
|
|
150
|
+
* violation. If the item’s target main size was made
|
|
151
|
+
* larger by this, it’s a min violation.
|
|
152
|
+
*/
|
|
153
|
+
let totalViolation = 0;
|
|
154
|
+
for (const item of flexItems) {
|
|
155
|
+
item.violation = 0;
|
|
156
|
+
if (!item.frozen) {
|
|
157
|
+
const { min, max, targetMainSize } = item;
|
|
158
|
+
item.targetMainSize = Math.max(min, Math.min(targetMainSize, max));
|
|
159
|
+
item.violation = item.targetMainSize - targetMainSize;
|
|
160
|
+
totalViolation += item.violation;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Freeze over-flexed items. The total violation is the
|
|
165
|
+
* sum of the adjustments from the previous step
|
|
166
|
+
* ∑(clamped size - unclamped size). If the total violation is:
|
|
167
|
+
* Zero
|
|
168
|
+
* - Freeze all items.
|
|
169
|
+
*
|
|
170
|
+
* Positive
|
|
171
|
+
* - Freeze all the items with min violations.
|
|
172
|
+
*
|
|
173
|
+
* Negative
|
|
174
|
+
* - Freeze all the items with max violations.
|
|
175
|
+
*/
|
|
176
|
+
hasNonFrozenItems = false;
|
|
177
|
+
for (const item of flexItems) if (totalViolation === 0 || Math.sign(totalViolation) === Math.sign(item.violation)) item.frozen = true;
|
|
178
|
+
else if (!item.frozen) hasNonFrozenItems = true;
|
|
179
|
+
}
|
|
180
|
+
const columnSizes = cascadeRounding(flexItems);
|
|
181
|
+
if (hasFractionalWidth && columnSizes.length > 0) {
|
|
182
|
+
const [, tableFractionalWidth] = originalWidth.toString().split(".");
|
|
183
|
+
const columnWidth = requireValue(columnSizes.at(-1), "Expected columnSizes.at(-1) to exist.").toString();
|
|
184
|
+
columnSizes[columnSizes.length - 1] = Number(`${columnWidth}.${tableFractionalWidth}`);
|
|
185
|
+
}
|
|
186
|
+
return columnSizes;
|
|
187
|
+
}
|
|
188
|
+
function cascadeRounding(flexItems) {
|
|
189
|
+
let fpTotal = 0;
|
|
190
|
+
let intTotal = 0;
|
|
191
|
+
const roundedArray = [];
|
|
192
|
+
for (const item of flexItems) {
|
|
193
|
+
const float = item.targetMainSize;
|
|
194
|
+
const integer = Math.round(float + fpTotal) - intTotal;
|
|
195
|
+
fpTotal += float;
|
|
196
|
+
intTotal += integer;
|
|
197
|
+
roundedArray.push(integer);
|
|
198
|
+
}
|
|
199
|
+
return roundedArray;
|
|
200
|
+
}
|
|
201
|
+
export { calculateColumnSizes, getMaxWidth, getMinWidth, isStatic, parseFractionalUnit, parseStaticWidth };
|
|
202
|
+
|
|
203
|
+
//# sourceMappingURL=table-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"table-utils.js","names":[],"sources":["../../src/table/table-utils.ts"],"sourcesContent":["/*\n * Copyright 2022 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/table/TableUtils.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 { requireValue } from \"../utils/require-value\";\nimport type { ColumnSize } from \"./column\";\n\n// numbers and percents are considered static. *fr units or a lack of units are considered dynamic.\nexport function isStatic(width?: string | number | null): boolean {\n return (\n width !== null &&\n width !== undefined &&\n (!Number.isNaN(Number(width)) ||\n /^(?<amount>\\d+)(?=%$)/u.exec(String(width)) !== null)\n );\n}\n\nexport function parseFractionalUnit(width?: string | number | null): number {\n if (\n width === null ||\n width === undefined ||\n width === \"\" ||\n typeof width === \"number\"\n ) {\n return 1;\n }\n\n const match = /^(?<amount>.+)(?=fr$)/u.exec(width);\n\n // if width is the incorrect format, just default it to a 1fr\n if (!match) {\n if (process.env.NODE_ENV !== \"production\") {\n console.warn(\n `width: ${width} is not a supported format, width should be a number (ex. 150), percentage (ex. '50%') or fr unit (ex. '2fr')`,\n \"defaulting to '1fr'\"\n );\n }\n\n return 1;\n }\n\n return Number(match[0]);\n}\n\nexport function parseStaticWidth(\n width: number | string,\n tableWidth: number\n): number {\n if (typeof width === \"string\") {\n const match = /^(?<amount>\\d+)(?=%$)/u.exec(width);\n\n if (!match) {\n throw new Error(\n \"Only percentages or numbers are supported for static column widths\"\n );\n }\n\n return tableWidth * (Number(match[0]) / 100);\n }\n\n return width;\n}\n\nexport function getMaxWidth(\n maxWidth: number | string | null | undefined,\n tableWidth: number\n): number {\n return maxWidth === null || maxWidth === undefined\n ? Number.MAX_SAFE_INTEGER\n : parseStaticWidth(maxWidth, tableWidth);\n}\n\n// cannot support FR units, we'd need to know everything else in the table to do that\nexport function getMinWidth(\n minWidth: number | string | null | undefined,\n tableWidth: number\n): number {\n return minWidth === null || minWidth === undefined\n ? 0\n : parseStaticWidth(minWidth, tableWidth);\n}\n\nexport interface IColumn {\n minWidth?: number | string;\n maxWidth?: number | string;\n width?: number | string;\n defaultWidth?: number | string;\n key: Key;\n}\n\ninterface FlexItem {\n frozen: boolean;\n baseSize: number;\n hypotheticalMainSize: number;\n min: number;\n max: number;\n flex: number;\n targetMainSize: number;\n violation: number;\n}\n\n/**\n * Implements the flex algorithm described in https://www.w3.org/TR/css-flexbox-1/#layout-algorithm\n * It makes a few constraint/assumptions: 1. All basis values are 0 unless it is a static width,\n * then the basis is the static width 2. All flex grow and shrink values are equal to the FR\n * specified on the column, grow and shrink for the same column are equal 3. We only have one row An\n * example of the setup can be seen here https://jsfiddle.net/snowystinger/wv0ymjaf/61/ where I let\n * the browser figure out the flex of the columns. Note: We differ in one key aspect, all of our\n * column widths must be whole numbers, so we avoid browser sub pixel rounding errors. To do this,\n * we use a cascading rounding algorithm to ensure that the sum of the widths is maintained while\n * distributing the rounding remainder across the columns.\n *\n * As noted in the chrome source code, this algorithm is very accurate, but has the potential to be\n * quadratic. They have deemed this to be acceptable because the number of elements is usually small\n * and the flex factors are usually not high variance. I believe we can make the same assumptions.\n * Particularly once resizing is started, it will convert all columns to the left to static widths,\n * so it will cut down on the number of FR columns.\n *\n * There are likely faster ways to do this, I've chosen to stick to the spec as closely as possible\n * for readability, accuracy, and for the note that this behaving quadratically is unlikely to be a\n * problem.\n *\n * @param availableWidth - The visible width of the table.\n * @param columns - The table defined columns.\n * @param changedColumns - Any columns we want to override, for example, during resizing.\n * @param getDefaultWidth - A function that returns the default width of a column by its index.\n * @param getDefaultMinWidth - A function that returns the default min width of a column by its\n * index.\n */\nexport function calculateColumnSizes(\n initialAvailableWidth: number,\n columns: IColumn[],\n changedColumns: Map<Key, ColumnSize>,\n getDefaultWidth?: (index: number) => ColumnSize | null | undefined,\n getDefaultMinWidth?: (index: number) => ColumnSize | null | undefined\n): number[] {\n let availableWidth = initialAvailableWidth;\n const originalWidth = availableWidth;\n const flooredWidth = Math.floor(availableWidth);\n const hasFractionalWidth = availableWidth - flooredWidth > 0;\n availableWidth = flooredWidth;\n let hasNonFrozenItems = false;\n\n const flexItems: FlexItem[] = columns.map((column, index) => {\n const width =\n changedColumns.get(column.key) === null ||\n changedColumns.get(column.key) === undefined\n ? (column.width ??\n column.defaultWidth ??\n getDefaultWidth?.(index) ??\n \"1fr\")\n : (changedColumns.get(column.key) ?? \"1fr\");\n\n let frozen = false;\n let baseSize = 0;\n let flex = 0;\n let targetMainSize = 0;\n\n if (isStatic(width)) {\n baseSize = parseStaticWidth(width, availableWidth);\n frozen = true;\n } else {\n flex = parseFractionalUnit(width);\n\n if (flex <= 0) {\n frozen = true;\n }\n }\n\n const min = getMinWidth(\n column.minWidth ?? getDefaultMinWidth?.(index) ?? 0,\n availableWidth\n );\n\n const max = getMaxWidth(column.maxWidth, availableWidth);\n const hypotheticalMainSize = Math.max(min, Math.min(baseSize, max));\n\n // 9.7.1\n // We don't make use of flex basis, it's always 0, so we are always in 'grow' mode.\n // 9.7.2\n if (frozen) {\n targetMainSize = hypotheticalMainSize;\n } else if (baseSize > hypotheticalMainSize) {\n frozen = true;\n targetMainSize = hypotheticalMainSize;\n }\n\n // 9.7.3\n if (!frozen) {\n hasNonFrozenItems = true;\n }\n\n return {\n baseSize,\n flex,\n frozen,\n hypotheticalMainSize,\n max,\n min,\n targetMainSize,\n violation: 0,\n };\n });\n\n // 9.7.4\n // 9.7.4.a\n while (hasNonFrozenItems) {\n // 9.7.4.b\n /**\n * Calculate the remaining free space as for initial free space,\n * above (9.7.3). If the sum of the unfrozen flex items’ flex factors is\n * less than one, multiply the initial free space by this sum (of flex factors).\n * If the magnitude of this value is less than the magnitude of\n * the remaining free space, use this as the remaining free space.\n */\n let usedWidth = 0;\n let flexFactors = 0;\n\n for (const item of flexItems) {\n if (item.frozen) {\n usedWidth += item.targetMainSize;\n } else {\n usedWidth += item.baseSize;\n flexFactors += item.flex;\n }\n }\n\n const remainingFreeSpace = availableWidth - usedWidth;\n\n // we only support integer FR's, and because of hasNonFrozenItems, we know that flexFactors > 0\n // so no need to check for flexFactors < 1\n // 9.7.4.c\n /**\n * If the remaining free space is zero\n * - Do nothing.\n * Else // remember, we're always in grow mode\n * - Find the ratio of the item’s flex grow factor to the\n * sum of the flex grow factors of all unfrozen items on\n * the line. Set the item’s target main size to its flex\n * base size plus a fraction of the remaining free space\n * proportional to the ratio.\n */\n if (remainingFreeSpace > 0) {\n for (const item of flexItems) {\n if (!item.frozen) {\n const ratio = item.flex / flexFactors;\n item.targetMainSize = item.baseSize + ratio * remainingFreeSpace;\n }\n }\n }\n\n // 9.7.4.d\n /**\n * Fix min/max violations. Clamp each non-frozen item’s\n * target main size by its used min and max main sizes\n * and floor its content-box size at zero. If the item’s\n * target main size was made smaller by this, it’s a max\n * violation. If the item’s target main size was made\n * larger by this, it’s a min violation.\n */\n let totalViolation = 0;\n\n for (const item of flexItems) {\n item.violation = 0;\n\n if (!item.frozen) {\n const { min, max, targetMainSize } = item;\n item.targetMainSize = Math.max(min, Math.min(targetMainSize, max));\n item.violation = item.targetMainSize - targetMainSize;\n totalViolation += item.violation;\n }\n }\n\n // 9.7.4.e\n /**\n * Freeze over-flexed items. The total violation is the\n * sum of the adjustments from the previous step\n * ∑(clamped size - unclamped size). If the total violation is:\n * Zero\n * - Freeze all items.\n *\n * Positive\n * - Freeze all the items with min violations.\n *\n * Negative\n * - Freeze all the items with max violations.\n */\n hasNonFrozenItems = false;\n\n for (const item of flexItems) {\n if (\n totalViolation === 0 ||\n Math.sign(totalViolation) === Math.sign(item.violation)\n ) {\n item.frozen = true;\n } else if (!item.frozen) {\n hasNonFrozenItems = true;\n }\n }\n }\n\n const columnSizes = cascadeRounding(flexItems);\n\n // Give the leftover sub-pixel width to the last column so the columns sum\n // exactly to the (possibly fractional) available width.\n if (hasFractionalWidth && columnSizes.length > 0) {\n const [, tableFractionalWidth] = originalWidth.toString().split(\".\");\n\n const columnWidth = requireValue(\n columnSizes.at(-1),\n \"Expected columnSizes.at(-1) to exist.\"\n ).toString();\n\n columnSizes[columnSizes.length - 1] = Number(\n `${columnWidth}.${tableFractionalWidth}`\n );\n }\n\n return columnSizes;\n}\n\nfunction cascadeRounding(flexItems: FlexItem[]): number[] {\n /*\n Given an array of floats that sum to an integer, this rounds the floats\n and returns an array of integers with the same sum.\n */\n let fpTotal = 0;\n let intTotal = 0;\n const roundedArray: number[] = [];\n\n for (const item of flexItems) {\n const float = item.targetMainSize;\n const integer = Math.round(float + fpTotal) - intTotal;\n fpTotal += float;\n intTotal += integer;\n roundedArray.push(integer);\n }\n\n return roundedArray;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAuBA,SAAgB,SAAS,OAAyC;CAChE,OACE,UAAU,QACV,UAAU,KAAA,MACT,CAAC,OAAO,MAAM,OAAO,KAAK,CAAC,KAC1B,yBAAyB,KAAK,OAAO,KAAK,CAAC,MAAM;AAEvD;AAEA,SAAgB,oBAAoB,OAAwC;CA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B,KACnB,KAAK,KAAK,cAAc,MAAM,KAAK,KAAK,KAAK,SAAS,GAEtD,KAAK,SAAS;OACT,IAAI,CAAC,KAAK,QACf,oBAAoB;CAG1B;CAEA,MAAM,cAAc,gBAAgB,SAAS;CAI7C,IAAI,sBAAsB,YAAY,SAAS,GAAG;EAChD,MAAM,GAAG,wBAAwB,cAAc,SAAS,CAAC,CAAC,MAAM,GAAG;EAEnE,MAAM,cAAc,aAClB,YAAY,GAAG,EAAE,GACjB,uCACF,CAAC,CAAC,SAAS;EAEX,YAAY,YAAY,SAAS,KAAK,OACpC,GAAG,YAAY,GAAG,sBACpB;CACF;CAEA,OAAO;AACT;AAEA,SAAS,gBAAgB,WAAiC;CAKxD,IAAI,UAAU;CACd,IAAI,WAAW;CACf,MAAM,eAAyB,CAAC;CAEhC,KAAK,MAAM,QAAQ,WAAW;EAC5B,MAAM,QAAQ,KAAK;EACnB,MAAM,UAAU,KAAK,MAAM,QAAQ,OAAO,IAAI;EAC9C,WAAW;EACX,YAAY;EACZ,aAAa,KAAK,OAAO;CAC3B;CAEA,OAAO;AACT"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
3
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
*
|
|
7
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
* governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
/*
|
|
13
|
+
* Derived from Adobe React Spectrum: packages/react-stately/src/tabs/useTabListState.ts.
|
|
14
|
+
* Modified for Solid Aria: adapted imports, collection descriptors, and reactive state APIs for Solid 2; synchronize selection and browser focus after rendering on the client.
|
|
15
|
+
* Licensed under Apache-2.0. See LICENSES/Apache-2.0.txt and NOTICE.txt at the repository root.
|
|
16
|
+
*/
|
|
17
|
+
import { SingleSelectListState } from "../list/create-single-select-list-state.js";
|
|
18
|
+
import { CollectionBase, CollectionStateBase, Key, SingleSelection } from "@solid2-aria/types-shared";
|
|
19
|
+
export interface TabListProps<T> extends CollectionBase<T>, Omit<SingleSelection, "disallowEmptySelection" | "selectedKey" | "defaultSelectedKey" | "onSelectionChange"> {
|
|
20
|
+
/**
|
|
21
|
+
* Whether the TabList is disabled.
|
|
22
|
+
* Shows that a selection exists, but is not available in that circumstance.
|
|
23
|
+
*/
|
|
24
|
+
isDisabled?: boolean;
|
|
25
|
+
/** The currently selected key in the collection (controlled). */
|
|
26
|
+
selectedKey?: Key;
|
|
27
|
+
/** The initial selected keys in the collection (uncontrolled). */
|
|
28
|
+
defaultSelectedKey?: Key;
|
|
29
|
+
/** Handler that is called when the selection changes. */
|
|
30
|
+
onSelectionChange?: (key: Key) => void;
|
|
31
|
+
}
|
|
32
|
+
export interface TabListStateOptions<T> extends Omit<TabListProps<T>, "children">, CollectionStateBase<T> {}
|
|
33
|
+
export interface TabListState<T> extends SingleSelectListState<T> {
|
|
34
|
+
/** Whether the tab list is disabled. */
|
|
35
|
+
isDisabled: boolean;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Provides state management for a Tabs component. Tabs include a TabList which tracks
|
|
39
|
+
* which tab is currently selected and displays the content associated with that Tab in a TabPanel.
|
|
40
|
+
*/
|
|
41
|
+
export declare function createTabListState<T extends object>(props: TabListStateOptions<T>): TabListState<T>;
|
|
42
|
+
//# sourceMappingURL=create-tab-list-state.d.ts.map
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
3
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
*
|
|
7
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
* governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
/*
|
|
13
|
+
* Derived from Adobe React Spectrum: packages/react-stately/src/tabs/useTabListState.ts.
|
|
14
|
+
* Modified for Solid Aria: adapted imports, collection descriptors, and reactive state APIs for Solid 2; synchronize selection and browser focus after rendering on the client.
|
|
15
|
+
* Licensed under Apache-2.0. See LICENSES/Apache-2.0.txt and NOTICE.txt at the repository root.
|
|
16
|
+
*/
|
|
17
|
+
import { getNodeProps } from "../utils/get-node-props.js";
|
|
18
|
+
import { createSingleSelectListState } from "../list/create-single-select-list-state.js";
|
|
19
|
+
import { createEffect, merge, omit, untrack } from "solid-js";
|
|
20
|
+
// src/tabs/create-tab-list-state.ts
|
|
21
|
+
/**
|
|
22
|
+
* Provides state management for a Tabs component. Tabs include a TabList which tracks
|
|
23
|
+
* which tab is currently selected and displays the content associated with that Tab in a TabPanel.
|
|
24
|
+
*/
|
|
25
|
+
function createTabListState(props) {
|
|
26
|
+
const state = createSingleSelectListState(merge(omit(props, "onSelectionChange"), {
|
|
27
|
+
get defaultSelectedKey() {
|
|
28
|
+
return props.defaultSelectedKey ?? findDefaultSelectedKey(props.collection, props.disabledKeys ? new Set(props.disabledKeys) : /* @__PURE__ */ new Set()) ?? void 0;
|
|
29
|
+
},
|
|
30
|
+
get onSelectionChange() {
|
|
31
|
+
return (key) => {
|
|
32
|
+
if (key !== null && key !== void 0) props.onSelectionChange?.(key);
|
|
33
|
+
};
|
|
34
|
+
},
|
|
35
|
+
get suppressTextValueWarning() {
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
}));
|
|
39
|
+
let lastSelectedKey = untrack(() => state.selectedKey);
|
|
40
|
+
createEffect(() => {
|
|
41
|
+
const manager = state.selectionManager;
|
|
42
|
+
let { selectedKey } = state;
|
|
43
|
+
let replaceSelection = false;
|
|
44
|
+
if ((props.selectedKey === null || props.selectedKey === void 0) && (manager.isEmpty || selectedKey === null || !state.collection.getItem(selectedKey))) {
|
|
45
|
+
selectedKey = findDefaultSelectedKey(state.collection, state.disabledKeys);
|
|
46
|
+
replaceSelection = selectedKey !== null;
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
manager,
|
|
50
|
+
replaceSelection,
|
|
51
|
+
selectedKey,
|
|
52
|
+
updateFocus: selectedKey !== null && manager.focusedKey === null || !manager.isFocused && selectedKey !== lastSelectedKey
|
|
53
|
+
};
|
|
54
|
+
}, ({ manager, replaceSelection, selectedKey, updateFocus }) => {
|
|
55
|
+
if (replaceSelection && selectedKey !== null) untrack(() => {
|
|
56
|
+
manager.setSelectedKeys([selectedKey]);
|
|
57
|
+
});
|
|
58
|
+
if (updateFocus) untrack(() => {
|
|
59
|
+
manager.setFocusedKey(selectedKey);
|
|
60
|
+
});
|
|
61
|
+
lastSelectedKey = selectedKey;
|
|
62
|
+
});
|
|
63
|
+
return merge(state, { get isDisabled() {
|
|
64
|
+
return props.isDisabled === true || false;
|
|
65
|
+
} });
|
|
66
|
+
}
|
|
67
|
+
function findDefaultSelectedKey(collection, disabledKeys) {
|
|
68
|
+
let selectedKey = null;
|
|
69
|
+
if (collection) {
|
|
70
|
+
selectedKey = collection.getFirstKey();
|
|
71
|
+
while (selectedKey !== null && selectedKey !== void 0 && (disabledKeys.has(selectedKey) || getNodeProps(collection.getItem(selectedKey)).isDisabled) && selectedKey !== collection.getLastKey()) selectedKey = collection.getKeyAfter(selectedKey);
|
|
72
|
+
if (selectedKey !== null && selectedKey !== void 0 && (disabledKeys.has(selectedKey) || getNodeProps(collection.getItem(selectedKey)).isDisabled) && selectedKey === collection.getLastKey()) selectedKey = collection.getFirstKey();
|
|
73
|
+
}
|
|
74
|
+
return selectedKey;
|
|
75
|
+
}
|
|
76
|
+
export { createTabListState };
|
|
77
|
+
|
|
78
|
+
//# sourceMappingURL=create-tab-list-state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-tab-list-state.js","names":[],"sources":["../../src/tabs/create-tab-list-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/tabs/useTabListState.ts.\n * Modified for Solid Aria: adapted imports, collection descriptors, and reactive state APIs for Solid 2; synchronize selection and browser focus after rendering on the client.\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 Key,\n Node,\n SingleSelection,\n} from \"@solid2-aria/types-shared\";\nimport { createEffect, merge, untrack, omit } from \"solid-js\";\n\nimport { createSingleSelectListState } from \"../list/create-single-select-list-state\";\nimport type { SingleSelectListState } from \"../list/create-single-select-list-state\";\nimport { getNodeProps } from \"../utils/get-node-props\";\n\nexport interface TabListProps<T>\n extends\n CollectionBase<T>,\n Omit<\n SingleSelection,\n | \"disallowEmptySelection\"\n | \"selectedKey\"\n | \"defaultSelectedKey\"\n | \"onSelectionChange\"\n > {\n /**\n * Whether the TabList is disabled.\n * Shows that a selection exists, but is not available in that circumstance.\n */\n isDisabled?: boolean;\n /** The currently selected key in the collection (controlled). */\n selectedKey?: Key;\n /** The initial selected keys in the collection (uncontrolled). */\n defaultSelectedKey?: Key;\n /** Handler that is called when the selection changes. */\n onSelectionChange?: (key: Key) => void;\n}\n\nexport interface TabListStateOptions<T>\n extends Omit<TabListProps<T>, \"children\">, CollectionStateBase<T> {}\n\nexport interface TabListState<T> extends SingleSelectListState<T> {\n /** Whether the tab list is disabled. */\n isDisabled: boolean;\n}\n\n/**\n * Provides state management for a Tabs component. Tabs include a TabList which tracks\n * which tab is currently selected and displays the content associated with that Tab in a TabPanel.\n */\nexport function createTabListState<T extends object>(\n props: TabListStateOptions<T>\n): TabListState<T> {\n const state = createSingleSelectListState<T>(\n merge(omit(props, \"onSelectionChange\"), {\n get defaultSelectedKey() {\n return (\n props.defaultSelectedKey ??\n findDefaultSelectedKey(\n props.collection,\n props.disabledKeys ? new Set(props.disabledKeys) : new Set()\n ) ??\n undefined\n );\n },\n get onSelectionChange() {\n return (key: Key | null) => {\n if (key !== null && key !== undefined) {\n props.onSelectionChange?.(key);\n }\n };\n },\n get suppressTextValueWarning() {\n return true;\n },\n })\n );\n\n let lastSelectedKey = untrack(() => state.selectedKey);\n createEffect(\n () => {\n const manager = state.selectionManager;\n let { selectedKey } = state;\n let replaceSelection = false;\n\n if (\n (props.selectedKey === null || props.selectedKey === undefined) &&\n (manager.isEmpty ||\n selectedKey === null ||\n !state.collection.getItem(selectedKey))\n ) {\n selectedKey = findDefaultSelectedKey(\n state.collection,\n state.disabledKeys\n );\n replaceSelection = selectedKey !== null;\n }\n\n return {\n manager,\n replaceSelection,\n selectedKey,\n updateFocus:\n (selectedKey !== null && manager.focusedKey === null) ||\n (!manager.isFocused && selectedKey !== lastSelectedKey),\n };\n },\n ({ manager, replaceSelection, selectedKey, updateFocus }) => {\n if (replaceSelection && selectedKey !== null) {\n untrack(() => {\n manager.setSelectedKeys([selectedKey]);\n });\n }\n\n if (updateFocus) {\n untrack(() => {\n manager.setFocusedKey(selectedKey);\n });\n }\n\n lastSelectedKey = selectedKey;\n }\n );\n\n return merge(state, {\n get isDisabled() {\n return props.isDisabled === true || false;\n },\n });\n}\n\nfunction findDefaultSelectedKey<T>(\n collection: Collection<Node<T>> | undefined,\n disabledKeys: Set<Key>\n) {\n let selectedKey: Key | null = null;\n\n if (collection) {\n selectedKey = collection.getFirstKey();\n\n // loop over tabs until we find one that isn't disabled and select that\n while (\n selectedKey !== null &&\n selectedKey !== undefined &&\n (disabledKeys.has(selectedKey) ||\n getNodeProps(collection.getItem(selectedKey)).isDisabled) &&\n selectedKey !== collection.getLastKey()\n ) {\n selectedKey = collection.getKeyAfter(selectedKey);\n }\n\n // if this check is true, then every item is disabled, it makes more sense to default to the first key than the last\n if (\n selectedKey !== null &&\n selectedKey !== undefined &&\n (disabledKeys.has(selectedKey) ||\n getNodeProps(collection.getItem(selectedKey)).isDisabled) &&\n selectedKey === collection.getLastKey()\n ) {\n selectedKey = collection.getFirstKey();\n }\n }\n\n return selectedKey;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAkEA,SAAgB,mBACd,OACiB;CACjB,MAAM,QAAQ,4BACZ,MAAM,KAAK,OAAO,mBAAmB,GAAG;EACtC,IAAI,qBAAqB;GACvB,OACE,MAAM,sBACN,uBACE,MAAM,YACN,MAAM,eAAe,IAAI,IAAI,MAAM,YAAY,oBAAI,IAAI,IAAI,CAC7D,KACA,KAAA;EAEJ;EACA,IAAI,oBAAoB;GACtB,QAAQ,QAAoB;IAC1B,IAAI,QAAQ,QAAQ,QAAQ,KAAA,GAC1B,MAAM,oBAAoB,GAAG;GAEjC;EACF;EACA,IAAI,2BAA2B;GAC7B,OAAO;EACT;CACF,CAAC,CACH;CAEA,IAAI,kBAAkB,cAAc,MAAM,WAAW;CACrD,mBACQ;EACJ,MAAM,UAAU,MAAM;EACtB,IAAI,EAAE,gBAAgB;EACtB,IAAI,mBAAmB;EAEvB,KACG,MAAM,gBAAgB,QAAQ,MAAM,gBAAgB,KAAA,OACpD,QAAQ,WACP,gBAAgB,QAChB,CAAC,MAAM,WAAW,QAAQ,WAAW,IACvC;GACA,cAAc,uBACZ,MAAM,YACN,MAAM,YACR;GACA,mBAAmB,gBAAgB;EACrC;EAEA,OAAO;GACL;GACA;GACA;GACA,aACG,gBAAgB,QAAQ,QAAQ,eAAe,QAC/C,CAAC,QAAQ,aAAa,gBAAgB;EAC3C;CACF,IACC,EAAE,SAAS,kBAAkB,aAAa,kBAAkB;EAC3D,IAAI,oBAAoB,gBAAgB,MACtC,cAAc;GACZ,QAAQ,gBAAgB,CAAC,WAAW,CAAC;EACvC,CAAC;EAGH,IAAI,aACF,cAAc;GACZ,QAAQ,cAAc,WAAW;EACnC,CAAC;EAGH,kBAAkB;CACpB,CACF;CAEA,OAAO,MAAM,OAAO,EAClB,IAAI,aAAa;EACf,OAAO,MAAM,eAAe,QAAQ;CACtC,EACF,CAAC;AACH;AAEA,SAAS,uBACP,YACA,cACA;CACA,IAAI,cAA0B;CAE9B,IAAI,YAAY;EACd,cAAc,WAAW,YAAY;EAGrC,OACE,gBAAgB,QAChB,gBAAgB,KAAA,MACf,aAAa,IAAI,WAAW,KAC3B,aAAa,WAAW,QAAQ,WAAW,CAAC,CAAC,CAAC,eAChD,gBAAgB,WAAW,WAAW,GAEtC,cAAc,WAAW,YAAY,WAAW;EAIlD,IACE,gBAAgB,QAChB,gBAAgB,KAAA,MACf,aAAa,IAAI,WAAW,KAC3B,aAAa,WAAW,QAAQ,WAAW,CAAC,CAAC,CAAC,eAChD,gBAAgB,WAAW,WAAW,GAEtC,cAAc,WAAW,YAAY;CAEzC;CAEA,OAAO;AACT"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
3
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
*
|
|
7
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
* governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
/*
|
|
13
|
+
* Derived from Adobe React Spectrum: packages/react-stately/src/toast/useToastState.ts.
|
|
14
|
+
* Modified for Solid Aria: adapted imports, collection descriptors, and reactive state APIs for Solid 2.
|
|
15
|
+
* Licensed under Apache-2.0. See LICENSES/Apache-2.0.txt and NOTICE.txt at the repository root.
|
|
16
|
+
*/
|
|
17
|
+
type ToastAction = "add" | "remove" | "clear";
|
|
18
|
+
export interface ToastStateProps {
|
|
19
|
+
/** The maximum number of toasts to display at a time. */
|
|
20
|
+
maxVisibleToasts?: number;
|
|
21
|
+
/** Function to wrap updates in (i.e. document.startViewTransition()). */
|
|
22
|
+
wrapUpdate?: (fn: () => void, action: ToastAction) => void;
|
|
23
|
+
}
|
|
24
|
+
export interface ToastOptions {
|
|
25
|
+
/** Handler that is called when the toast is closed, either by the user or after a timeout. */
|
|
26
|
+
onClose?: () => void;
|
|
27
|
+
/** A timeout to automatically close the toast after, in milliseconds. */
|
|
28
|
+
timeout?: number;
|
|
29
|
+
}
|
|
30
|
+
export interface QueuedToast<T> extends ToastOptions {
|
|
31
|
+
/** The content of the toast. */
|
|
32
|
+
content: T;
|
|
33
|
+
/** A unique key for the toast. */
|
|
34
|
+
key: string;
|
|
35
|
+
/** A timer for the toast, if a timeout was set. */
|
|
36
|
+
timer?: Timer;
|
|
37
|
+
}
|
|
38
|
+
export interface ToastState<T> {
|
|
39
|
+
/** Adds a new toast to the queue. */
|
|
40
|
+
add: (content: T, options?: ToastOptions) => string;
|
|
41
|
+
/**
|
|
42
|
+
* Closes a toast.
|
|
43
|
+
*/
|
|
44
|
+
close: (key: string) => void;
|
|
45
|
+
/** Pauses the timers for all visible toasts. */
|
|
46
|
+
pauseAll: () => void;
|
|
47
|
+
/** Resumes the timers for all visible toasts. */
|
|
48
|
+
resumeAll: () => void;
|
|
49
|
+
/** The visible toasts. */
|
|
50
|
+
visibleToasts: QueuedToast<T>[];
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Provides state management for a toast queue. Toasts display brief, temporary notifications
|
|
54
|
+
* of actions, errors, or other events in an application.
|
|
55
|
+
*/
|
|
56
|
+
export declare function createToastState<T>(props?: ToastStateProps): ToastState<T>;
|
|
57
|
+
/** Subscribes for the lifetime of the current reactive owner. */
|
|
58
|
+
export declare function createToastQueue<T>(queue: ToastQueue<T>): ToastState<T>;
|
|
59
|
+
/**
|
|
60
|
+
* A ToastQueue manages the order of toasts.
|
|
61
|
+
*/
|
|
62
|
+
export declare class ToastQueue<T> {
|
|
63
|
+
private queue;
|
|
64
|
+
private readonly subscriptions;
|
|
65
|
+
private readonly maxVisibleToasts;
|
|
66
|
+
private readonly wrapUpdate?;
|
|
67
|
+
/** The currently visible toasts. */
|
|
68
|
+
visibleToasts: QueuedToast<T>[];
|
|
69
|
+
constructor(options?: ToastStateProps);
|
|
70
|
+
private runWithWrapUpdate;
|
|
71
|
+
/** Subscribes to updates to the visible toasts. */
|
|
72
|
+
subscribe(fn: () => void): () => void;
|
|
73
|
+
/** Adds a new toast to the queue. */
|
|
74
|
+
add(content: T, options?: ToastOptions): string;
|
|
75
|
+
/**
|
|
76
|
+
* Closes a toast.
|
|
77
|
+
*/
|
|
78
|
+
close(key: string): void;
|
|
79
|
+
private updateVisibleToasts;
|
|
80
|
+
/** Pauses the timers for all visible toasts. */
|
|
81
|
+
pauseAll(): void;
|
|
82
|
+
/** Resumes the timers for all visible toasts. */
|
|
83
|
+
resumeAll(): void;
|
|
84
|
+
clear(): void;
|
|
85
|
+
}
|
|
86
|
+
declare class Timer {
|
|
87
|
+
private timerId;
|
|
88
|
+
private startTime;
|
|
89
|
+
private remaining;
|
|
90
|
+
private readonly callback;
|
|
91
|
+
constructor(callback: () => void, delay: number);
|
|
92
|
+
reset(delay: number): void;
|
|
93
|
+
pause(): void;
|
|
94
|
+
resume(): void;
|
|
95
|
+
}
|
|
96
|
+
export {};
|
|
97
|
+
//# sourceMappingURL=create-toast-state.d.ts.map
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
3
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
*
|
|
7
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
* governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
/*
|
|
13
|
+
* Derived from Adobe React Spectrum: packages/react-stately/src/toast/useToastState.ts.
|
|
14
|
+
* Modified for Solid Aria: adapted imports, collection descriptors, and reactive state APIs for Solid 2.
|
|
15
|
+
* Licensed under Apache-2.0. See LICENSES/Apache-2.0.txt and NOTICE.txt at the repository root.
|
|
16
|
+
*/
|
|
17
|
+
import { createMemo, createRenderEffect, createSignal, untrack } from "solid-js";
|
|
18
|
+
// src/toast/create-toast-state.ts
|
|
19
|
+
/**
|
|
20
|
+
* Provides state management for a toast queue. Toasts display brief, temporary notifications
|
|
21
|
+
* of actions, errors, or other events in an application.
|
|
22
|
+
*/
|
|
23
|
+
function createToastState(props = {}) {
|
|
24
|
+
const queue = createMemo(() => new ToastQueue({
|
|
25
|
+
maxVisibleToasts: props.maxVisibleToasts ?? 1,
|
|
26
|
+
wrapUpdate: props.wrapUpdate
|
|
27
|
+
}));
|
|
28
|
+
return untrack(() => subscribeToQueue(queue, true));
|
|
29
|
+
}
|
|
30
|
+
/** Subscribes for the lifetime of the current reactive owner. */
|
|
31
|
+
function createToastQueue(queue) {
|
|
32
|
+
return subscribeToQueue(() => queue, false);
|
|
33
|
+
}
|
|
34
|
+
function subscribeToQueue(getQueue, ownsQueue) {
|
|
35
|
+
const [visibleToasts, setVisibleToasts] = createSignal(untrack(() => getQueue().visibleToasts), { ownedWrite: true });
|
|
36
|
+
createRenderEffect(getQueue, (queue) => {
|
|
37
|
+
setVisibleToasts(queue.visibleToasts);
|
|
38
|
+
const unsubscribe = queue.subscribe(() => {
|
|
39
|
+
setVisibleToasts(queue.visibleToasts);
|
|
40
|
+
});
|
|
41
|
+
return () => {
|
|
42
|
+
unsubscribe();
|
|
43
|
+
if (ownsQueue) queue.clear();
|
|
44
|
+
};
|
|
45
|
+
});
|
|
46
|
+
return {
|
|
47
|
+
add: (content, options) => getQueue().add(content, options),
|
|
48
|
+
close: (key) => {
|
|
49
|
+
getQueue().close(key);
|
|
50
|
+
},
|
|
51
|
+
pauseAll: () => {
|
|
52
|
+
getQueue().pauseAll();
|
|
53
|
+
},
|
|
54
|
+
resumeAll: () => {
|
|
55
|
+
getQueue().resumeAll();
|
|
56
|
+
},
|
|
57
|
+
get visibleToasts() {
|
|
58
|
+
return visibleToasts();
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* A ToastQueue manages the order of toasts.
|
|
64
|
+
*/
|
|
65
|
+
var ToastQueue = class {
|
|
66
|
+
queue = [];
|
|
67
|
+
subscriptions = /* @__PURE__ */ new Set();
|
|
68
|
+
maxVisibleToasts;
|
|
69
|
+
wrapUpdate;
|
|
70
|
+
/** The currently visible toasts. */
|
|
71
|
+
visibleToasts = [];
|
|
72
|
+
constructor(options) {
|
|
73
|
+
this.maxVisibleToasts = options?.maxVisibleToasts ?? Infinity;
|
|
74
|
+
this.wrapUpdate = options?.wrapUpdate;
|
|
75
|
+
}
|
|
76
|
+
runWithWrapUpdate(fn, action) {
|
|
77
|
+
if (this.wrapUpdate) this.wrapUpdate(fn, action);
|
|
78
|
+
else fn();
|
|
79
|
+
}
|
|
80
|
+
/** Subscribes to updates to the visible toasts. */
|
|
81
|
+
subscribe(fn) {
|
|
82
|
+
this.subscriptions.add(fn);
|
|
83
|
+
return () => {
|
|
84
|
+
this.subscriptions.delete(fn);
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
/** Adds a new toast to the queue. */
|
|
88
|
+
add(content, options = {}) {
|
|
89
|
+
const toastKey = `_${Math.random().toString(36).slice(2)}`;
|
|
90
|
+
const toast = {
|
|
91
|
+
...options,
|
|
92
|
+
content,
|
|
93
|
+
key: toastKey,
|
|
94
|
+
timer: options.timeout !== void 0 && options.timeout !== 0 && !Number.isNaN(options.timeout) ? new Timer(() => {
|
|
95
|
+
this.close(toastKey);
|
|
96
|
+
}, options.timeout) : void 0
|
|
97
|
+
};
|
|
98
|
+
this.queue.unshift(toast);
|
|
99
|
+
this.updateVisibleToasts("add");
|
|
100
|
+
return toastKey;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Closes a toast.
|
|
104
|
+
*/
|
|
105
|
+
close(key) {
|
|
106
|
+
const index = this.queue.findIndex((t) => t.key === key);
|
|
107
|
+
const toast = this.queue[index];
|
|
108
|
+
if (toast) {
|
|
109
|
+
toast.timer?.pause();
|
|
110
|
+
toast.onClose?.();
|
|
111
|
+
this.queue.splice(index, 1);
|
|
112
|
+
}
|
|
113
|
+
this.updateVisibleToasts("remove");
|
|
114
|
+
}
|
|
115
|
+
updateVisibleToasts(action) {
|
|
116
|
+
this.visibleToasts = this.queue.slice(0, this.maxVisibleToasts);
|
|
117
|
+
this.runWithWrapUpdate(() => {
|
|
118
|
+
for (const fn of this.subscriptions) fn();
|
|
119
|
+
}, action);
|
|
120
|
+
}
|
|
121
|
+
/** Pauses the timers for all visible toasts. */
|
|
122
|
+
pauseAll() {
|
|
123
|
+
for (const toast of this.visibleToasts) if (toast.timer) toast.timer.pause();
|
|
124
|
+
}
|
|
125
|
+
/** Resumes the timers for all visible toasts. */
|
|
126
|
+
resumeAll() {
|
|
127
|
+
for (const toast of this.visibleToasts) if (toast.timer) toast.timer.resume();
|
|
128
|
+
}
|
|
129
|
+
clear() {
|
|
130
|
+
for (const toast of this.queue) toast.timer?.pause();
|
|
131
|
+
this.queue = [];
|
|
132
|
+
this.updateVisibleToasts("clear");
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
var Timer = class {
|
|
136
|
+
timerId = null;
|
|
137
|
+
startTime = null;
|
|
138
|
+
remaining;
|
|
139
|
+
callback;
|
|
140
|
+
constructor(callback, delay) {
|
|
141
|
+
this.remaining = delay;
|
|
142
|
+
this.callback = callback;
|
|
143
|
+
}
|
|
144
|
+
reset(delay) {
|
|
145
|
+
this.remaining = delay;
|
|
146
|
+
this.resume();
|
|
147
|
+
}
|
|
148
|
+
pause() {
|
|
149
|
+
if (this.timerId === null || this.timerId === void 0) return;
|
|
150
|
+
clearTimeout(this.timerId);
|
|
151
|
+
this.timerId = null;
|
|
152
|
+
this.remaining -= Date.now() - (this.startTime ?? Date.now());
|
|
153
|
+
}
|
|
154
|
+
resume() {
|
|
155
|
+
if (this.timerId !== null || this.remaining <= 0) return;
|
|
156
|
+
this.startTime = Date.now();
|
|
157
|
+
this.timerId = setTimeout(() => {
|
|
158
|
+
this.timerId = null;
|
|
159
|
+
this.remaining = 0;
|
|
160
|
+
this.callback();
|
|
161
|
+
}, this.remaining);
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
export { ToastQueue, createToastQueue, createToastState };
|
|
165
|
+
|
|
166
|
+
//# sourceMappingURL=create-toast-state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-toast-state.js","names":[],"sources":["../../src/toast/create-toast-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/toast/useToastState.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 {\n createSignal,\n createMemo,\n createRenderEffect,\n untrack,\n} from \"solid-js\";\n\ntype ToastAction = \"add\" | \"remove\" | \"clear\";\n\nexport interface ToastStateProps {\n /** The maximum number of toasts to display at a time. */\n maxVisibleToasts?: number;\n /** Function to wrap updates in (i.e. document.startViewTransition()). */\n wrapUpdate?: (fn: () => void, action: ToastAction) => void;\n}\n\nexport interface ToastOptions {\n /** Handler that is called when the toast is closed, either by the user or after a timeout. */\n onClose?: () => void;\n /** A timeout to automatically close the toast after, in milliseconds. */\n timeout?: number;\n}\n\nexport interface QueuedToast<T> extends ToastOptions {\n /** The content of the toast. */\n content: T;\n /** A unique key for the toast. */\n key: string;\n /** A timer for the toast, if a timeout was set. */\n timer?: Timer;\n}\n\nexport interface ToastState<T> {\n /** Adds a new toast to the queue. */\n add: (content: T, options?: ToastOptions) => string;\n /**\n * Closes a toast.\n */\n close: (key: string) => void;\n /** Pauses the timers for all visible toasts. */\n pauseAll: () => void;\n /** Resumes the timers for all visible toasts. */\n resumeAll: () => void;\n /** The visible toasts. */\n visibleToasts: QueuedToast<T>[];\n}\n\n/**\n * Provides state management for a toast queue. Toasts display brief, temporary notifications\n * of actions, errors, or other events in an application.\n */\nexport function createToastState<T>(\n props: ToastStateProps = {}\n): ToastState<T> {\n const queue = createMemo(\n () =>\n new ToastQueue<T>({\n maxVisibleToasts: props.maxVisibleToasts ?? 1,\n wrapUpdate: props.wrapUpdate,\n })\n );\n\n return untrack(() => subscribeToQueue(queue, true));\n}\n\n/** Subscribes for the lifetime of the current reactive owner. */\nexport function createToastQueue<T>(queue: ToastQueue<T>): ToastState<T> {\n return subscribeToQueue(() => queue, false);\n}\n\nfunction subscribeToQueue<T>(\n getQueue: () => ToastQueue<T>,\n ownsQueue: boolean\n): ToastState<T> {\n const [visibleToasts, setVisibleToasts] = createSignal<QueuedToast<T>[]>(\n untrack(() => getQueue().visibleToasts),\n { ownedWrite: true }\n );\n\n createRenderEffect(getQueue, (queue) => {\n setVisibleToasts(queue.visibleToasts);\n\n const unsubscribe = queue.subscribe(() => {\n setVisibleToasts(queue.visibleToasts);\n });\n\n return () => {\n unsubscribe();\n\n if (ownsQueue) {\n queue.clear();\n }\n };\n });\n\n return {\n add: (content, options) => getQueue().add(content, options),\n close: (key) => {\n getQueue().close(key);\n },\n pauseAll: () => {\n getQueue().pauseAll();\n },\n resumeAll: () => {\n getQueue().resumeAll();\n },\n get visibleToasts() {\n return visibleToasts();\n },\n };\n}\n\n/**\n * A ToastQueue manages the order of toasts.\n */\nexport class ToastQueue<T> {\n private queue: QueuedToast<T>[] = [];\n private readonly subscriptions = new Set<() => void>();\n private readonly maxVisibleToasts: number;\n private readonly wrapUpdate?: (fn: () => void, action: ToastAction) => void;\n /** The currently visible toasts. */\n visibleToasts: QueuedToast<T>[] = [];\n constructor(options?: ToastStateProps) {\n this.maxVisibleToasts = options?.maxVisibleToasts ?? Infinity;\n this.wrapUpdate = options?.wrapUpdate;\n }\n private runWithWrapUpdate(fn: () => void, action: ToastAction): void {\n if (this.wrapUpdate) {\n this.wrapUpdate(fn, action);\n } else {\n fn();\n }\n }\n /** Subscribes to updates to the visible toasts. */\n subscribe(fn: () => void): () => void {\n this.subscriptions.add(fn);\n\n return () => {\n this.subscriptions.delete(fn);\n };\n }\n /** Adds a new toast to the queue. */\n add(content: T, options: ToastOptions = {}): string {\n const toastKey = `_${Math.random().toString(36).slice(2)}`;\n\n const toast: QueuedToast<T> = {\n ...options,\n content,\n key: toastKey,\n timer:\n options.timeout !== undefined &&\n options.timeout !== 0 &&\n !Number.isNaN(options.timeout)\n ? new Timer(() => {\n this.close(toastKey);\n }, options.timeout)\n : undefined,\n };\n\n this.queue.unshift(toast);\n this.updateVisibleToasts(\"add\");\n\n return toastKey;\n }\n /**\n * Closes a toast.\n */\n close(key: string): void {\n const index = this.queue.findIndex((t) => t.key === key);\n\n const toast = this.queue[index];\n\n if (toast) {\n toast.timer?.pause();\n toast.onClose?.();\n this.queue.splice(index, 1);\n }\n\n this.updateVisibleToasts(\"remove\");\n }\n private updateVisibleToasts(action: ToastAction) {\n this.visibleToasts = this.queue.slice(0, this.maxVisibleToasts);\n this.runWithWrapUpdate(() => {\n for (const fn of this.subscriptions) {\n fn();\n }\n }, action);\n }\n /** Pauses the timers for all visible toasts. */\n pauseAll(): void {\n for (const toast of this.visibleToasts) {\n if (toast.timer) {\n toast.timer.pause();\n }\n }\n }\n /** Resumes the timers for all visible toasts. */\n resumeAll(): void {\n for (const toast of this.visibleToasts) {\n if (toast.timer) {\n toast.timer.resume();\n }\n }\n }\n clear(): void {\n for (const toast of this.queue) {\n toast.timer?.pause();\n }\n\n this.queue = [];\n this.updateVisibleToasts(\"clear\");\n }\n}\n\nclass Timer {\n private timerId: ReturnType<typeof setTimeout> | null = null;\n private startTime: number | null = null;\n private remaining: number;\n private readonly callback: () => void;\n constructor(callback: () => void, delay: number) {\n this.remaining = delay;\n this.callback = callback;\n }\n reset(delay: number): void {\n this.remaining = delay;\n this.resume();\n }\n pause(): void {\n if (this.timerId === null || this.timerId === undefined) {\n return;\n }\n\n clearTimeout(this.timerId);\n this.timerId = null;\n this.remaining -= Date.now() - (this.startTime ?? Date.now());\n }\n resume(): void {\n if (this.timerId !== null || this.remaining <= 0) {\n return;\n }\n\n this.startTime = Date.now();\n this.timerId = setTimeout(() => {\n this.timerId = null;\n this.remaining = 0;\n this.callback();\n }, this.remaining);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAoEA,SAAgB,iBACd,QAAyB,CAAC,GACX;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