@mustib/web-components 0.0.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -0
- package/components/mu-element.d.ts +107 -0
- package/components/mu-element.js +4 -0
- package/components/mu-icon.d.ts +25 -0
- package/components/mu-icon.js +65 -0
- package/components/mu-range-fill.d.ts +48 -0
- package/components/mu-range-fill.js +94 -0
- package/components/mu-range-thumb-value.d.ts +48 -0
- package/components/mu-range-thumb-value.js +137 -0
- package/components/mu-range-thumb.d.ts +120 -0
- package/components/mu-range-thumb.js +305 -0
- package/components/mu-range.d.ts +206 -0
- package/components/mu-range.js +661 -0
- package/components/mu-select-item.d.ts +29 -0
- package/components/mu-select-item.js +124 -0
- package/components/mu-select-items.d.ts +218 -0
- package/components/mu-select-items.js +570 -0
- package/components/mu-select-label-content.d.ts +38 -0
- package/components/mu-select-label-content.js +159 -0
- package/components/mu-select-label.d.ts +52 -0
- package/components/mu-select-label.js +352 -0
- package/components/mu-select.d.ts +63 -0
- package/components/mu-select.js +347 -0
- package/components/mu-transparent.d.ts +56 -0
- package/components/mu-transparent.js +75 -0
- package/components/mu-trigger.d.ts +129 -0
- package/components/mu-trigger.js +175 -0
- package/decorators.d.ts +34 -0
- package/decorators.js +50 -0
- package/index.d.ts +15 -0
- package/index.js +17 -0
- package/mu-element-CZDI_RCY.js +1117 -0
- package/package.json +45 -0
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { _ as __decorate, p as parseJson } from '../mu-element-CZDI_RCY.js';
|
|
2
|
+
import { MuTransparent } from './mu-transparent.js';
|
|
3
|
+
import { staticProperty } from '../decorators.js';
|
|
4
|
+
import 'lit';
|
|
5
|
+
import 'lit/decorators.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* `<mu-trigger>` is a helper element that listens for a specified event
|
|
9
|
+
* (e.g., `click`) and dispatches a custom event (e.g., `mu-trigger-toggle`)
|
|
10
|
+
* to a target element.
|
|
11
|
+
*
|
|
12
|
+
* This is useful when you want to listen to event and dispatch a custom event
|
|
13
|
+
* like dispatch toggle when a user clicks on a button.
|
|
14
|
+
*
|
|
15
|
+
* it abstracts away the logic of selecting the element, listening to the event, dispatching the custom event, removing the event listener when the element is disconnected, and more.
|
|
16
|
+
*
|
|
17
|
+
* you can reuse different triggers (click, keydown, hover, etc.)
|
|
18
|
+
* without hard-coding logic inside the parent element (e.g., `mu-select`).
|
|
19
|
+
*/
|
|
20
|
+
class MuTrigger extends MuTransparent {
|
|
21
|
+
constructor() {
|
|
22
|
+
super(...arguments);
|
|
23
|
+
/**
|
|
24
|
+
* The DOM event to listen for (e.g., `"click"`, `"keydown"`, `"mouseenter"`).
|
|
25
|
+
* @attr listen-to
|
|
26
|
+
* @default "click"
|
|
27
|
+
*/
|
|
28
|
+
this.listenTo = 'click';
|
|
29
|
+
/**
|
|
30
|
+
* A boolean value indicates if the event should call `stopPropagation`.
|
|
31
|
+
* @default false
|
|
32
|
+
*/
|
|
33
|
+
this.stopPropagation = false;
|
|
34
|
+
/**
|
|
35
|
+
* A boolean value indicates if the event should call `stopImmediatePropagation`.
|
|
36
|
+
* @default false
|
|
37
|
+
*/
|
|
38
|
+
this.stopImmediatePropagation = false;
|
|
39
|
+
/**
|
|
40
|
+
* The name of the custom event to dispatch when the trigger fires.
|
|
41
|
+
* @default "mu-trigger-toggle"
|
|
42
|
+
*/
|
|
43
|
+
this.dispatch = 'mu-trigger-toggle';
|
|
44
|
+
/**
|
|
45
|
+
* Whether the event is no-cancelable.
|
|
46
|
+
* @default false
|
|
47
|
+
*/
|
|
48
|
+
this.noCancelable = false;
|
|
49
|
+
/**
|
|
50
|
+
* Whether the custom event should not bubble.
|
|
51
|
+
*
|
|
52
|
+
* @default false
|
|
53
|
+
*/
|
|
54
|
+
this.noBubble = false;
|
|
55
|
+
/**
|
|
56
|
+
* A boolean value indicates if the listener should not be added as a capture listener.
|
|
57
|
+
* @default false
|
|
58
|
+
*/
|
|
59
|
+
this.noCapture = false;
|
|
60
|
+
/**
|
|
61
|
+
* A boolean value indicates if the event should not call `preventDefault`.
|
|
62
|
+
* @default false
|
|
63
|
+
*/
|
|
64
|
+
this.noPreventDefault = false;
|
|
65
|
+
this.eventActionData = undefined;
|
|
66
|
+
this._addEventActionAttributes = undefined;
|
|
67
|
+
/**
|
|
68
|
+
*
|
|
69
|
+
*/
|
|
70
|
+
this._listener = (e) => {
|
|
71
|
+
if (this.disabled)
|
|
72
|
+
return;
|
|
73
|
+
if (this.stopPropagation)
|
|
74
|
+
e.stopPropagation();
|
|
75
|
+
if (this.stopImmediatePropagation)
|
|
76
|
+
e.stopImmediatePropagation();
|
|
77
|
+
if (!this.noPreventDefault)
|
|
78
|
+
e.preventDefault();
|
|
79
|
+
const { dispatchElement, eventName, shouldDispatch } = this._createDispatchEvent(e);
|
|
80
|
+
if (!shouldDispatch)
|
|
81
|
+
return;
|
|
82
|
+
dispatchElement.dispatchEvent(new CustomEvent(eventName, { bubbles: !this.noBubble, composed: true, cancelable: !this.noCancelable, detail: this.detail }));
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* The current target of the event.
|
|
87
|
+
*/
|
|
88
|
+
get _currentTarget() {
|
|
89
|
+
const currTarget = this.currentTargetSelector ? this.closestPierce(this.currentTargetSelector) : this;
|
|
90
|
+
if (!currTarget) {
|
|
91
|
+
console.warn(`no element found with selector (${this.currentTargetSelector}) as the current target to listen to (${this.listenTo}) events.\nFalling back to the current element`, this);
|
|
92
|
+
}
|
|
93
|
+
return currTarget || this;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* A function that returns the element where the event should be dispatched.
|
|
97
|
+
* If not provided, the trigger dispatches the event on itself.
|
|
98
|
+
*/
|
|
99
|
+
_getDispatchElement() {
|
|
100
|
+
const element = this.dispatchToSelector ? this.closestPierce(this.dispatchToSelector) : this;
|
|
101
|
+
if (!element)
|
|
102
|
+
console.warn(`no element found with selector ${this.dispatchToSelector} to dispatch ${this.dispatch} to.\nFalling back to the current element`, this);
|
|
103
|
+
return element || this;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* This function is called after the event is fired.
|
|
107
|
+
* You can return a custom object with the following properties to customize the dispatching of the event.
|
|
108
|
+
* - `shouldDispatch`: a boolean indicating whether the event should be dispatched.
|
|
109
|
+
* - `eventName`: a string indicating the name of the event to be dispatched.
|
|
110
|
+
* - `dispatchElement`: an element indicating where the event should be dispatched.
|
|
111
|
+
*
|
|
112
|
+
* If you return nothing, the event will not be dispatched.
|
|
113
|
+
*
|
|
114
|
+
* @param e The original event that was fired.
|
|
115
|
+
* @returns {Object} An object with the properties above.
|
|
116
|
+
*/
|
|
117
|
+
_createDispatchEvent(e) {
|
|
118
|
+
return {
|
|
119
|
+
shouldDispatch: true,
|
|
120
|
+
eventName: this.dispatch,
|
|
121
|
+
dispatchElement: this._getDispatchElement()
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
*
|
|
126
|
+
*/
|
|
127
|
+
connectedCallback() {
|
|
128
|
+
super.connectedCallback();
|
|
129
|
+
this._currentTarget.addEventListener(this.listenTo, this._listener, { capture: !this.noCapture });
|
|
130
|
+
}
|
|
131
|
+
disconnectedCallback() {
|
|
132
|
+
super.disconnectedCallback();
|
|
133
|
+
this._currentTarget.removeEventListener(this.listenTo, this._listener, { capture: !this.noCapture });
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
__decorate([
|
|
137
|
+
staticProperty()
|
|
138
|
+
], MuTrigger.prototype, "listenTo", void 0);
|
|
139
|
+
__decorate([
|
|
140
|
+
staticProperty({
|
|
141
|
+
converter(value) {
|
|
142
|
+
return value ? parseJson(value) : undefined;
|
|
143
|
+
},
|
|
144
|
+
})
|
|
145
|
+
], MuTrigger.prototype, "detail", void 0);
|
|
146
|
+
__decorate([
|
|
147
|
+
staticProperty({ converter: Boolean })
|
|
148
|
+
], MuTrigger.prototype, "stopPropagation", void 0);
|
|
149
|
+
__decorate([
|
|
150
|
+
staticProperty({ converter: Boolean })
|
|
151
|
+
], MuTrigger.prototype, "stopImmediatePropagation", void 0);
|
|
152
|
+
__decorate([
|
|
153
|
+
staticProperty()
|
|
154
|
+
], MuTrigger.prototype, "dispatch", void 0);
|
|
155
|
+
__decorate([
|
|
156
|
+
staticProperty({ converter: Boolean })
|
|
157
|
+
], MuTrigger.prototype, "noCancelable", void 0);
|
|
158
|
+
__decorate([
|
|
159
|
+
staticProperty({ converter: Boolean })
|
|
160
|
+
], MuTrigger.prototype, "noBubble", void 0);
|
|
161
|
+
__decorate([
|
|
162
|
+
staticProperty({ converter: Boolean })
|
|
163
|
+
], MuTrigger.prototype, "noCapture", void 0);
|
|
164
|
+
__decorate([
|
|
165
|
+
staticProperty()
|
|
166
|
+
], MuTrigger.prototype, "currentTargetSelector", void 0);
|
|
167
|
+
__decorate([
|
|
168
|
+
staticProperty({ converter: Boolean })
|
|
169
|
+
], MuTrigger.prototype, "noPreventDefault", void 0);
|
|
170
|
+
__decorate([
|
|
171
|
+
staticProperty()
|
|
172
|
+
], MuTrigger.prototype, "dispatchToSelector", void 0);
|
|
173
|
+
MuTrigger.register('mu-trigger');
|
|
174
|
+
|
|
175
|
+
export { MuTrigger };
|
package/decorators.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
type Options = {
|
|
2
|
+
/**
|
|
3
|
+
* The HTML attribute to get the value from.
|
|
4
|
+
* If not provided, it defaults to the kebab case version of the property name.
|
|
5
|
+
* @example If the property name is "propName", the attribute will default to "prop-name".
|
|
6
|
+
*/
|
|
7
|
+
attribute?: string;
|
|
8
|
+
/**
|
|
9
|
+
* A function that converts the attribute value to the property value.
|
|
10
|
+
*/
|
|
11
|
+
converter?: (value: string | null) => any;
|
|
12
|
+
/**
|
|
13
|
+
* Whether to reflect the default value of the property to the attribute.
|
|
14
|
+
*
|
|
15
|
+
* The default value is the value that is assigned to the property on the class definition like so:
|
|
16
|
+
* `propName = value` or basically any value that calls the setter before the first call to the getter.
|
|
17
|
+
*
|
|
18
|
+
* This is useful when you want the attribute to have the same value as the property by default.
|
|
19
|
+
*
|
|
20
|
+
* For example, if you have a property `visible` with a default value of `true`, and you want the attribute `visible` to have the value `"true"` by default, you can set `reflectDefault` to `true`.
|
|
21
|
+
*
|
|
22
|
+
* @default false
|
|
23
|
+
*/
|
|
24
|
+
reflectDefault?: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* A function that converts the default property value to the attribute value.
|
|
27
|
+
*
|
|
28
|
+
* this is only used if `reflectDefault` is true
|
|
29
|
+
*/
|
|
30
|
+
reflectConverter?: (value: any) => string;
|
|
31
|
+
};
|
|
32
|
+
declare function staticProperty(options?: Options): <T extends HTMLElement>(target: T, key: string) => void;
|
|
33
|
+
|
|
34
|
+
export { staticProperty };
|
package/decorators.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
const defaultConverter = (value) => (value ?? undefined);
|
|
2
|
+
const toKebabCase = (str) => str.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
|
|
3
|
+
const defaultReflectConverter = (value) => value.toString();
|
|
4
|
+
function staticProperty(options) {
|
|
5
|
+
return function staticPropertyDecorator(target, key) {
|
|
6
|
+
if (!Reflect.has(target, '__staticProperties')) {
|
|
7
|
+
Reflect.set(target, '__staticProperties', new WeakMap());
|
|
8
|
+
}
|
|
9
|
+
const { attribute = toKebabCase(key), converter = defaultConverter, reflectDefault = false, reflectConverter = defaultReflectConverter } = options ?? {};
|
|
10
|
+
Reflect.defineProperty(target, key, {
|
|
11
|
+
configurable: false,
|
|
12
|
+
enumerable: true,
|
|
13
|
+
set(v) {
|
|
14
|
+
const mapData = getOrCreateMapData(this, key);
|
|
15
|
+
if (mapData.hasBeenCalled) {
|
|
16
|
+
throw new Error(`cannot set ${v} for a static property ${key} after first call to get`);
|
|
17
|
+
}
|
|
18
|
+
if (reflectDefault) {
|
|
19
|
+
this.setAttribute(attribute, reflectConverter(v));
|
|
20
|
+
}
|
|
21
|
+
mapData.defaultValue = v;
|
|
22
|
+
},
|
|
23
|
+
get() {
|
|
24
|
+
const mapData = getOrCreateMapData(this, key);
|
|
25
|
+
if (mapData.hasBeenCalled)
|
|
26
|
+
return mapData.value;
|
|
27
|
+
mapData.hasBeenCalled = true;
|
|
28
|
+
const attrValue = this.getAttribute(attribute);
|
|
29
|
+
if (attrValue === null && mapData.defaultValue !== undefined) {
|
|
30
|
+
mapData.value = mapData.defaultValue;
|
|
31
|
+
}
|
|
32
|
+
else
|
|
33
|
+
mapData.value = converter(attrValue);
|
|
34
|
+
return mapData.value;
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function getOrCreateMapData(instance, key) {
|
|
40
|
+
let properties = Reflect.get(Reflect.getPrototypeOf(instance), '__staticProperties');
|
|
41
|
+
let _mapData = properties.get(instance) || properties.set(instance, {}).get(instance);
|
|
42
|
+
const staticData = _mapData[key] ||= {
|
|
43
|
+
value: undefined,
|
|
44
|
+
hasBeenCalled: false,
|
|
45
|
+
defaultValue: undefined
|
|
46
|
+
};
|
|
47
|
+
return staticData;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export { staticProperty };
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import './components/mu-transparent.js';
|
|
2
|
+
import './components/mu-trigger.js';
|
|
3
|
+
import './components/mu-select.js';
|
|
4
|
+
import './components/mu-select-item.js';
|
|
5
|
+
import './components/mu-select-items.js';
|
|
6
|
+
import './components/mu-select-label.js';
|
|
7
|
+
import './components/mu-select-label-content.js';
|
|
8
|
+
import './components/mu-range.js';
|
|
9
|
+
import './components/mu-range-thumb.js';
|
|
10
|
+
import './components/mu-icon.js';
|
|
11
|
+
import './components/mu-element.js';
|
|
12
|
+
import 'lit';
|
|
13
|
+
import '@mustib/utils/browser';
|
|
14
|
+
import './components/mu-range-fill.js';
|
|
15
|
+
import './components/mu-range-thumb-value.js';
|
package/index.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import './mu-element-CZDI_RCY.js';
|
|
2
|
+
import './components/mu-transparent.js';
|
|
3
|
+
import './components/mu-trigger.js';
|
|
4
|
+
import './components/mu-select.js';
|
|
5
|
+
import './components/mu-select-item.js';
|
|
6
|
+
import './components/mu-select-items.js';
|
|
7
|
+
import './components/mu-select-label.js';
|
|
8
|
+
import './components/mu-select-label-content.js';
|
|
9
|
+
import './components/mu-range.js';
|
|
10
|
+
import './components/mu-range-fill.js';
|
|
11
|
+
import './components/mu-range-thumb.js';
|
|
12
|
+
import './components/mu-range-thumb-value.js';
|
|
13
|
+
import './components/mu-icon.js';
|
|
14
|
+
import 'lit';
|
|
15
|
+
import 'lit/decorators.js';
|
|
16
|
+
import './decorators.js';
|
|
17
|
+
import 'lit/directives/repeat.js';
|