@momentum-design/components 0.125.0 → 0.126.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/dist/browser/index.js +259 -259
- package/dist/browser/index.js.map +4 -4
- package/dist/components/responsivesettingsprovider/index.d.ts +7 -0
- package/dist/components/responsivesettingsprovider/index.js +4 -0
- package/dist/components/responsivesettingsprovider/responsiveSettingsContext.d.ts +11 -0
- package/dist/components/responsivesettingsprovider/responsiveSettingsContext.js +14 -0
- package/dist/components/responsivesettingsprovider/responsivesettingsprovider.component.d.ts +65 -0
- package/dist/components/responsivesettingsprovider/responsivesettingsprovider.component.js +122 -0
- package/dist/components/responsivesettingsprovider/responsivesettingsprovider.constants.d.ts +9 -0
- package/dist/components/responsivesettingsprovider/responsivesettingsprovider.constants.js +9 -0
- package/dist/components/responsivesettingsprovider/responsivesettingsprovider.types.d.ts +25 -0
- package/dist/components/responsivesettingsprovider/responsivesettingsprovider.types.js +1 -0
- package/dist/custom-elements.json +1770 -1674
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/react/index.d.ts +6 -5
- package/dist/react/index.js +6 -5
- package/dist/react/responsivesettingsprovider/index.d.ts +35 -0
- package/dist/react/responsivesettingsprovider/index.js +44 -0
- package/dist/utils/controllers/ElementStore.d.ts +10 -0
- package/dist/utils/controllers/ElementStore.js +30 -2
- package/dist/utils/dom.d.ts +13 -0
- package/dist/utils/dom.js +13 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -54,6 +54,7 @@ import Progressbar from './components/progressbar';
|
|
|
54
54
|
import Progressspinner from './components/progressspinner';
|
|
55
55
|
import Radio from './components/radio';
|
|
56
56
|
import RadioGroup from './components/radiogroup';
|
|
57
|
+
import ResponsiveSettingsProvider from './components/responsivesettingsprovider';
|
|
57
58
|
import ScreenreaderAnnouncer from './components/screenreaderannouncer';
|
|
58
59
|
import Searchfield from './components/searchfield';
|
|
59
60
|
import Searchpopover from './components/searchpopover';
|
|
@@ -102,6 +103,6 @@ import { BUTTON_COLORS, BUTTON_VARIANTS, ICON_BUTTON_SIZES, PILL_BUTTON_SIZES }
|
|
|
102
103
|
import { SKELETON_VARIANTS } from './components/skeleton/skeleton.constants';
|
|
103
104
|
import { inMemoryCache, webAPIAssetsCache } from './utils/assets-cache';
|
|
104
105
|
import type { TablistChangeEvent } from './components/tablist/tablist.types';
|
|
105
|
-
export { Accordion, AccordionButton, AccordionGroup, AlertChip, Animation, AnnouncementDialog, Appheader, Avatar, AvatarButton, Badge, Brandvisual, Bullet, Button, ButtonGroup, ButtonLink, Card, CardButton, CardCheckbox, CardRadio, Checkbox, Chip, Coachmark, ControlTypeProvider, Dialog, Divider, FilterChip, FormfieldGroup, Icon, IconProvider, Illustration, IllustrationProvider, Input, InputChip, Link, LinkButton, Linksimple, List, Listheader, ListItem, Marker, MenuBar, MenuItem, MenuItemCheckbox, MenuItemRadio, MenuPopover, MenuSection, NavMenuItem, OptGroup, Option, Password, Popover, Presence, Progressbar, Progressspinner, Radio, RadioGroup, ScreenreaderAnnouncer, Searchfield, Searchpopover, Select, SelectListbox, SideNavigation, Skeleton, Spinner, StaticChip, StaticCheckbox, StaticRadio, StaticToggle, Stepper, StepperConnector, StepperItem, Tab, TabList, Text, Textarea, ThemeProvider, Toast, Toggle, Typewriter, ToggleTip, Tooltip, VirtualizedList, Combobox, Slider, ListBox, Banner, };
|
|
106
|
+
export { Accordion, AccordionButton, AccordionGroup, AlertChip, Animation, AnnouncementDialog, Appheader, Avatar, AvatarButton, Badge, Brandvisual, Bullet, Button, ButtonGroup, ButtonLink, Card, CardButton, CardCheckbox, CardRadio, Checkbox, Chip, Coachmark, ControlTypeProvider, Dialog, Divider, FilterChip, FormfieldGroup, Icon, IconProvider, Illustration, IllustrationProvider, Input, InputChip, Link, LinkButton, Linksimple, List, Listheader, ListItem, Marker, MenuBar, MenuItem, MenuItemCheckbox, MenuItemRadio, MenuPopover, MenuSection, NavMenuItem, OptGroup, Option, Password, Popover, Presence, Progressbar, Progressspinner, Radio, RadioGroup, ResponsiveSettingsProvider, ScreenreaderAnnouncer, Searchfield, Searchpopover, Select, SelectListbox, SideNavigation, Skeleton, Spinner, StaticChip, StaticCheckbox, StaticRadio, StaticToggle, Stepper, StepperConnector, StepperItem, Tab, TabList, Text, Textarea, ThemeProvider, Toast, Toggle, Typewriter, ToggleTip, Tooltip, VirtualizedList, Combobox, Slider, ListBox, Banner, };
|
|
106
107
|
export type { BadgeType, ButtonColor, ButtonVariant, IconButtonSize, MenuPopoverActionEvent, MenuPopoverChangeEvent, MenuSectionChangeEvent, PillButtonSize, PopoverPlacement, SkeletonVariant, SelectChangeEvent, SelectInputEvent, SpinnerSize, SpinnerVariant, SliderChangeEvent, TextType, TypewriterType, InputInputEvent, InputChangeEvent, InputFocusEvent, InputBlurEvent, InputClearEvent, VirtualizedListScrollEvent, TablistChangeEvent, TextareaInputEvent, TextareaChangeEvent, TextareaFocusEvent, TextareaBlurEvent, TextareaLimitExceededEvent, };
|
|
107
108
|
export { BUTTON_COLORS, BUTTON_VARIANTS, ICON_BUTTON_SIZES, inMemoryCache, PILL_BUTTON_SIZES, SKELETON_VARIANTS, webAPIAssetsCache, };
|
package/dist/index.js
CHANGED
|
@@ -56,6 +56,7 @@ import Progressbar from './components/progressbar';
|
|
|
56
56
|
import Progressspinner from './components/progressspinner';
|
|
57
57
|
import Radio from './components/radio';
|
|
58
58
|
import RadioGroup from './components/radiogroup';
|
|
59
|
+
import ResponsiveSettingsProvider from './components/responsivesettingsprovider';
|
|
59
60
|
import ScreenreaderAnnouncer from './components/screenreaderannouncer';
|
|
60
61
|
import Searchfield from './components/searchfield';
|
|
61
62
|
import Searchpopover from './components/searchpopover';
|
|
@@ -91,6 +92,6 @@ import { BUTTON_COLORS, BUTTON_VARIANTS, ICON_BUTTON_SIZES, PILL_BUTTON_SIZES, }
|
|
|
91
92
|
import { SKELETON_VARIANTS } from './components/skeleton/skeleton.constants';
|
|
92
93
|
import { inMemoryCache, webAPIAssetsCache } from './utils/assets-cache';
|
|
93
94
|
// Components Exports
|
|
94
|
-
export { Accordion, AccordionButton, AccordionGroup, AlertChip, Animation, AnnouncementDialog, Appheader, Avatar, AvatarButton, Badge, Brandvisual, Bullet, Button, ButtonGroup, ButtonLink, Card, CardButton, CardCheckbox, CardRadio, Checkbox, Chip, Coachmark, ControlTypeProvider, Dialog, Divider, FilterChip, FormfieldGroup, Icon, IconProvider, Illustration, IllustrationProvider, Input, InputChip, Link, LinkButton, Linksimple, List, Listheader, ListItem, Marker, MenuBar, MenuItem, MenuItemCheckbox, MenuItemRadio, MenuPopover, MenuSection, NavMenuItem, OptGroup, Option, Password, Popover, Presence, Progressbar, Progressspinner, Radio, RadioGroup, ScreenreaderAnnouncer, Searchfield, Searchpopover, Select, SelectListbox, SideNavigation, Skeleton, Spinner, StaticChip, StaticCheckbox, StaticRadio, StaticToggle, Stepper, StepperConnector, StepperItem, Tab, TabList, Text, Textarea, ThemeProvider, Toast, Toggle, Typewriter, ToggleTip, Tooltip, VirtualizedList, Combobox, Slider, ListBox, Banner, };
|
|
95
|
+
export { Accordion, AccordionButton, AccordionGroup, AlertChip, Animation, AnnouncementDialog, Appheader, Avatar, AvatarButton, Badge, Brandvisual, Bullet, Button, ButtonGroup, ButtonLink, Card, CardButton, CardCheckbox, CardRadio, Checkbox, Chip, Coachmark, ControlTypeProvider, Dialog, Divider, FilterChip, FormfieldGroup, Icon, IconProvider, Illustration, IllustrationProvider, Input, InputChip, Link, LinkButton, Linksimple, List, Listheader, ListItem, Marker, MenuBar, MenuItem, MenuItemCheckbox, MenuItemRadio, MenuPopover, MenuSection, NavMenuItem, OptGroup, Option, Password, Popover, Presence, Progressbar, Progressspinner, Radio, RadioGroup, ResponsiveSettingsProvider, ScreenreaderAnnouncer, Searchfield, Searchpopover, Select, SelectListbox, SideNavigation, Skeleton, Spinner, StaticChip, StaticCheckbox, StaticRadio, StaticToggle, Stepper, StepperConnector, StepperItem, Tab, TabList, Text, Textarea, ThemeProvider, Toast, Toggle, Typewriter, ToggleTip, Tooltip, VirtualizedList, Combobox, Slider, ListBox, Banner, };
|
|
95
96
|
// Constants / Utils Exports
|
|
96
97
|
export { BUTTON_COLORS, BUTTON_VARIANTS, ICON_BUTTON_SIZES, inMemoryCache, PILL_BUTTON_SIZES, SKELETON_VARIANTS, webAPIAssetsCache, };
|
package/dist/react/index.d.ts
CHANGED
|
@@ -2,19 +2,19 @@ export { default as Accordion } from './accordion';
|
|
|
2
2
|
export { default as AccordionButton } from './accordionbutton';
|
|
3
3
|
export { default as AccordionGroup } from './accordiongroup';
|
|
4
4
|
export { default as AlertChip } from './alertchip';
|
|
5
|
+
export { default as Animation } from './animation';
|
|
5
6
|
export { default as AnnouncementDialog } from './announcementdialog';
|
|
6
7
|
export { default as Appheader } from './appheader';
|
|
7
|
-
export { default as Animation } from './animation';
|
|
8
8
|
export { default as Avatar } from './avatar';
|
|
9
9
|
export { default as AvatarButton } from './avatarbutton';
|
|
10
10
|
export { default as Badge } from './badge';
|
|
11
11
|
export { default as Banner } from './banner';
|
|
12
12
|
export { default as Brandvisual } from './brandvisual';
|
|
13
|
-
export { default as Bullet } from './bullet';
|
|
14
13
|
export { default as Button } from './button';
|
|
14
|
+
export { default as Bullet } from './bullet';
|
|
15
15
|
export { default as ButtonGroup } from './buttongroup';
|
|
16
|
-
export { default as ButtonLink } from './buttonlink';
|
|
17
16
|
export { default as Buttonsimple } from './buttonsimple';
|
|
17
|
+
export { default as ButtonLink } from './buttonlink';
|
|
18
18
|
export { default as Card } from './card';
|
|
19
19
|
export { default as CardButton } from './cardbutton';
|
|
20
20
|
export { default as CardCheckbox } from './cardcheckbox';
|
|
@@ -44,8 +44,8 @@ export { default as Listheader } from './listheader';
|
|
|
44
44
|
export { default as ListItem } from './listitem';
|
|
45
45
|
export { default as Marker } from './marker';
|
|
46
46
|
export { default as MenuBar } from './menubar';
|
|
47
|
-
export { default as MenuItem } from './menuitem';
|
|
48
47
|
export { default as MenuItemCheckbox } from './menuitemcheckbox';
|
|
48
|
+
export { default as MenuItem } from './menuitem';
|
|
49
49
|
export { default as MenuItemRadio } from './menuitemradio';
|
|
50
50
|
export { default as MenuPopover } from './menupopover';
|
|
51
51
|
export { default as MenuSection } from './menusection';
|
|
@@ -59,6 +59,7 @@ export { default as Progressbar } from './progressbar';
|
|
|
59
59
|
export { default as Progressspinner } from './progressspinner';
|
|
60
60
|
export { default as Radio } from './radio';
|
|
61
61
|
export { default as RadioGroup } from './radiogroup';
|
|
62
|
+
export { default as ResponsiveSettingsProvider } from './responsivesettingsprovider';
|
|
62
63
|
export { default as ScreenreaderAnnouncer } from './screenreaderannouncer';
|
|
63
64
|
export { default as Searchfield } from './searchfield';
|
|
64
65
|
export { default as Searchpopover } from './searchpopover';
|
|
@@ -71,9 +72,9 @@ export { default as Spinner } from './spinner';
|
|
|
71
72
|
export { default as StaticCheckbox } from './staticcheckbox';
|
|
72
73
|
export { default as StaticChip } from './staticchip';
|
|
73
74
|
export { default as StaticRadio } from './staticradio';
|
|
74
|
-
export { default as StaticToggle } from './statictoggle';
|
|
75
75
|
export { default as Stepper } from './stepper';
|
|
76
76
|
export { default as StepperConnector } from './stepperconnector';
|
|
77
|
+
export { default as StaticToggle } from './statictoggle';
|
|
77
78
|
export { default as StepperItem } from './stepperitem';
|
|
78
79
|
export { default as Tab } from './tab';
|
|
79
80
|
export { default as TabList } from './tablist';
|
package/dist/react/index.js
CHANGED
|
@@ -2,19 +2,19 @@ export { default as Accordion } from './accordion';
|
|
|
2
2
|
export { default as AccordionButton } from './accordionbutton';
|
|
3
3
|
export { default as AccordionGroup } from './accordiongroup';
|
|
4
4
|
export { default as AlertChip } from './alertchip';
|
|
5
|
+
export { default as Animation } from './animation';
|
|
5
6
|
export { default as AnnouncementDialog } from './announcementdialog';
|
|
6
7
|
export { default as Appheader } from './appheader';
|
|
7
|
-
export { default as Animation } from './animation';
|
|
8
8
|
export { default as Avatar } from './avatar';
|
|
9
9
|
export { default as AvatarButton } from './avatarbutton';
|
|
10
10
|
export { default as Badge } from './badge';
|
|
11
11
|
export { default as Banner } from './banner';
|
|
12
12
|
export { default as Brandvisual } from './brandvisual';
|
|
13
|
-
export { default as Bullet } from './bullet';
|
|
14
13
|
export { default as Button } from './button';
|
|
14
|
+
export { default as Bullet } from './bullet';
|
|
15
15
|
export { default as ButtonGroup } from './buttongroup';
|
|
16
|
-
export { default as ButtonLink } from './buttonlink';
|
|
17
16
|
export { default as Buttonsimple } from './buttonsimple';
|
|
17
|
+
export { default as ButtonLink } from './buttonlink';
|
|
18
18
|
export { default as Card } from './card';
|
|
19
19
|
export { default as CardButton } from './cardbutton';
|
|
20
20
|
export { default as CardCheckbox } from './cardcheckbox';
|
|
@@ -44,8 +44,8 @@ export { default as Listheader } from './listheader';
|
|
|
44
44
|
export { default as ListItem } from './listitem';
|
|
45
45
|
export { default as Marker } from './marker';
|
|
46
46
|
export { default as MenuBar } from './menubar';
|
|
47
|
-
export { default as MenuItem } from './menuitem';
|
|
48
47
|
export { default as MenuItemCheckbox } from './menuitemcheckbox';
|
|
48
|
+
export { default as MenuItem } from './menuitem';
|
|
49
49
|
export { default as MenuItemRadio } from './menuitemradio';
|
|
50
50
|
export { default as MenuPopover } from './menupopover';
|
|
51
51
|
export { default as MenuSection } from './menusection';
|
|
@@ -59,6 +59,7 @@ export { default as Progressbar } from './progressbar';
|
|
|
59
59
|
export { default as Progressspinner } from './progressspinner';
|
|
60
60
|
export { default as Radio } from './radio';
|
|
61
61
|
export { default as RadioGroup } from './radiogroup';
|
|
62
|
+
export { default as ResponsiveSettingsProvider } from './responsivesettingsprovider';
|
|
62
63
|
export { default as ScreenreaderAnnouncer } from './screenreaderannouncer';
|
|
63
64
|
export { default as Searchfield } from './searchfield';
|
|
64
65
|
export { default as Searchpopover } from './searchpopover';
|
|
@@ -71,9 +72,9 @@ export { default as Spinner } from './spinner';
|
|
|
71
72
|
export { default as StaticCheckbox } from './staticcheckbox';
|
|
72
73
|
export { default as StaticChip } from './staticchip';
|
|
73
74
|
export { default as StaticRadio } from './staticradio';
|
|
74
|
-
export { default as StaticToggle } from './statictoggle';
|
|
75
75
|
export { default as Stepper } from './stepper';
|
|
76
76
|
export { default as StepperConnector } from './stepperconnector';
|
|
77
|
+
export { default as StaticToggle } from './statictoggle';
|
|
77
78
|
export { default as StepperItem } from './stepperitem';
|
|
78
79
|
export { default as Tab } from './tab';
|
|
79
80
|
export { default as TabList } from './tablist';
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import Component from '../../components/responsivesettingsprovider';
|
|
2
|
+
/**
|
|
3
|
+
* `mdc-responsivesettingsprovider` is a provider component that supplies responsive settings
|
|
4
|
+
* context to its child components.
|
|
5
|
+
*
|
|
6
|
+
* This component does not make any assumptions about how the values are determined. Values can be set
|
|
7
|
+
* based on media queries or other device detection mechanisms.This way consumer can mix and match
|
|
8
|
+
* different settings depending on their target devices and use cases.
|
|
9
|
+
*
|
|
10
|
+
* For example, when the device has table screen size/resolution, but because it is fixed dialog like
|
|
11
|
+
* popovers provide better user experience.
|
|
12
|
+
*
|
|
13
|
+
* ## Responsive settings
|
|
14
|
+
*
|
|
15
|
+
* ### Media
|
|
16
|
+
*
|
|
17
|
+
* Generic media type to enforce responsive behavior in child components.
|
|
18
|
+
* Consumer component can use the media type from the context or
|
|
19
|
+
* just use CSS selector like [media="mobile"] to apply responsive styles.
|
|
20
|
+
*
|
|
21
|
+
* It is "unknown" by default so components can fall back to there default behavior.
|
|
22
|
+
*
|
|
23
|
+
* ### Popover Positioning
|
|
24
|
+
*
|
|
25
|
+
* By default, popovers are positioned close to the trigger element. But on small screens (e.g.: mobile devices),
|
|
26
|
+
* it is often better to show popovers/menus at the center of the screen like dialogs.
|
|
27
|
+
*
|
|
28
|
+
* ### Force Fullscreen Dialog
|
|
29
|
+
*
|
|
30
|
+
* Some components like dialogs can be shown in fullscreen mode on small screens for better user experience.
|
|
31
|
+
*
|
|
32
|
+
* @tagname mdc-responsivesettingsprovider
|
|
33
|
+
*/
|
|
34
|
+
declare const reactWrapper: import("@lit/react").ReactWebComponent<Component, {}>;
|
|
35
|
+
export default reactWrapper;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { createComponent } from '@lit/react';
|
|
3
|
+
import Component from '../../components/responsivesettingsprovider';
|
|
4
|
+
import { TAG_NAME } from '../../components/responsivesettingsprovider/responsivesettingsprovider.constants';
|
|
5
|
+
/**
|
|
6
|
+
* `mdc-responsivesettingsprovider` is a provider component that supplies responsive settings
|
|
7
|
+
* context to its child components.
|
|
8
|
+
*
|
|
9
|
+
* This component does not make any assumptions about how the values are determined. Values can be set
|
|
10
|
+
* based on media queries or other device detection mechanisms.This way consumer can mix and match
|
|
11
|
+
* different settings depending on their target devices and use cases.
|
|
12
|
+
*
|
|
13
|
+
* For example, when the device has table screen size/resolution, but because it is fixed dialog like
|
|
14
|
+
* popovers provide better user experience.
|
|
15
|
+
*
|
|
16
|
+
* ## Responsive settings
|
|
17
|
+
*
|
|
18
|
+
* ### Media
|
|
19
|
+
*
|
|
20
|
+
* Generic media type to enforce responsive behavior in child components.
|
|
21
|
+
* Consumer component can use the media type from the context or
|
|
22
|
+
* just use CSS selector like [media="mobile"] to apply responsive styles.
|
|
23
|
+
*
|
|
24
|
+
* It is "unknown" by default so components can fall back to there default behavior.
|
|
25
|
+
*
|
|
26
|
+
* ### Popover Positioning
|
|
27
|
+
*
|
|
28
|
+
* By default, popovers are positioned close to the trigger element. But on small screens (e.g.: mobile devices),
|
|
29
|
+
* it is often better to show popovers/menus at the center of the screen like dialogs.
|
|
30
|
+
*
|
|
31
|
+
* ### Force Fullscreen Dialog
|
|
32
|
+
*
|
|
33
|
+
* Some components like dialogs can be shown in fullscreen mode on small screens for better user experience.
|
|
34
|
+
*
|
|
35
|
+
* @tagname mdc-responsivesettingsprovider
|
|
36
|
+
*/
|
|
37
|
+
const reactWrapper = createComponent({
|
|
38
|
+
tagName: TAG_NAME,
|
|
39
|
+
elementClass: Component,
|
|
40
|
+
react: React,
|
|
41
|
+
events: {},
|
|
42
|
+
displayName: 'ResponsiveSettingsProvider',
|
|
43
|
+
});
|
|
44
|
+
export default reactWrapper;
|
|
@@ -135,6 +135,16 @@ export declare class ElementStore<TItem extends HTMLElement> implements Reactive
|
|
|
135
135
|
* @param index - The index at which to add the item.
|
|
136
136
|
*/
|
|
137
137
|
addAt(newItem: Element, index: number): void;
|
|
138
|
+
/**
|
|
139
|
+
* Implements binary search on the cache, to get the index of the nearest newItem position.
|
|
140
|
+
*
|
|
141
|
+
* @param cache - The array which contains the list of dom node elements.
|
|
142
|
+
* @param newItem - The new node element which is needed to be added in the list item.
|
|
143
|
+
* @returns either:
|
|
144
|
+
* - the index where the new item need to be inserted or
|
|
145
|
+
* - -1 when the item must be appended to the end of the list item.
|
|
146
|
+
*/
|
|
147
|
+
private getIndexToInsertInCache;
|
|
138
148
|
/**
|
|
139
149
|
* Adds an item to the cache at the specified index.
|
|
140
150
|
* When the index
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { LIFE_CYCLE_EVENTS } from '../mixins/lifecycle/lifecycle.contants';
|
|
2
|
-
import { isBefore } from '../dom';
|
|
2
|
+
import { isAfter, isBefore } from '../dom';
|
|
3
3
|
const defaultIsValidFn = (item) => !!item;
|
|
4
4
|
/**
|
|
5
5
|
* ElementStore is a controller that manages a collection of elements.
|
|
@@ -133,6 +133,34 @@ export class ElementStore {
|
|
|
133
133
|
addAt(newItem, index) {
|
|
134
134
|
this.addItem(newItem, index);
|
|
135
135
|
}
|
|
136
|
+
/**
|
|
137
|
+
* Implements binary search on the cache, to get the index of the nearest newItem position.
|
|
138
|
+
*
|
|
139
|
+
* @param cache - The array which contains the list of dom node elements.
|
|
140
|
+
* @param newItem - The new node element which is needed to be added in the list item.
|
|
141
|
+
* @returns either:
|
|
142
|
+
* - the index where the new item need to be inserted or
|
|
143
|
+
* - -1 when the item must be appended to the end of the list item.
|
|
144
|
+
*/
|
|
145
|
+
getIndexToInsertInCache(newItem) {
|
|
146
|
+
// If the new item is located at the last place, then we can check the last -1 cache item and return if valid
|
|
147
|
+
if (!this.cache.length || !isAfter(this.cache.at(-1), newItem)) {
|
|
148
|
+
return -1;
|
|
149
|
+
}
|
|
150
|
+
// Fall back to binary search
|
|
151
|
+
let begin = 0;
|
|
152
|
+
let end = this.cache.length - 1;
|
|
153
|
+
while (begin <= end) {
|
|
154
|
+
const middle = Math.floor((begin + end) / 2);
|
|
155
|
+
if (isBefore(this.cache[middle], newItem)) {
|
|
156
|
+
begin = middle + 1;
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
end = middle - 1;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return begin;
|
|
163
|
+
}
|
|
136
164
|
/**
|
|
137
165
|
* Adds an item to the cache at the specified index.
|
|
138
166
|
* When the index
|
|
@@ -148,7 +176,7 @@ export class ElementStore {
|
|
|
148
176
|
var _a;
|
|
149
177
|
const newItem = item;
|
|
150
178
|
if (this.isValidItem(newItem) && !this.cache.includes(newItem)) {
|
|
151
|
-
const idx = index === undefined ? this.
|
|
179
|
+
const idx = index === undefined ? this.getIndexToInsertInCache(newItem) : index;
|
|
152
180
|
if (this.onStoreUpdate) {
|
|
153
181
|
(_a = this.onStoreUpdate) === null || _a === void 0 ? void 0 : _a.call(this, newItem, 'added', idx === -1 ? this.cache.length : idx, this.cache.slice());
|
|
154
182
|
}
|
package/dist/utils/dom.d.ts
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* nodeB precedes nodeA in either a pre-order depth-first traversal of a tree containing both
|
|
3
|
+
* (e.g., as a descendant or preceding sibling or a descendant of a preceding sibling or
|
|
4
|
+
* preceding sibling of an ancestor) or (if they are disconnected) in an arbitrary but
|
|
5
|
+
* consistent ordering.
|
|
6
|
+
*
|
|
7
|
+
* @param nodeA - The first node to compare.
|
|
8
|
+
* @param nodeB - The second node to compare.
|
|
9
|
+
* @returns - True if nodeA is after nodeB, false otherwise.
|
|
10
|
+
*
|
|
11
|
+
* @see [compareDocumentPosition](https://developer.mozilla.org/en-US/docs/Web/API/Node/compareDocumentPosition)
|
|
12
|
+
*/
|
|
13
|
+
export declare const isAfter: (nodeA: Element, nodeB: Element) => boolean;
|
|
1
14
|
/**
|
|
2
15
|
* nodeB follows nodeA in either a pre-order depth-first traversal of a tree containing both
|
|
3
16
|
* (e.g., as a descendant or following sibling or a descendant of a following sibling or
|
package/dist/utils/dom.js
CHANGED
|
@@ -1,4 +1,17 @@
|
|
|
1
1
|
/* eslint-disable max-classes-per-file,no-bitwise */
|
|
2
|
+
/**
|
|
3
|
+
* nodeB precedes nodeA in either a pre-order depth-first traversal of a tree containing both
|
|
4
|
+
* (e.g., as a descendant or preceding sibling or a descendant of a preceding sibling or
|
|
5
|
+
* preceding sibling of an ancestor) or (if they are disconnected) in an arbitrary but
|
|
6
|
+
* consistent ordering.
|
|
7
|
+
*
|
|
8
|
+
* @param nodeA - The first node to compare.
|
|
9
|
+
* @param nodeB - The second node to compare.
|
|
10
|
+
* @returns - True if nodeA is after nodeB, false otherwise.
|
|
11
|
+
*
|
|
12
|
+
* @see [compareDocumentPosition](https://developer.mozilla.org/en-US/docs/Web/API/Node/compareDocumentPosition)
|
|
13
|
+
*/
|
|
14
|
+
export const isAfter = (nodeA, nodeB) => !!(nodeA.compareDocumentPosition(nodeB) & Node.DOCUMENT_POSITION_PRECEDING);
|
|
2
15
|
/**
|
|
3
16
|
* nodeB follows nodeA in either a pre-order depth-first traversal of a tree containing both
|
|
4
17
|
* (e.g., as a descendant or following sibling or a descendant of a following sibling or
|