@justeattakeaway/pie-webc-core 0.25.0 → 0.26.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/dist/index.js
CHANGED
|
@@ -1,35 +1,46 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { customElement as a } from "lit/decorators.js";
|
|
2
|
+
import { isServer as u } from "lit";
|
|
3
|
+
const f = (t, e, n) => function(i, s) {
|
|
4
|
+
const o = `#${s}`;
|
|
5
|
+
Object.defineProperty(i, s, {
|
|
5
6
|
get() {
|
|
6
7
|
return this[o];
|
|
7
8
|
},
|
|
8
|
-
set(
|
|
9
|
-
e.includes(
|
|
10
|
-
`<${t}> Invalid value "${
|
|
9
|
+
set(c) {
|
|
10
|
+
e.includes(c) ? this[o] = c : (console.error(
|
|
11
|
+
`<${t}> Invalid value "${c}" provided for property "${s}".`,
|
|
11
12
|
`Must be one of: ${e.join(" | ")}.`,
|
|
12
13
|
`Falling back to default value: "${n}"`
|
|
13
14
|
), this[o] = n);
|
|
14
15
|
},
|
|
15
16
|
configurable: !0
|
|
16
17
|
});
|
|
17
|
-
},
|
|
18
|
-
const
|
|
19
|
-
Object.defineProperty(n,
|
|
18
|
+
}, m = (t) => function(n, r) {
|
|
19
|
+
const i = `#${r}`;
|
|
20
|
+
Object.defineProperty(n, r, {
|
|
20
21
|
get() {
|
|
21
|
-
return this[
|
|
22
|
+
return this[i];
|
|
22
23
|
},
|
|
23
|
-
set(
|
|
24
|
-
(
|
|
24
|
+
set(s) {
|
|
25
|
+
(s == null || typeof s == "string" && s.trim() === "") && console.error(`<${t}> Missing required attribute "${r}"`), this[i] = s;
|
|
25
26
|
},
|
|
26
27
|
configurable: !0
|
|
27
28
|
});
|
|
28
29
|
};
|
|
29
|
-
function
|
|
30
|
-
|
|
30
|
+
function h(t) {
|
|
31
|
+
return (e) => {
|
|
32
|
+
try {
|
|
33
|
+
a(t)(e);
|
|
34
|
+
} catch (n) {
|
|
35
|
+
const r = customElements.get(t), i = r == null ? void 0 : r.v;
|
|
36
|
+
e.v !== i && console.warn(
|
|
37
|
+
`PIE Web Component: "${t}" was already registered with version: ${i ?? "No version data found. Icon components do not contain version data. If the component is not an icon, please report the missing version data."}.`,
|
|
38
|
+
n
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
31
42
|
}
|
|
32
|
-
function
|
|
43
|
+
function p(t) {
|
|
33
44
|
return new CustomEvent(t.type, {
|
|
34
45
|
detail: {
|
|
35
46
|
sourceEvent: t
|
|
@@ -38,16 +49,16 @@ function b(t) {
|
|
|
38
49
|
cancelable: t.cancelable
|
|
39
50
|
});
|
|
40
51
|
}
|
|
41
|
-
function
|
|
52
|
+
function b(t, e, n) {
|
|
42
53
|
e.startsWith("pie-") || console.warn("A custom event name should start with `pie-`");
|
|
43
|
-
const
|
|
54
|
+
const r = new CustomEvent(e, {
|
|
44
55
|
bubbles: !0,
|
|
45
56
|
composed: !0,
|
|
46
57
|
detail: n
|
|
47
58
|
});
|
|
48
|
-
t.dispatchEvent(
|
|
59
|
+
t.dispatchEvent(r);
|
|
49
60
|
}
|
|
50
|
-
const
|
|
61
|
+
const g = (t) => {
|
|
51
62
|
class e extends t {
|
|
52
63
|
/**
|
|
53
64
|
* A getter to determine whether the text direction is right-to-left (RTL).
|
|
@@ -59,18 +70,18 @@ const m = (t) => {
|
|
|
59
70
|
* @returns {boolean} - Returns `true` if the text direction is RTL, otherwise `false`.
|
|
60
71
|
*/
|
|
61
72
|
get isRTL() {
|
|
62
|
-
return this.dir ? this.dir === "rtl" : !
|
|
73
|
+
return this.dir ? this.dir === "rtl" : !u && !this.dir ? document.documentElement.getAttribute("dir") === "rtl" : !1;
|
|
63
74
|
}
|
|
64
75
|
}
|
|
65
76
|
return e;
|
|
66
|
-
},
|
|
77
|
+
}, v = (t) => {
|
|
67
78
|
const n = class n extends t {
|
|
68
79
|
get form() {
|
|
69
80
|
return this._internals.form;
|
|
70
81
|
}
|
|
71
82
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
72
|
-
constructor(...
|
|
73
|
-
super(...
|
|
83
|
+
constructor(...i) {
|
|
84
|
+
super(...i), this._internals = this.attachInternals();
|
|
74
85
|
}
|
|
75
86
|
};
|
|
76
87
|
n.formAssociated = !0;
|
|
@@ -78,11 +89,11 @@ const m = (t) => {
|
|
|
78
89
|
return e;
|
|
79
90
|
};
|
|
80
91
|
export {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
92
|
+
v as FormControlMixin,
|
|
93
|
+
g as RtlMixin,
|
|
94
|
+
b as dispatchCustomEvent,
|
|
95
|
+
m as requiredProperty,
|
|
96
|
+
h as safeCustomElement,
|
|
97
|
+
f as validPropertyValues,
|
|
98
|
+
p as wrapNativeEvent
|
|
88
99
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@justeattakeaway/pie-webc-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.26.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",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"lit": "3.2.0"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@justeattakeaway/pie-components-config": "0.
|
|
31
|
+
"@justeattakeaway/pie-components-config": "0.20.1"
|
|
32
32
|
},
|
|
33
33
|
"volta": {
|
|
34
34
|
"extends": "../../../package.json"
|
package/src/decorators/index.ts
CHANGED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { customElement } from 'lit/decorators.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Custom decorator that wraps Lit's customElement decorator with error handling.
|
|
5
|
+
* Logs a warning if the custom element has already been defined, including version info of the already registered component if available.
|
|
6
|
+
*
|
|
7
|
+
* @param {string} elementSelector - Custom element tag name.
|
|
8
|
+
* @returns {ClassDecorator}
|
|
9
|
+
*/
|
|
10
|
+
export function safeCustomElement (elementSelector: string): ClassDecorator {
|
|
11
|
+
return (elementClass: unknown) => {
|
|
12
|
+
try {
|
|
13
|
+
customElement(elementSelector)(elementClass as CustomElementConstructor);
|
|
14
|
+
} catch (e) {
|
|
15
|
+
type WithVProperty = { v?: string }
|
|
16
|
+
const registeredClass = customElements.get(elementSelector) as WithVProperty;
|
|
17
|
+
const registeredVersion = registeredClass?.v;
|
|
18
|
+
const missingVersionMessage = 'No version data found. Icon components do not contain version data. If the component is not an icon, please report the missing version data.';
|
|
19
|
+
const currentElementVersion = (elementClass as WithVProperty).v;
|
|
20
|
+
|
|
21
|
+
if (currentElementVersion !== registeredVersion) {
|
|
22
|
+
console.warn(
|
|
23
|
+
`PIE Web Component: "${elementSelector}" was already registered with version: ${registeredVersion ?? missingVersionMessage}.`,
|
|
24
|
+
e,
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
}
|
package/src/functions/index.ts
CHANGED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import type { LitElement } from 'lit';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Defines a web component, ensuring that the component is only defined once in the Custom Element Registry.
|
|
5
|
-
*
|
|
6
|
-
* If the component has already been defined with the same name, a warning is logged to the console.
|
|
7
|
-
*
|
|
8
|
-
* @param {string} elementSelector - The selector of the custom element. Must be a valid custom element selector, containing a dash. I.e. 'my-component'
|
|
9
|
-
* @param {typeof LitElement} elementClass - The class that defines the custom element, extending LitElement.
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
*
|
|
13
|
-
* ```javascript
|
|
14
|
-
* import { css, html, LitElement } from 'lit';
|
|
15
|
-
*
|
|
16
|
-
* // IMPORTANT: Add the following JSDoc comment above your class setting the `@tagname` to the selector you want to use. - This is mandatory.
|
|
17
|
-
* // "@tagname my-component"
|
|
18
|
-
* class MyComponent extends LitElement {
|
|
19
|
-
* static styles = css`
|
|
20
|
-
* :host {
|
|
21
|
-
* display: block;
|
|
22
|
-
* padding: 16px;
|
|
23
|
-
* color: var(--my-component-text-color, black);
|
|
24
|
-
* }
|
|
25
|
-
* `;
|
|
26
|
-
*
|
|
27
|
-
* render() {
|
|
28
|
-
* return html`
|
|
29
|
-
* <p>My custom element content goes here!</p>
|
|
30
|
-
* `;
|
|
31
|
-
* }
|
|
32
|
-
* }
|
|
33
|
-
*
|
|
34
|
-
* defineCustomElement('my-component', MyComponent);
|
|
35
|
-
* ```
|
|
36
|
-
*
|
|
37
|
-
* NOTE: The inclusion of the `@tagname` JSDoc comment above your class is essential for correct functionality. Ensure it matches the tag you're registering.
|
|
38
|
-
*
|
|
39
|
-
* @returns {void}
|
|
40
|
-
*/
|
|
41
|
-
export function defineCustomElement (elementSelector: string, elementClass: typeof LitElement): void {
|
|
42
|
-
if (!customElements.get(elementSelector)) {
|
|
43
|
-
customElements.define(elementSelector, elementClass);
|
|
44
|
-
} else {
|
|
45
|
-
console.warn(`PIE Web Component: "${elementSelector}" has already been defined. Please ensure the component is only being defined once in your application.`);
|
|
46
|
-
}
|
|
47
|
-
}
|