@momentum-design/components 0.124.1 → 0.125.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/dist/browser/index.js +161 -161
- package/dist/browser/index.js.map +3 -3
- package/dist/custom-elements.json +369 -369
- package/dist/react/index.d.ts +2 -2
- package/dist/react/index.js +2 -2
- 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/react/index.d.ts
CHANGED
|
@@ -9,8 +9,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
|
-
export { default as Bullet } from './bullet';
|
|
13
12
|
export { default as Brandvisual } from './brandvisual';
|
|
13
|
+
export { default as Bullet } from './bullet';
|
|
14
14
|
export { default as Button } from './button';
|
|
15
15
|
export { default as ButtonGroup } from './buttongroup';
|
|
16
16
|
export { default as ButtonLink } from './buttonlink';
|
|
@@ -74,9 +74,9 @@ export { default as StaticRadio } from './staticradio';
|
|
|
74
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 StepperItem } from './stepperitem';
|
|
78
77
|
export { default as Tab } from './tab';
|
|
79
78
|
export { default as TabList } from './tablist';
|
|
79
|
+
export { default as StepperItem } from './stepperitem';
|
|
80
80
|
export { default as Text } from './text';
|
|
81
81
|
export { default as Textarea } from './textarea';
|
|
82
82
|
export { default as ThemeProvider } from './themeprovider';
|
package/dist/react/index.js
CHANGED
|
@@ -9,8 +9,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
|
-
export { default as Bullet } from './bullet';
|
|
13
12
|
export { default as Brandvisual } from './brandvisual';
|
|
13
|
+
export { default as Bullet } from './bullet';
|
|
14
14
|
export { default as Button } from './button';
|
|
15
15
|
export { default as ButtonGroup } from './buttongroup';
|
|
16
16
|
export { default as ButtonLink } from './buttonlink';
|
|
@@ -74,9 +74,9 @@ export { default as StaticRadio } from './staticradio';
|
|
|
74
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 StepperItem } from './stepperitem';
|
|
78
77
|
export { default as Tab } from './tab';
|
|
79
78
|
export { default as TabList } from './tablist';
|
|
79
|
+
export { default as StepperItem } from './stepperitem';
|
|
80
80
|
export { default as Text } from './text';
|
|
81
81
|
export { default as Textarea } from './textarea';
|
|
82
82
|
export { default as ThemeProvider } from './themeprovider';
|
|
@@ -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
|