@justeattakeaway/pie-webc-core 0.17.1 → 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 +12 -0
- package/dist/index.js +63 -52
- package/package.json +3 -3
- package/src/functions/dispatchCustomEvent.ts +22 -0
- package/src/functions/index.ts +1 -0
- package/src/index.ts +2 -1
- package/src/interfaces/index.ts +1 -0
- package/src/interfaces/pie-input-element.ts +3 -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 +7 -1
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
[36mvite v4.
|
|
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.
|
|
6
|
+
[2mdist/[22m[36mindex.js [39m[1m[2m2.66 kB[22m[1m[22m[2m │ gzip: 1.20 kB[22m
|
|
7
7
|
[32m✓ built in 198ms[39m
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.19.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [Added] - dispatchCustomEvent helper function. ([#1272](https://github.com/justeattakeaway/pie/pull/1272)) by [@dandel10n](https://github.com/dandel10n)
|
|
8
|
+
|
|
9
|
+
## 0.18.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- [Added] - PIEInputElement interface ([#1257](https://github.com/justeattakeaway/pie/pull/1257)) by [@fernandofranca](https://github.com/fernandofranca)
|
|
14
|
+
|
|
3
15
|
## 0.17.1
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,54 @@
|
|
|
1
|
-
import { isServer as
|
|
2
|
-
const a = (e) => {
|
|
3
|
-
|
|
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
|
+
get() {
|
|
6
|
+
return this[o];
|
|
7
|
+
},
|
|
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
|
+
},
|
|
15
|
+
configurable: !0
|
|
16
|
+
});
|
|
17
|
+
}, d = (t) => function(r, i) {
|
|
18
|
+
const s = `#${i}`;
|
|
19
|
+
Object.defineProperty(r, i, {
|
|
20
|
+
get() {
|
|
21
|
+
return this[s];
|
|
22
|
+
},
|
|
23
|
+
set(n) {
|
|
24
|
+
(n == null || typeof n == "string" && n.trim() === "") && console.error(`<${t}> Missing required attribute "${i}"`), this[s] = n;
|
|
25
|
+
},
|
|
26
|
+
configurable: !0
|
|
27
|
+
});
|
|
28
|
+
};
|
|
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
|
+
}
|
|
32
|
+
function m(t) {
|
|
33
|
+
return new CustomEvent(t.type, {
|
|
34
|
+
detail: {
|
|
35
|
+
sourceEvent: t
|
|
36
|
+
},
|
|
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
|
|
47
|
+
});
|
|
48
|
+
t.dispatchEvent(i);
|
|
49
|
+
}
|
|
50
|
+
const h = (t) => {
|
|
51
|
+
class e extends t {
|
|
4
52
|
/**
|
|
5
53
|
* A getter to determine whether the text direction is right-to-left (RTL).
|
|
6
54
|
* If the `dir` property is present on the component, it will be used to determine the text direction.
|
|
@@ -11,12 +59,12 @@ const a = (e) => {
|
|
|
11
59
|
* @returns {boolean} - Returns `true` if the text direction is RTL, otherwise `false`.
|
|
12
60
|
*/
|
|
13
61
|
get isRTL() {
|
|
14
|
-
return this.dir ? this.dir === "rtl" : !
|
|
62
|
+
return this.dir ? this.dir === "rtl" : !c && !this.dir ? document.documentElement.getAttribute("dir") === "rtl" : !1;
|
|
15
63
|
}
|
|
16
64
|
}
|
|
17
|
-
return
|
|
18
|
-
},
|
|
19
|
-
class
|
|
65
|
+
return e;
|
|
66
|
+
}, p = (t) => {
|
|
67
|
+
class e extends t {
|
|
20
68
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
21
69
|
constructor(...i) {
|
|
22
70
|
super(...i), this._internals = this.attachInternals();
|
|
@@ -25,51 +73,14 @@ const a = (e) => {
|
|
|
25
73
|
return this._internals.form;
|
|
26
74
|
}
|
|
27
75
|
}
|
|
28
|
-
return
|
|
29
|
-
}, f = (e, t, n) => function(o, r) {
|
|
30
|
-
const s = `#${r}`;
|
|
31
|
-
Object.defineProperty(o, r, {
|
|
32
|
-
get() {
|
|
33
|
-
return this[s];
|
|
34
|
-
},
|
|
35
|
-
set(c) {
|
|
36
|
-
t.includes(c) ? this[s] = c : (console.error(
|
|
37
|
-
`<${e}> Invalid value "${c}" provided for property "${r}".`,
|
|
38
|
-
`Must be one of: ${t.join(" | ")}.`,
|
|
39
|
-
`Falling back to default value: "${n}"`
|
|
40
|
-
), this[s] = n);
|
|
41
|
-
},
|
|
42
|
-
configurable: !0
|
|
43
|
-
});
|
|
44
|
-
}, m = (e) => function(n, i) {
|
|
45
|
-
const o = `#${i}`;
|
|
46
|
-
Object.defineProperty(n, i, {
|
|
47
|
-
get() {
|
|
48
|
-
return this[o];
|
|
49
|
-
},
|
|
50
|
-
set(r) {
|
|
51
|
-
(r == null || typeof r == "string" && r.trim() === "") && console.error(`<${e}> Missing required attribute "${i}"`), this[o] = r;
|
|
52
|
-
},
|
|
53
|
-
configurable: !0
|
|
54
|
-
});
|
|
76
|
+
return e.formAssociated = !0, e;
|
|
55
77
|
};
|
|
56
|
-
function b(e, t) {
|
|
57
|
-
customElements.get(e) ? console.warn(`PIE Web Component: "${e}" has already been defined. Please ensure the component is only being defined once in your application.`) : customElements.define(e, t);
|
|
58
|
-
}
|
|
59
|
-
function p(e) {
|
|
60
|
-
return new CustomEvent(e.type, {
|
|
61
|
-
detail: {
|
|
62
|
-
sourceEvent: e
|
|
63
|
-
},
|
|
64
|
-
bubbles: e.bubbles,
|
|
65
|
-
cancelable: e.cancelable
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
78
|
export {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
79
|
+
p as FormControlMixin,
|
|
80
|
+
h as RtlMixin,
|
|
81
|
+
f as defineCustomElement,
|
|
82
|
+
b as dispatchCustomEvent,
|
|
83
|
+
d as requiredProperty,
|
|
84
|
+
a as validPropertyValues,
|
|
85
|
+
m as wrapNativeEvent
|
|
75
86
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@justeattakeaway/pie-webc-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.19.0",
|
|
4
4
|
"description": "PIE design system base classes, mixins and utilities for web components",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"build": "run -T vite build",
|
|
11
11
|
"lint:scripts": "run -T eslint .",
|
|
12
12
|
"lint:scripts:fix": "run -T eslint . --fix",
|
|
13
|
-
"test": "run -T vitest run",
|
|
13
|
+
"test": "run -T vitest run --config ../../../vite.config.js",
|
|
14
14
|
"test:ci": "yarn test",
|
|
15
15
|
"test:browsers": "npx playwright test -c ./playwright-lit.config.ts",
|
|
16
16
|
"test:browsers:ci": "yarn test:browsers",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"lit": "3.1.1"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
|
-
"@justeattakeaway/pie-components-config": "0.
|
|
23
|
+
"@justeattakeaway/pie-components-config": "0.11.0"
|
|
24
24
|
},
|
|
25
25
|
"volta": {
|
|
26
26
|
"extends": "../../../package.json"
|
|
@@ -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
package/src/index.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './pie-input-element';
|
|
@@ -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
|
@@ -13,7 +13,13 @@ export default defineConfig({
|
|
|
13
13
|
},
|
|
14
14
|
},
|
|
15
15
|
test: {
|
|
16
|
+
dir: '.',
|
|
16
17
|
environment: 'jsdom',
|
|
17
|
-
|
|
18
|
+
globals: true,
|
|
19
|
+
exclude: [
|
|
20
|
+
'**/test/{accessibility,component,system,visual}/*.spec.{js,ts}',
|
|
21
|
+
'**/test/**/*.browser.spec.{js,ts}',
|
|
22
|
+
'**/node_modules/**/*'
|
|
23
|
+
],
|
|
18
24
|
},
|
|
19
25
|
});
|