@mustib/web-components 0.0.0-alpha.5 → 0.0.0-alpha.7
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/common-BBjg-zl9.js +604 -0
- package/components/mu-element.d.ts +3 -1
- package/components/mu-element.js +2 -1
- package/components/mu-icon.d.ts +4 -0
- package/components/mu-icon.js +14 -1
- package/components/mu-range-fill.js +2 -1
- package/components/mu-range-thumb-value.js +2 -1
- package/components/mu-range-thumb.js +2 -1
- package/components/mu-range.d.ts +46 -1
- package/components/mu-range.js +97 -19
- package/components/mu-select-item.js +2 -1
- package/components/mu-select-items.js +2 -1
- package/components/mu-select-label-content.js +2 -1
- package/components/mu-select-label.js +2 -1
- package/components/mu-select.js +2 -1
- package/components/mu-sortable-item.js +2 -1
- package/components/mu-sortable-trigger.js +2 -1
- package/components/mu-sortable.js +2 -1
- package/components/mu-toast-item.d.ts +6 -0
- package/components/mu-toast-item.js +229 -0
- package/components/mu-toast.d.ts +6 -0
- package/components/mu-toast.js +216 -0
- package/components/mu-transparent.js +2 -1
- package/components/mu-trigger.js +2 -1
- package/constants-DPnKJ57t.js +8 -0
- package/index.d.ts +9 -2
- package/index.js +11 -1
- package/{mu-element-CEvBHYiI.js → mu-element-yEZ17QUl.js} +2 -195
- package/mu-toast-DfNHcc7U.d.ts +276 -0
- package/package.json +7 -2
- package/utils/Toast.d.ts +6 -0
- package/utils/Toast.js +321 -0
- package/utils/ToastController.d.ts +6 -0
- package/utils/ToastController.js +189 -0
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import { M as MuElement, _ as __decorate } from '../mu-element-yEZ17QUl.js';
|
|
2
|
+
import { css, html } from 'lit';
|
|
3
|
+
import { property } from 'lit/decorators.js';
|
|
4
|
+
import { repeat } from 'lit/directives/repeat.js';
|
|
5
|
+
import './mu-toast-item.js';
|
|
6
|
+
import { ToastController } from '../utils/ToastController.js';
|
|
7
|
+
import '../common-BBjg-zl9.js';
|
|
8
|
+
import './mu-icon.js';
|
|
9
|
+
import 'lit/directive-helpers.js';
|
|
10
|
+
import '../constants-DPnKJ57t.js';
|
|
11
|
+
import '../utils/Toast.js';
|
|
12
|
+
|
|
13
|
+
class MuToast extends MuElement {
|
|
14
|
+
constructor() {
|
|
15
|
+
super(...arguments);
|
|
16
|
+
this.controller = new ToastController(this);
|
|
17
|
+
this.position = 'top-center';
|
|
18
|
+
this.autoReParent = false;
|
|
19
|
+
this._topLayerElements = new Set();
|
|
20
|
+
this._fullscreenElement = null;
|
|
21
|
+
this.autoReParentObserver = new MutationObserver((mutations) => {
|
|
22
|
+
for (const mutation of mutations) {
|
|
23
|
+
if (mutation.type === 'attributes' &&
|
|
24
|
+
mutation.attributeName === 'open' &&
|
|
25
|
+
mutation.target instanceof HTMLDialogElement) {
|
|
26
|
+
if (mutation.target.open)
|
|
27
|
+
this.addTopLayerElement(mutation.target);
|
|
28
|
+
else
|
|
29
|
+
this.removeTopLayerElement(mutation.target);
|
|
30
|
+
}
|
|
31
|
+
if (mutation.removedNodes.length) {
|
|
32
|
+
mutation.removedNodes.forEach((node) => {
|
|
33
|
+
if (this._topLayerElements.has(node))
|
|
34
|
+
this.removeTopLayerElement(node);
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
this.fullscreenReParentHandler = () => {
|
|
40
|
+
if (document.fullscreenElement) {
|
|
41
|
+
if (this._fullscreenElement)
|
|
42
|
+
this._topLayerElements.delete(this._fullscreenElement);
|
|
43
|
+
this._fullscreenElement = document.fullscreenElement;
|
|
44
|
+
this.addTopLayerElement(document.fullscreenElement);
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
this.removeTopLayerElement(this._fullscreenElement);
|
|
48
|
+
this._fullscreenElement = null;
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
setIsEmpty(status) {
|
|
53
|
+
if (status)
|
|
54
|
+
this.setAttribute('empty', '');
|
|
55
|
+
else
|
|
56
|
+
this.removeAttribute('empty');
|
|
57
|
+
}
|
|
58
|
+
addTopLayerElement(element) {
|
|
59
|
+
this._topLayerElements.add(element);
|
|
60
|
+
this.controller.reParent(element);
|
|
61
|
+
this.controller.popover();
|
|
62
|
+
}
|
|
63
|
+
removeTopLayerElement(element) {
|
|
64
|
+
element && this._topLayerElements.delete(element);
|
|
65
|
+
const nextLayer = [...this._topLayerElements].pop() || document.body;
|
|
66
|
+
this.controller.reParent(nextLayer);
|
|
67
|
+
this.controller.popover();
|
|
68
|
+
}
|
|
69
|
+
willUpdate(_changedProperties) {
|
|
70
|
+
super.willUpdate(_changedProperties);
|
|
71
|
+
this.setIsEmpty(this.controller.toastsQueue.length === 0);
|
|
72
|
+
}
|
|
73
|
+
connectedCallback() {
|
|
74
|
+
super.connectedCallback();
|
|
75
|
+
if (this.autoReParent) {
|
|
76
|
+
document.addEventListener('fullscreenchange', this.fullscreenReParentHandler);
|
|
77
|
+
this.autoReParentObserver.observe(document.body, {
|
|
78
|
+
attributes: true,
|
|
79
|
+
childList: true,
|
|
80
|
+
subtree: true,
|
|
81
|
+
attributeFilter: ['open'],
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
disconnectedCallback() {
|
|
86
|
+
super.disconnectedCallback();
|
|
87
|
+
document.removeEventListener('fullscreenchange', this.fullscreenReParentHandler);
|
|
88
|
+
this.autoReParentObserver.disconnect();
|
|
89
|
+
}
|
|
90
|
+
render() {
|
|
91
|
+
const toastsArray = [...this.controller.toastsQueue];
|
|
92
|
+
/**
|
|
93
|
+
* reverse for top position so new toasts stack on top
|
|
94
|
+
*/
|
|
95
|
+
if (this.position.startsWith('top'))
|
|
96
|
+
toastsArray.reverse();
|
|
97
|
+
const toasts = repeat(toastsArray, (toast) => toast.id, (toast, i) => {
|
|
98
|
+
return html `
|
|
99
|
+
<mu-toast-item
|
|
100
|
+
class="toast"
|
|
101
|
+
style="
|
|
102
|
+
--bottom-index: ${toastsArray.length - i};
|
|
103
|
+
--top-index: ${i + 1};
|
|
104
|
+
direction:${toast.direction};
|
|
105
|
+
"
|
|
106
|
+
exportparts='
|
|
107
|
+
container: toast-item-container,
|
|
108
|
+
label-icon: toast-item-label-icon,
|
|
109
|
+
content: toast-item-content,
|
|
110
|
+
label: toast-item-label,
|
|
111
|
+
message: toast-item-message,
|
|
112
|
+
spinner: toast-item-spinner,
|
|
113
|
+
action-btn: toast-item-action-btn,
|
|
114
|
+
close-btn: toast-item-close-btn,
|
|
115
|
+
progress: toast-item-progress,
|
|
116
|
+
'
|
|
117
|
+
.toast=${toast}
|
|
118
|
+
></mu-toast-item>
|
|
119
|
+
`;
|
|
120
|
+
});
|
|
121
|
+
return html `
|
|
122
|
+
<div
|
|
123
|
+
id="container"
|
|
124
|
+
part="container"
|
|
125
|
+
?stack-toasts=${this.controller.stackToasts}
|
|
126
|
+
>
|
|
127
|
+
<slot name="before"></slot>
|
|
128
|
+
${toasts}
|
|
129
|
+
<slot name="after"></slot>
|
|
130
|
+
</div>
|
|
131
|
+
`;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
MuToast.styles = [
|
|
135
|
+
MuElement.cssBase,
|
|
136
|
+
css `
|
|
137
|
+
#container {
|
|
138
|
+
display: grid;
|
|
139
|
+
justify-content: center;
|
|
140
|
+
position: fixed;
|
|
141
|
+
inset: 5%;
|
|
142
|
+
height: fit-content;
|
|
143
|
+
gap: var(--mu-base-rem);
|
|
144
|
+
width: fit-content;
|
|
145
|
+
font-weight: normal;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
.toast {
|
|
149
|
+
transition: translate 150ms;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
#container:hover :where(.toast) {
|
|
153
|
+
translate: 0;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
:host([position^="top"]) :where(#container) {
|
|
157
|
+
align-content: start;
|
|
158
|
+
margin-bottom: auto;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
:host([position^="bottom"]) :where(#container) {
|
|
162
|
+
align-content: end;
|
|
163
|
+
margin-top: auto;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
:host([position="bottom-center"]) :where(#container),
|
|
167
|
+
:host([position="top-center"]) :where(#container) {
|
|
168
|
+
margin-inline: auto;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
:host([position="bottom-end"]) :where(#container),
|
|
172
|
+
:host([position="top-end"]) :where(#container) {
|
|
173
|
+
margin-inline-start: auto;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
:host([position="bottom-start"]) :where(#container),
|
|
177
|
+
:host([position="top-start"]) :where(#container) {
|
|
178
|
+
margin-inline-end: auto;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/* for reversed toasts array to work on top positions */
|
|
182
|
+
:host([position^="top"]) :where(.toast) {
|
|
183
|
+
z-index: var(--bottom-index);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/* Stacking */
|
|
187
|
+
:host([position^="top"])
|
|
188
|
+
:where(
|
|
189
|
+
#container[stack-toasts] .toast:nth-of-type(n + 2)
|
|
190
|
+
) {
|
|
191
|
+
translate: 0 calc(-100% * (var(--top-index) - 1));
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
:host([position^="bottom"])
|
|
195
|
+
:where(
|
|
196
|
+
#container[stack-toasts] .toast:not(:last-of-type)
|
|
197
|
+
) {
|
|
198
|
+
translate: 0 calc(100% * (var(--bottom-index) - 1));
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
@media (prefers-reduced-motion: reduce) {
|
|
202
|
+
.toast {
|
|
203
|
+
transition: none;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
`,
|
|
207
|
+
];
|
|
208
|
+
__decorate([
|
|
209
|
+
property({ type: String, attribute: 'position', reflect: true })
|
|
210
|
+
], MuToast.prototype, "position", void 0);
|
|
211
|
+
__decorate([
|
|
212
|
+
property({ type: Boolean, attribute: 'auto-re-parent' })
|
|
213
|
+
], MuToast.prototype, "autoReParent", void 0);
|
|
214
|
+
MuToast.register('mu-toast');
|
|
215
|
+
|
|
216
|
+
export { MuToast };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { _ as __decorate, M as MuElement } from '../mu-element-
|
|
1
|
+
import { _ as __decorate, M as MuElement } from '../mu-element-yEZ17QUl.js';
|
|
2
2
|
import { css, html } from 'lit';
|
|
3
3
|
import { property } from 'lit/decorators.js';
|
|
4
|
+
import '../common-BBjg-zl9.js';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* A base class for "transparent" wrapper components.
|
package/components/mu-trigger.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { _ as __decorate
|
|
1
|
+
import { _ as __decorate } from '../mu-element-yEZ17QUl.js';
|
|
2
|
+
import { p as parseJson } from '../common-BBjg-zl9.js';
|
|
2
3
|
import { property } from 'lit/decorators.js';
|
|
3
4
|
import { MuTransparent } from './mu-transparent.js';
|
|
4
5
|
import 'lit';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Symbol used to lock internal toast events.
|
|
3
|
+
* Prevents external code from dispatching state-changing events,
|
|
4
|
+
* ensuring only the Toast and ToastController can manage lifecycle.
|
|
5
|
+
*/
|
|
6
|
+
const TOAST_LOCK_SYMBOL = Symbol('toast-lock');
|
|
7
|
+
|
|
8
|
+
export { TOAST_LOCK_SYMBOL as T };
|
package/index.d.ts
CHANGED
|
@@ -19,8 +19,12 @@ export { MuSelectLabel } from './components/mu-select-label.js';
|
|
|
19
19
|
import { MuSelectLabelContentComponent } from './components/mu-select-label-content.js';
|
|
20
20
|
export { MuSelectLabelContent } from './components/mu-select-label-content.js';
|
|
21
21
|
import { MuSortableComponent } from './components/mu-sortable.js';
|
|
22
|
+
export { MuSortable } from './components/mu-sortable.js';
|
|
22
23
|
import { MuSortableItemComponent } from './components/mu-sortable-item.js';
|
|
23
|
-
|
|
24
|
+
export { MuSortableItem } from './components/mu-sortable-item.js';
|
|
25
|
+
export { MuSortableTrigger } from './components/mu-sortable-trigger.js';
|
|
26
|
+
import { M as MuToastComponent, a as MuToastItemComponent } from './mu-toast-DfNHcc7U.js';
|
|
27
|
+
export { A as AnimationKeyframes, L as LockedEvent, b as MuToast, c as MuToastItem, T as Toast, d as ToastController, e as ToastData } from './mu-toast-DfNHcc7U.js';
|
|
24
28
|
import { MuTransparentComponent } from './components/mu-transparent.js';
|
|
25
29
|
export { MuTransparent } from './components/mu-transparent.js';
|
|
26
30
|
import { MuTriggerComponent } from './components/mu-trigger.js';
|
|
@@ -28,6 +32,7 @@ export { MuTrigger } from './components/mu-trigger.js';
|
|
|
28
32
|
export { MuElement, MuElementComponent } from './components/mu-element.js';
|
|
29
33
|
import 'lit';
|
|
30
34
|
import '@mustib/utils/browser';
|
|
35
|
+
import '@mustib/utils';
|
|
31
36
|
|
|
32
37
|
type ComponentsAttributes = {
|
|
33
38
|
'mu-select': MuSelectComponent['attributes'];
|
|
@@ -44,10 +49,12 @@ type ComponentsAttributes = {
|
|
|
44
49
|
'mu-trigger': MuTriggerComponent['attributes'];
|
|
45
50
|
'mu-sortable': MuSortableComponent['attributes'];
|
|
46
51
|
'mu-sortable-item': MuSortableItemComponent['attributes'];
|
|
52
|
+
'mu-toast': MuToastComponent['attributes'];
|
|
53
|
+
'mu-toast-item': MuToastItemComponent['attributes'];
|
|
47
54
|
};
|
|
48
55
|
type MuComponentsAttributes<GlobalAttributes = Record<string, any>> = {
|
|
49
56
|
[key in keyof ComponentsAttributes]: Partial<ComponentsAttributes[key]> & GlobalAttributes;
|
|
50
57
|
};
|
|
51
58
|
|
|
52
|
-
export { MuIconComponent, MuRangeComponent, MuRangeFillComponent, MuRangeThumbComponent, MuRangeThumbValueComponent, MuSelectComponent, MuSelectItemComponent, MuSelectItemsComponent, MuSelectLabelComponent, MuSelectLabelContentComponent, MuTransparentComponent, MuTriggerComponent };
|
|
59
|
+
export { MuIconComponent, MuRangeComponent, MuRangeFillComponent, MuRangeThumbComponent, MuRangeThumbValueComponent, MuSelectComponent, MuSelectItemComponent, MuSelectItemsComponent, MuSelectLabelComponent, MuSelectLabelContentComponent, MuSortableComponent, MuSortableItemComponent, MuToastComponent, MuToastItemComponent, MuTransparentComponent, MuTriggerComponent };
|
|
53
60
|
export type { MuComponentsAttributes };
|
package/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { M as MuElement } from './mu-element-
|
|
1
|
+
export { M as MuElement } from './mu-element-yEZ17QUl.js';
|
|
2
2
|
export { MuIcon } from './components/mu-icon.js';
|
|
3
3
|
export { MuRange } from './components/mu-range.js';
|
|
4
4
|
export { MuRangeFill } from './components/mu-range-fill.js';
|
|
@@ -9,8 +9,18 @@ export { MuSelectItem } from './components/mu-select-item.js';
|
|
|
9
9
|
export { MuSelectItems } from './components/mu-select-items.js';
|
|
10
10
|
export { MuSelectLabel } from './components/mu-select-label.js';
|
|
11
11
|
export { MuSelectLabelContent } from './components/mu-select-label-content.js';
|
|
12
|
+
export { MuSortable } from './components/mu-sortable.js';
|
|
13
|
+
export { MuSortableItem } from './components/mu-sortable-item.js';
|
|
14
|
+
export { MuSortableTrigger } from './components/mu-sortable-trigger.js';
|
|
15
|
+
export { MuToast } from './components/mu-toast.js';
|
|
16
|
+
export { MuToastItem } from './components/mu-toast-item.js';
|
|
17
|
+
export { Toast } from './utils/Toast.js';
|
|
18
|
+
export { ToastController } from './utils/ToastController.js';
|
|
12
19
|
export { MuTransparent } from './components/mu-transparent.js';
|
|
13
20
|
export { MuTrigger } from './components/mu-trigger.js';
|
|
21
|
+
import './common-BBjg-zl9.js';
|
|
14
22
|
import 'lit';
|
|
15
23
|
import 'lit/decorators.js';
|
|
16
24
|
import 'lit/directives/repeat.js';
|
|
25
|
+
import 'lit/directive-helpers.js';
|
|
26
|
+
import './constants-DPnKJ57t.js';
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { p as parseJson, A as AppError, L as LIBRARY_ERROR_SCOPE } from './common-BBjg-zl9.js';
|
|
1
2
|
import { css, LitElement } from 'lit';
|
|
2
3
|
import { property } from 'lit/decorators.js';
|
|
3
4
|
|
|
@@ -36,200 +37,6 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
36
37
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
37
38
|
};
|
|
38
39
|
|
|
39
|
-
const capitalizeFirst = (str) => str[0].toUpperCase().concat(str.slice(1).toLowerCase());
|
|
40
|
-
/**
|
|
41
|
-
* Capitalizes the first letter of a string or each word in a string.
|
|
42
|
-
*
|
|
43
|
-
* @param {string} str - The string to capitalize.
|
|
44
|
-
* @param {object} [options] - Optional parameters.
|
|
45
|
-
* @param {boolean} [options.onlyFirstWord=false] - Whether to capitalize only the first word (default: false).
|
|
46
|
-
* @param {string} [options.splitter=' '] - The delimiter to split the string into words (default: ' ').
|
|
47
|
-
* @param {string} [options.joiner=options.splitter] - The delimiter to join the capitalized words (default: options.splitter).
|
|
48
|
-
* @returns {string} The capitalized string.
|
|
49
|
-
*/
|
|
50
|
-
function capitalize(str, options) {
|
|
51
|
-
const { onlyFirstWord: onlyFirst = false, splitter = ' ', joiner = splitter, } = options || {};
|
|
52
|
-
if (typeof str !== 'string' || str === '')
|
|
53
|
-
return str;
|
|
54
|
-
return (onlyFirst ? [str] : str.split(splitter))
|
|
55
|
-
.map(capitalizeFirst)
|
|
56
|
-
.join(joiner);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
class AppError extends Error {
|
|
60
|
-
options;
|
|
61
|
-
static throw(type, error, options) {
|
|
62
|
-
return new AppError(options)
|
|
63
|
-
.push(type, error, options?.pushOptions)
|
|
64
|
-
.throw();
|
|
65
|
-
}
|
|
66
|
-
static async aggregate(aggregateFunc, options) {
|
|
67
|
-
const appError = new AppError(options);
|
|
68
|
-
try {
|
|
69
|
-
await aggregateFunc(appError);
|
|
70
|
-
appError.end();
|
|
71
|
-
}
|
|
72
|
-
catch (error) {
|
|
73
|
-
if (error instanceof Error) {
|
|
74
|
-
Error.captureStackTrace(error, options?.stackTraceConstructor ?? AppError.aggregate);
|
|
75
|
-
}
|
|
76
|
-
throw error;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
length = 0;
|
|
80
|
-
errors = {};
|
|
81
|
-
get message() {
|
|
82
|
-
return this.toString();
|
|
83
|
-
}
|
|
84
|
-
constructor(options) {
|
|
85
|
-
super();
|
|
86
|
-
this.options = options;
|
|
87
|
-
}
|
|
88
|
-
async catch(catchFunc) {
|
|
89
|
-
try {
|
|
90
|
-
await catchFunc();
|
|
91
|
-
}
|
|
92
|
-
catch (error) {
|
|
93
|
-
if (error instanceof AppError) {
|
|
94
|
-
for (const [type, errors] of Object.entries(error.errors)) {
|
|
95
|
-
if (errors)
|
|
96
|
-
errors.forEach((err) => this.push(type, err.message, { scope: err.scope }));
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
else {
|
|
100
|
-
if (error instanceof Error) {
|
|
101
|
-
Error.captureStackTrace(error, this.catch);
|
|
102
|
-
}
|
|
103
|
-
throw error;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
toString(options) {
|
|
108
|
-
const formattedErrors = [];
|
|
109
|
-
Object.keys(this.errors).forEach((errorType) => {
|
|
110
|
-
const rawErrors = this.errors[errorType];
|
|
111
|
-
if (!rawErrors)
|
|
112
|
-
return;
|
|
113
|
-
const { indentation = 4 } = this.options || {};
|
|
114
|
-
const formattedErrorType = rawErrors.reduce((result, err) => {
|
|
115
|
-
const hasMatchedScope = this.matchesScope({
|
|
116
|
-
errScope: err.scope,
|
|
117
|
-
includesScope: options?.includesScope,
|
|
118
|
-
excludesScope: options?.excludesScope,
|
|
119
|
-
});
|
|
120
|
-
if (hasMatchedScope) {
|
|
121
|
-
result.push(`${result.length + 1}- ${err.message}.`);
|
|
122
|
-
}
|
|
123
|
-
return result;
|
|
124
|
-
}, []);
|
|
125
|
-
const hasManyErrors = formattedErrorType.length > 1;
|
|
126
|
-
const indentationPrefix = `${' '.repeat(indentation)}`;
|
|
127
|
-
if (formattedErrorType.length > 0)
|
|
128
|
-
formattedErrors.push(`${errorType} Error${hasManyErrors ? 's' : ''}:\n${indentationPrefix}${formattedErrorType.join(`\n${indentationPrefix}`)}`);
|
|
129
|
-
});
|
|
130
|
-
return formattedErrors.join('\n');
|
|
131
|
-
}
|
|
132
|
-
matchesScope({ errScope, includesScope, excludesScope, }) {
|
|
133
|
-
if (includesScope === undefined && excludesScope === undefined)
|
|
134
|
-
return true;
|
|
135
|
-
if (errScope === undefined)
|
|
136
|
-
return false;
|
|
137
|
-
if (excludesScope) {
|
|
138
|
-
return !excludesScope.some((scope) => errScope.includes(scope));
|
|
139
|
-
}
|
|
140
|
-
if (includesScope) {
|
|
141
|
-
return includesScope.some((scope) => errScope.includes(scope));
|
|
142
|
-
}
|
|
143
|
-
return false;
|
|
144
|
-
}
|
|
145
|
-
push(type, error, options) {
|
|
146
|
-
const errorType = capitalize(type, { onlyFirstWord: true });
|
|
147
|
-
const errors = this.errors[errorType];
|
|
148
|
-
const newError = Array.isArray(error)
|
|
149
|
-
? error.map((err) => ({ message: err, scope: options?.scope }))
|
|
150
|
-
: [{ message: error, scope: options?.scope }];
|
|
151
|
-
if (Array.isArray(errors)) {
|
|
152
|
-
errors.push(...newError);
|
|
153
|
-
}
|
|
154
|
-
else {
|
|
155
|
-
this.errors[errorType] = newError;
|
|
156
|
-
this.length++;
|
|
157
|
-
}
|
|
158
|
-
return this;
|
|
159
|
-
}
|
|
160
|
-
throw() {
|
|
161
|
-
Error.captureStackTrace(this, this.options?.stackTraceConstructor || this.throw);
|
|
162
|
-
throw this;
|
|
163
|
-
}
|
|
164
|
-
end() {
|
|
165
|
-
if (this.length > 0)
|
|
166
|
-
this.throw();
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
const LIBRARY_ERROR_SCOPE = Symbol('@mustib/utils');
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* Creates a debounced version of the provided function that delays its execution until after
|
|
174
|
-
* a specified number of milliseconds have elapsed since the last time it was invoked.
|
|
175
|
-
*
|
|
176
|
-
* @param func - The function to debounce.
|
|
177
|
-
* @param ms - The number of milliseconds to delay; defaults to 100ms.
|
|
178
|
-
* @returns A debounced version of the input function.
|
|
179
|
-
*/
|
|
180
|
-
function debounce(func, ms = 100) {
|
|
181
|
-
let timeoutId;
|
|
182
|
-
return function debounced(...args) {
|
|
183
|
-
clearTimeout(timeoutId);
|
|
184
|
-
timeoutId = setTimeout(() => func(...args), ms);
|
|
185
|
-
};
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
* Returns a promise that resolves after a specified number of milliseconds.
|
|
190
|
-
*
|
|
191
|
-
* @param milliseconds - The number of milliseconds to wait before resolving the promise. Defaults to 0.
|
|
192
|
-
* @returns A promise that resolves after the specified delay.
|
|
193
|
-
*/
|
|
194
|
-
function wait(milliseconds = 0) {
|
|
195
|
-
return new Promise(r => { setTimeout(r, milliseconds); });
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
/**
|
|
199
|
-
* Creates a throttled version of the given function that, when invoked repeatedly,
|
|
200
|
-
* will only call the original function at most once every `ms` milliseconds.
|
|
201
|
-
*
|
|
202
|
-
* @param func - The function to throttle.
|
|
203
|
-
* @param ms - The number of milliseconds to throttle invocations to. Defaults to 100ms.
|
|
204
|
-
* @returns A throttled version of the input function.
|
|
205
|
-
*/
|
|
206
|
-
function throttle(func, ms = 100) {
|
|
207
|
-
let isThrottled = false;
|
|
208
|
-
return function throttled(...args) {
|
|
209
|
-
if (isThrottled)
|
|
210
|
-
return;
|
|
211
|
-
isThrottled = true;
|
|
212
|
-
func(...args);
|
|
213
|
-
setTimeout(() => { isThrottled = false; }, ms);
|
|
214
|
-
};
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
/**
|
|
218
|
-
* Parses a string as JSON and returns the parsed value. If the string cannot be parsed as JSON,
|
|
219
|
-
* it returns undefined.
|
|
220
|
-
*
|
|
221
|
-
* @param {string} value - The string to parse as JSON.
|
|
222
|
-
* @return {T | undefined} - The parsed JSON value or undefined (since undefined is not a valid JSON).
|
|
223
|
-
*/
|
|
224
|
-
function parseJson(value) {
|
|
225
|
-
try {
|
|
226
|
-
return JSON.parse(value);
|
|
227
|
-
}
|
|
228
|
-
catch (error) {
|
|
229
|
-
return undefined;
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
|
|
233
40
|
function getElementBoundaries(element) {
|
|
234
41
|
const { top: elementTop, bottom, left: elementLeft, right, width, height, } = element.getBoundingClientRect();
|
|
235
42
|
const pageWidth = document.documentElement.clientWidth;
|
|
@@ -1166,4 +973,4 @@ __decorate([
|
|
|
1166
973
|
})
|
|
1167
974
|
], MuElement.prototype, "eventActionEvents", void 0);
|
|
1168
975
|
|
|
1169
|
-
export { EventAction as E, MuElement as M, __decorate as _, disableElementScroll as
|
|
976
|
+
export { EventAction as E, MuElement as M, __decorate as _, disableElementScroll as d, enableElementScroll as e, getElementBoundaries as g };
|