@justeattakeaway/pie-webc-core 0.18.0 → 0.19.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/.turbo/turbo-build.log +3 -3
- package/CHANGELOG.md +6 -0
- package/dist/index.js +42 -32
- package/package.json +1 -1
- package/src/functions/dispatchCustomEvent.ts +22 -0
- package/src/functions/index.ts +1 -0
- package/src/test/functions/dispatchCustomElement/MockComponent.ts +28 -0
- package/src/test/functions/dispatchCustomElement/dispatchCustomEvent.browser.spec.ts +45 -0
- package/vite.config.js +1 -1
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
[36mvite v4.5.2 [32mbuilding for production...[36m[39m
|
|
2
2
|
transforming...
|
|
3
|
-
[32m✓[39m
|
|
3
|
+
[32m✓[39m 14 modules transformed.
|
|
4
4
|
rendering chunks...
|
|
5
5
|
computing gzip size...
|
|
6
|
-
[2mdist/[22m[36mindex.js [39m[1m[2m2.
|
|
7
|
-
[32m✓ built in
|
|
6
|
+
[2mdist/[22m[36mindex.js [39m[1m[2m2.66 kB[22m[1m[22m[2m │ gzip: 1.20 kB[22m
|
|
7
|
+
[32m✓ built in 198ms[39m
|
package/CHANGELOG.md
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,45 +1,54 @@
|
|
|
1
|
-
import { isServer as
|
|
2
|
-
const a = (
|
|
3
|
-
const
|
|
4
|
-
Object.defineProperty(
|
|
1
|
+
import { isServer as c } from "lit";
|
|
2
|
+
const a = (t, e, r) => function(s, n) {
|
|
3
|
+
const o = `#${n}`;
|
|
4
|
+
Object.defineProperty(s, n, {
|
|
5
5
|
get() {
|
|
6
|
-
return this[
|
|
6
|
+
return this[o];
|
|
7
7
|
},
|
|
8
|
-
set(
|
|
9
|
-
|
|
10
|
-
`<${
|
|
11
|
-
`Must be one of: ${
|
|
12
|
-
`Falling back to default value: "${
|
|
13
|
-
), this[
|
|
8
|
+
set(u) {
|
|
9
|
+
e.includes(u) ? this[o] = u : (console.error(
|
|
10
|
+
`<${t}> Invalid value "${u}" provided for property "${n}".`,
|
|
11
|
+
`Must be one of: ${e.join(" | ")}.`,
|
|
12
|
+
`Falling back to default value: "${r}"`
|
|
13
|
+
), this[o] = r);
|
|
14
14
|
},
|
|
15
15
|
configurable: !0
|
|
16
16
|
});
|
|
17
|
-
}, d = (
|
|
18
|
-
const
|
|
19
|
-
Object.defineProperty(
|
|
17
|
+
}, d = (t) => function(r, i) {
|
|
18
|
+
const s = `#${i}`;
|
|
19
|
+
Object.defineProperty(r, i, {
|
|
20
20
|
get() {
|
|
21
|
-
return this[
|
|
21
|
+
return this[s];
|
|
22
22
|
},
|
|
23
|
-
set(
|
|
24
|
-
(
|
|
23
|
+
set(n) {
|
|
24
|
+
(n == null || typeof n == "string" && n.trim() === "") && console.error(`<${t}> Missing required attribute "${i}"`), this[s] = n;
|
|
25
25
|
},
|
|
26
26
|
configurable: !0
|
|
27
27
|
});
|
|
28
28
|
};
|
|
29
|
-
function f(
|
|
30
|
-
customElements.get(
|
|
29
|
+
function f(t, e) {
|
|
30
|
+
customElements.get(t) ? console.warn(`PIE Web Component: "${t}" has already been defined. Please ensure the component is only being defined once in your application.`) : customElements.define(t, e);
|
|
31
31
|
}
|
|
32
|
-
function m(
|
|
33
|
-
return new CustomEvent(
|
|
32
|
+
function m(t) {
|
|
33
|
+
return new CustomEvent(t.type, {
|
|
34
34
|
detail: {
|
|
35
|
-
sourceEvent:
|
|
35
|
+
sourceEvent: t
|
|
36
36
|
},
|
|
37
|
-
bubbles:
|
|
38
|
-
cancelable:
|
|
37
|
+
bubbles: t.bubbles,
|
|
38
|
+
cancelable: t.cancelable
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
function b(t, e, r) {
|
|
42
|
+
e.startsWith("pie-") || console.warn("A custom event name should start with `pie-`");
|
|
43
|
+
const i = new CustomEvent(e, {
|
|
44
|
+
bubbles: !0,
|
|
45
|
+
composed: !0,
|
|
46
|
+
detail: r
|
|
39
47
|
});
|
|
48
|
+
t.dispatchEvent(i);
|
|
40
49
|
}
|
|
41
|
-
const
|
|
42
|
-
class
|
|
50
|
+
const h = (t) => {
|
|
51
|
+
class e extends t {
|
|
43
52
|
/**
|
|
44
53
|
* A getter to determine whether the text direction is right-to-left (RTL).
|
|
45
54
|
* If the `dir` property is present on the component, it will be used to determine the text direction.
|
|
@@ -50,12 +59,12 @@ const b = (e) => {
|
|
|
50
59
|
* @returns {boolean} - Returns `true` if the text direction is RTL, otherwise `false`.
|
|
51
60
|
*/
|
|
52
61
|
get isRTL() {
|
|
53
|
-
return this.dir ? this.dir === "rtl" : !
|
|
62
|
+
return this.dir ? this.dir === "rtl" : !c && !this.dir ? document.documentElement.getAttribute("dir") === "rtl" : !1;
|
|
54
63
|
}
|
|
55
64
|
}
|
|
56
|
-
return
|
|
57
|
-
}, p = (
|
|
58
|
-
class
|
|
65
|
+
return e;
|
|
66
|
+
}, p = (t) => {
|
|
67
|
+
class e extends t {
|
|
59
68
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
60
69
|
constructor(...i) {
|
|
61
70
|
super(...i), this._internals = this.attachInternals();
|
|
@@ -64,12 +73,13 @@ const b = (e) => {
|
|
|
64
73
|
return this._internals.form;
|
|
65
74
|
}
|
|
66
75
|
}
|
|
67
|
-
return
|
|
76
|
+
return e.formAssociated = !0, e;
|
|
68
77
|
};
|
|
69
78
|
export {
|
|
70
79
|
p as FormControlMixin,
|
|
71
|
-
|
|
80
|
+
h as RtlMixin,
|
|
72
81
|
f as defineCustomElement,
|
|
82
|
+
b as dispatchCustomEvent,
|
|
73
83
|
d as requiredProperty,
|
|
74
84
|
a as validPropertyValues,
|
|
75
85
|
m as wrapNativeEvent
|
package/package.json
CHANGED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dispatch a custom event.
|
|
3
|
+
*
|
|
4
|
+
* To be used whenever we have custom events we want to
|
|
5
|
+
* bubble up through the component.
|
|
6
|
+
* Bubbles and composed event props are set to true.
|
|
7
|
+
* @param {Element} element The element to dispatch the event from.
|
|
8
|
+
* @param {string} eventType
|
|
9
|
+
* @param {any} detail
|
|
10
|
+
*/
|
|
11
|
+
export function dispatchCustomEvent (element: Element, eventType: string, detail?: CustomEventInit['detail']) : void {
|
|
12
|
+
if (!eventType.startsWith('pie-')) {
|
|
13
|
+
console.warn('A custom event name should start with `pie-`');
|
|
14
|
+
}
|
|
15
|
+
const event = new CustomEvent(eventType, {
|
|
16
|
+
bubbles: true,
|
|
17
|
+
composed: true,
|
|
18
|
+
detail,
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
element.dispatchEvent(event);
|
|
22
|
+
}
|
package/src/functions/index.ts
CHANGED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { LitElement, html } from 'lit';
|
|
2
|
+
import { property } from 'lit/decorators.js';
|
|
3
|
+
import { defineCustomElement } from '../../../functions/defineCustomElement.js';
|
|
4
|
+
import { dispatchCustomEvent } from '../../../functions/dispatchCustomEvent.js';
|
|
5
|
+
|
|
6
|
+
const componentSelector = 'dispatch-custom-event-mock';
|
|
7
|
+
|
|
8
|
+
export class MockComponent extends LitElement {
|
|
9
|
+
@property({ type: String })
|
|
10
|
+
public eventName = 'pie-mock-event';
|
|
11
|
+
|
|
12
|
+
render () {
|
|
13
|
+
return html`
|
|
14
|
+
<button
|
|
15
|
+
@click="${() => dispatchCustomEvent(this, this.eventName)}"
|
|
16
|
+
data-test-id="dispatch-custom-event-mock">
|
|
17
|
+
Component with the event to dispatch
|
|
18
|
+
</button>`;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
declare global {
|
|
23
|
+
interface HTMLElementTagNameMap {
|
|
24
|
+
[componentSelector]: MockComponent;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
defineCustomElement(componentSelector, MockComponent);
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { test, expect } from '@sand4rt/experimental-ct-web';
|
|
2
|
+
import { MockComponent } from './MockComponent.ts';
|
|
3
|
+
|
|
4
|
+
test.describe('dispatchCustomEvent function', () => {
|
|
5
|
+
test('should dispatch an event when clicked', async ({ mount, page }) => {
|
|
6
|
+
// Arrange
|
|
7
|
+
const events : Array<Event> = [];
|
|
8
|
+
|
|
9
|
+
await mount(MockComponent, {
|
|
10
|
+
on: {
|
|
11
|
+
'pie-mock-event': (event: Event) => events.push(event),
|
|
12
|
+
},
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
// Act
|
|
16
|
+
await page.locator('[data-test-id="dispatch-custom-event-mock"]').click();
|
|
17
|
+
|
|
18
|
+
// Assert
|
|
19
|
+
expect(events).toHaveLength(1);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
test('should call console.warn when event name do not start with "pie-"', async ({ mount, page }) => {
|
|
23
|
+
// Arrange
|
|
24
|
+
let result = '';
|
|
25
|
+
const expected = 'A custom event name should start with `pie-`';
|
|
26
|
+
|
|
27
|
+
await mount(MockComponent, {
|
|
28
|
+
props: {
|
|
29
|
+
eventName: 'mock-event',
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
page.on('console', (msg) => {
|
|
34
|
+
if (msg.type() === 'warning') {
|
|
35
|
+
result = msg.text();
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
// Act
|
|
40
|
+
await page.locator('[data-test-id="dispatch-custom-event-mock"]').click();
|
|
41
|
+
|
|
42
|
+
// Assert
|
|
43
|
+
expect(result).toMatch(expected);
|
|
44
|
+
});
|
|
45
|
+
});
|
package/vite.config.js
CHANGED