@justeattakeaway/pie-webc-core 1.1.0 → 2.0.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,27 +1,27 @@
|
|
|
1
1
|
import { customElement as a } from "lit/decorators.js";
|
|
2
|
-
const d = (t, e,
|
|
3
|
-
const o = `#${
|
|
4
|
-
Object.defineProperty(
|
|
2
|
+
const d = (t, e, s) => function(r, i) {
|
|
3
|
+
const o = `#${i}`;
|
|
4
|
+
Object.defineProperty(r, i, {
|
|
5
5
|
get() {
|
|
6
6
|
return this[o];
|
|
7
7
|
},
|
|
8
8
|
set(c) {
|
|
9
9
|
e.includes(c) ? this[o] = c : (console.error(
|
|
10
|
-
`<${t}> Invalid value "${c}" provided for property "${
|
|
10
|
+
`<${t}> Invalid value "${c}" provided for property "${i}".`,
|
|
11
11
|
`Must be one of: ${e.join(" | ")}.`,
|
|
12
|
-
`Falling back to default value: "${
|
|
13
|
-
), this[o] =
|
|
12
|
+
`Falling back to default value: "${s}"`
|
|
13
|
+
), this[o] = s);
|
|
14
14
|
},
|
|
15
15
|
configurable: !0
|
|
16
16
|
});
|
|
17
|
-
}, l = (t) => function(
|
|
18
|
-
const
|
|
19
|
-
Object.defineProperty(
|
|
17
|
+
}, l = (t) => function(s, n) {
|
|
18
|
+
const r = `#${n}`;
|
|
19
|
+
Object.defineProperty(s, n, {
|
|
20
20
|
get() {
|
|
21
|
-
return this[
|
|
21
|
+
return this[r];
|
|
22
22
|
},
|
|
23
|
-
set(
|
|
24
|
-
(
|
|
23
|
+
set(i) {
|
|
24
|
+
(i == null || typeof i == "string" && i.trim() === "") && console.error(`<${t}> Missing required attribute "${n}"`), this[r] = i;
|
|
25
25
|
},
|
|
26
26
|
configurable: !0
|
|
27
27
|
});
|
|
@@ -30,11 +30,11 @@ function h(t) {
|
|
|
30
30
|
return (e) => {
|
|
31
31
|
try {
|
|
32
32
|
a(t)(e);
|
|
33
|
-
} catch (
|
|
34
|
-
const
|
|
35
|
-
e.v !==
|
|
36
|
-
`PIE Web Component: "${t}" was already registered with version: ${
|
|
37
|
-
|
|
33
|
+
} catch (s) {
|
|
34
|
+
const n = customElements.get(t), r = n == null ? void 0 : n.v;
|
|
35
|
+
e.v !== r && console.warn(
|
|
36
|
+
`PIE Web Component: "${t}" was already registered with version: ${r ?? "No version data found. Icon components do not contain version data. If the component is not an icon, please report the missing version data."}.`,
|
|
37
|
+
s
|
|
38
38
|
);
|
|
39
39
|
}
|
|
40
40
|
};
|
|
@@ -48,16 +48,16 @@ function b(t) {
|
|
|
48
48
|
cancelable: t.cancelable
|
|
49
49
|
});
|
|
50
50
|
}
|
|
51
|
-
function
|
|
51
|
+
function p(t, e, s) {
|
|
52
52
|
e.startsWith("pie-") || console.warn("A custom event name should start with `pie-`");
|
|
53
|
-
const
|
|
53
|
+
const n = new CustomEvent(e, {
|
|
54
54
|
bubbles: !0,
|
|
55
55
|
composed: !0,
|
|
56
|
-
detail:
|
|
56
|
+
detail: s
|
|
57
57
|
});
|
|
58
|
-
t.dispatchEvent(
|
|
58
|
+
t.dispatchEvent(n);
|
|
59
59
|
}
|
|
60
|
-
const
|
|
60
|
+
const m = (t) => {
|
|
61
61
|
class e extends t {
|
|
62
62
|
constructor() {
|
|
63
63
|
super(...arguments), this._isRTL = !1, this.observer = null;
|
|
@@ -65,8 +65,8 @@ const p = (t) => {
|
|
|
65
65
|
get isRTL() {
|
|
66
66
|
return this._isRTL;
|
|
67
67
|
}
|
|
68
|
-
set isRTL(
|
|
69
|
-
this._isRTL =
|
|
68
|
+
set isRTL(n) {
|
|
69
|
+
this._isRTL = n, this.requestUpdate();
|
|
70
70
|
}
|
|
71
71
|
connectedCallback() {
|
|
72
72
|
super.connectedCallback(), this.handleWritingDirectionUpdate(), this.observer = new MutationObserver(() => {
|
|
@@ -90,23 +90,37 @@ const p = (t) => {
|
|
|
90
90
|
}
|
|
91
91
|
return e;
|
|
92
92
|
}, f = (t) => {
|
|
93
|
-
const
|
|
93
|
+
const s = class s extends t {
|
|
94
94
|
get form() {
|
|
95
95
|
return this._internals.form;
|
|
96
96
|
}
|
|
97
97
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
98
|
-
constructor(...
|
|
99
|
-
super(...
|
|
98
|
+
constructor(...r) {
|
|
99
|
+
super(...r), this._internals = this.attachInternals();
|
|
100
100
|
}
|
|
101
101
|
};
|
|
102
|
-
|
|
103
|
-
let e =
|
|
102
|
+
s.formAssociated = !0;
|
|
103
|
+
let e = s;
|
|
104
|
+
return e;
|
|
105
|
+
}, v = (t) => {
|
|
106
|
+
const s = class s extends t {
|
|
107
|
+
};
|
|
108
|
+
s.shadowRootOptions = {
|
|
109
|
+
// The `as any` cast is a safe way to access the static property
|
|
110
|
+
// from the generic superclass constructor. LitElement provides a default.
|
|
111
|
+
// This is unfortunately unavoidable and a common issue with mixins in TS.
|
|
112
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
113
|
+
...t.shadowRootOptions,
|
|
114
|
+
delegatesFocus: !0
|
|
115
|
+
};
|
|
116
|
+
let e = s;
|
|
104
117
|
return e;
|
|
105
118
|
};
|
|
106
119
|
export {
|
|
120
|
+
v as DelegatesFocusMixin,
|
|
107
121
|
f as FormControlMixin,
|
|
108
|
-
|
|
109
|
-
|
|
122
|
+
m as RtlMixin,
|
|
123
|
+
p as dispatchCustomEvent,
|
|
110
124
|
l as requiredProperty,
|
|
111
125
|
h as safeCustomElement,
|
|
112
126
|
d as validPropertyValues,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@justeattakeaway/pie-webc-core",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.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",
|
|
@@ -27,6 +27,9 @@
|
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"lit": "3.2.0"
|
|
29
29
|
},
|
|
30
|
+
"peerDependencies": {
|
|
31
|
+
"@justeattakeaway/pie-css": "0.22.0"
|
|
32
|
+
},
|
|
30
33
|
"devDependencies": {
|
|
31
34
|
"@justeattakeaway/pie-components-config": "0.21.0"
|
|
32
35
|
},
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { LitElement } from 'lit';
|
|
2
|
+
import type { GenericConstructor } from '../types/GenericConstructor';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Mixin to add `delegatesFocus: true` to a LitElement's shadow root options.
|
|
6
|
+
* This is useful for custom elements that act like form controls, allowing focus
|
|
7
|
+
* to be automatically delegated to the first focusable element inside the shadow DOM.
|
|
8
|
+
*
|
|
9
|
+
* @param superClass - The LitElement class to extend.
|
|
10
|
+
* @returns A class extending the provided LitElement with the delegatesFocus behaviour.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import { LitElement, html } from 'lit';
|
|
15
|
+
* import { DelegatesFocusMixin } from './path-to-DelegatesFocusMixin'; // Update the import path
|
|
16
|
+
*
|
|
17
|
+
* // Create a new component using the DelegatesFocusMixin
|
|
18
|
+
* class MyCustomInput extends DelegatesFocusMixin(LitElement) {
|
|
19
|
+
* render() {
|
|
20
|
+
* // The focus will automatically go to the input when the component is focused
|
|
21
|
+
* return html`<input>`;
|
|
22
|
+
* }
|
|
23
|
+
* }
|
|
24
|
+
*
|
|
25
|
+
* customElements.define('my-custom-input', MyCustomInput);
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export const DelegatesFocusMixin =
|
|
29
|
+
<T extends GenericConstructor<LitElement>>(superClass: T) => {
|
|
30
|
+
/**
|
|
31
|
+
* A LitElement with `delegatesFocus` enabled on its shadow root.
|
|
32
|
+
* @extends {LitElement}
|
|
33
|
+
*/
|
|
34
|
+
class DelegatesFocusElement extends superClass {
|
|
35
|
+
/**
|
|
36
|
+
* Overrides shadow root options to include `delegatesFocus: true`, ensuring
|
|
37
|
+
* focus is passed into the component's shadow DOM to the first focusable element. It preserves
|
|
38
|
+
* any existing shadowRootOptions from the superclass.
|
|
39
|
+
*/
|
|
40
|
+
static shadowRootOptions = {
|
|
41
|
+
// The `as any` cast is a safe way to access the static property
|
|
42
|
+
// from the generic superclass constructor. LitElement provides a default.
|
|
43
|
+
// This is unfortunately unavoidable and a common issue with mixins in TS.
|
|
44
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
45
|
+
...(superClass as any).shadowRootOptions,
|
|
46
|
+
delegatesFocus: true,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return DelegatesFocusElement as T;
|
|
51
|
+
};
|