@justeattakeaway/pie-webc-core 18.0.0 → 18.1.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 +1 -7
- package/dist/index.js +50 -66
- package/package.json +1 -1
- package/src/decorators/index.ts +0 -1
- package/src/decorators/required-property.ts +0 -46
package/README.md
CHANGED
|
@@ -34,16 +34,10 @@ $ yarn add @justeattakeaway/pie-webc-core
|
|
|
34
34
|
## Importing the package
|
|
35
35
|
|
|
36
36
|
```js
|
|
37
|
-
import {
|
|
37
|
+
import { RtlMixin } from '@justeattakeaway/pie-webc-core';
|
|
38
38
|
|
|
39
39
|
export class MyComponent extends RtlMixin(LitElement) implements MyComponentProps {
|
|
40
40
|
// ...
|
|
41
|
-
|
|
42
|
-
@property({ type: String })
|
|
43
|
-
@requiredProperty('my-component')
|
|
44
|
-
public value!: string;
|
|
45
|
-
|
|
46
|
-
// ...
|
|
47
41
|
}
|
|
48
42
|
```
|
|
49
43
|
## Internals
|
package/dist/index.js
CHANGED
|
@@ -1,54 +1,39 @@
|
|
|
1
|
-
import { customElement as
|
|
1
|
+
import { customElement as c } from "lit/decorators.js";
|
|
2
2
|
/**
|
|
3
3
|
* @license
|
|
4
4
|
* Copyright 2021 Google LLC
|
|
5
5
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
6
6
|
*/
|
|
7
|
-
const
|
|
7
|
+
const b = Symbol("pie-aria"), h = Symbol("pie-parent-disabled"), p = (t, e, n) => function(i, r) {
|
|
8
8
|
const o = `#${r}`;
|
|
9
9
|
Object.defineProperty(i, r, {
|
|
10
10
|
get() {
|
|
11
11
|
return this[o];
|
|
12
12
|
},
|
|
13
13
|
set(a) {
|
|
14
|
-
|
|
14
|
+
e.includes(a) ? this[o] = a : (console.error(
|
|
15
15
|
`<${t}> Invalid value "${a}" provided for property "${r}".`,
|
|
16
|
-
`Must be one of: ${
|
|
16
|
+
`Must be one of: ${e.join(" | ")}.`,
|
|
17
17
|
`Falling back to default value: "${n}"`
|
|
18
18
|
), this[o] = n);
|
|
19
19
|
},
|
|
20
20
|
configurable: !0
|
|
21
21
|
});
|
|
22
|
-
}, u = (t) => t == null || typeof t == "string" && t.trim() === "", g = (t) => function(n, e) {
|
|
23
|
-
const i = `#${e}`, r = `#${e}HasBeenSet`, o = `#${e}HasWarned`;
|
|
24
|
-
Object.defineProperty(n, e, {
|
|
25
|
-
get() {
|
|
26
|
-
return this[i];
|
|
27
|
-
},
|
|
28
|
-
set(l) {
|
|
29
|
-
this[r] = !0, u(l) && console.error(`<${t}> Missing required attribute "${e}"`), this[i] = l;
|
|
30
|
-
},
|
|
31
|
-
configurable: !0
|
|
32
|
-
});
|
|
33
|
-
const a = n, c = a.connectedCallback;
|
|
34
|
-
a.connectedCallback = function() {
|
|
35
|
-
c == null || c.call(this), !this[r] && !this[o] && (this[o] = !0, console.error(`<${t}> Missing required attribute "${e}"`));
|
|
36
|
-
};
|
|
37
22
|
};
|
|
38
|
-
function
|
|
39
|
-
return (
|
|
23
|
+
function m(t) {
|
|
24
|
+
return (e) => {
|
|
40
25
|
try {
|
|
41
|
-
|
|
26
|
+
c(t)(e);
|
|
42
27
|
} catch (n) {
|
|
43
|
-
const
|
|
44
|
-
|
|
28
|
+
const s = customElements.get(t), i = s == null ? void 0 : s.v;
|
|
29
|
+
e.v !== i && console.warn(
|
|
45
30
|
`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."}.`,
|
|
46
31
|
n
|
|
47
32
|
);
|
|
48
33
|
}
|
|
49
34
|
};
|
|
50
35
|
}
|
|
51
|
-
function
|
|
36
|
+
function v(t) {
|
|
52
37
|
return new CustomEvent(t.type, {
|
|
53
38
|
detail: {
|
|
54
39
|
sourceEvent: t
|
|
@@ -57,28 +42,28 @@ function L(t) {
|
|
|
57
42
|
cancelable: t.cancelable
|
|
58
43
|
});
|
|
59
44
|
}
|
|
60
|
-
function
|
|
61
|
-
|
|
62
|
-
const
|
|
45
|
+
function f(t, e, n) {
|
|
46
|
+
e.startsWith("pie-") || console.warn("A custom event name should start with `pie-`");
|
|
47
|
+
const s = new CustomEvent(e, {
|
|
63
48
|
bubbles: !0,
|
|
64
49
|
composed: !0,
|
|
65
50
|
detail: n
|
|
66
51
|
});
|
|
67
|
-
t.dispatchEvent(
|
|
52
|
+
t.dispatchEvent(s);
|
|
68
53
|
}
|
|
69
|
-
function
|
|
54
|
+
function l() {
|
|
70
55
|
return typeof navigator < "u" && /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
|
|
71
56
|
}
|
|
72
|
-
const
|
|
73
|
-
class
|
|
57
|
+
const g = (t) => {
|
|
58
|
+
class e extends t {
|
|
74
59
|
constructor() {
|
|
75
60
|
super(...arguments), this._isRTL = !1, this.observer = null;
|
|
76
61
|
}
|
|
77
62
|
get isRTL() {
|
|
78
63
|
return this._isRTL;
|
|
79
64
|
}
|
|
80
|
-
set isRTL(
|
|
81
|
-
this._isRTL =
|
|
65
|
+
set isRTL(s) {
|
|
66
|
+
this._isRTL = s, this.requestUpdate();
|
|
82
67
|
}
|
|
83
68
|
connectedCallback() {
|
|
84
69
|
super.connectedCallback(), this.handleWritingDirectionUpdate(), this.observer = new MutationObserver(() => {
|
|
@@ -100,8 +85,8 @@ const T = (t) => {
|
|
|
100
85
|
this.isRTL = this.dir === "rtl" || document.documentElement.getAttribute("dir") === "rtl";
|
|
101
86
|
}
|
|
102
87
|
}
|
|
103
|
-
return
|
|
104
|
-
},
|
|
88
|
+
return e;
|
|
89
|
+
}, x = (t) => {
|
|
105
90
|
const n = class n extends t {
|
|
106
91
|
get form() {
|
|
107
92
|
return this._internals.form;
|
|
@@ -112,9 +97,9 @@ const T = (t) => {
|
|
|
112
97
|
}
|
|
113
98
|
};
|
|
114
99
|
n.formAssociated = !0;
|
|
115
|
-
let
|
|
116
|
-
return
|
|
117
|
-
},
|
|
100
|
+
let e = n;
|
|
101
|
+
return e;
|
|
102
|
+
}, L = (t) => {
|
|
118
103
|
const n = class n extends t {
|
|
119
104
|
};
|
|
120
105
|
n.shadowRootOptions = {
|
|
@@ -125,47 +110,46 @@ const T = (t) => {
|
|
|
125
110
|
...t.shadowRootOptions,
|
|
126
111
|
delegatesFocus: !0
|
|
127
112
|
};
|
|
128
|
-
let
|
|
129
|
-
return
|
|
130
|
-
},
|
|
131
|
-
var
|
|
132
|
-
return ((
|
|
133
|
-
}).filter(Boolean).join(" ").trim() || void 0,
|
|
134
|
-
class
|
|
113
|
+
let e = n;
|
|
114
|
+
return e;
|
|
115
|
+
}, d = (t) => Array.from(t).map((n) => {
|
|
116
|
+
var s;
|
|
117
|
+
return ((s = n.textContent) == null ? void 0 : s.replace(/\s+/g, " ").trim()) ?? "";
|
|
118
|
+
}).filter(Boolean).join(" ").trim() || void 0, T = (t) => {
|
|
119
|
+
class e extends t {
|
|
135
120
|
get associatedLabelText() {
|
|
136
121
|
return this._associatedLabelText;
|
|
137
122
|
}
|
|
138
|
-
firstUpdated(
|
|
139
|
-
super.firstUpdated(
|
|
123
|
+
firstUpdated(s) {
|
|
124
|
+
super.firstUpdated(s), this.observeAssociatedLabels();
|
|
140
125
|
}
|
|
141
126
|
disconnectedCallback() {
|
|
142
|
-
var
|
|
143
|
-
super.disconnectedCallback(), (
|
|
127
|
+
var s;
|
|
128
|
+
super.disconnectedCallback(), (s = this._labelMutationObserver) == null || s.disconnect();
|
|
144
129
|
}
|
|
145
130
|
updateAssociatedLabelText() {
|
|
146
|
-
this._associatedLabelText =
|
|
131
|
+
this._associatedLabelText = d(this._internals.labels), this.requestUpdate();
|
|
147
132
|
}
|
|
148
133
|
observeAssociatedLabels() {
|
|
149
|
-
const { labels:
|
|
150
|
-
!
|
|
134
|
+
const { labels: s } = this._internals;
|
|
135
|
+
!l() || !s.length || (this.updateAssociatedLabelText(), this._labelMutationObserver = new MutationObserver(() => this.updateAssociatedLabelText()), s.forEach((i) => {
|
|
151
136
|
var r;
|
|
152
137
|
(r = this._labelMutationObserver) == null || r.observe(i, { childList: !0, characterData: !0, subtree: !0 });
|
|
153
138
|
}));
|
|
154
139
|
}
|
|
155
140
|
}
|
|
156
|
-
return
|
|
141
|
+
return e;
|
|
157
142
|
};
|
|
158
143
|
export {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
v as
|
|
170
|
-
L as wrapNativeEvent
|
|
144
|
+
T as AssociatedLabelMixin,
|
|
145
|
+
L as DelegatesFocusMixin,
|
|
146
|
+
x as FormControlMixin,
|
|
147
|
+
g as RtlMixin,
|
|
148
|
+
b as ariaContext,
|
|
149
|
+
f as dispatchCustomEvent,
|
|
150
|
+
l as isSafari,
|
|
151
|
+
h as parentDisabledContext,
|
|
152
|
+
m as safeCustomElement,
|
|
153
|
+
p as validPropertyValues,
|
|
154
|
+
v as wrapNativeEvent
|
|
171
155
|
};
|
package/package.json
CHANGED
package/src/decorators/index.ts
CHANGED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
const isMissing = <T>(value: T): boolean => value === undefined || value === null || (typeof value === 'string' && value.trim() === '');
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* A decorator for marking a property as required.
|
|
5
|
-
* If the property's value is `undefined`, `null` or empty string, an error is logged.
|
|
6
|
-
*
|
|
7
|
-
* This also checks on `connectedCallback` so a missing required property is still reported
|
|
8
|
-
* even when the corresponding attribute is never set at all (in which case the property
|
|
9
|
-
* setter below is never invoked).
|
|
10
|
-
* @returns {Function} - The decorator function.
|
|
11
|
-
*/
|
|
12
|
-
export const requiredProperty = <T>(componentName: string) => function validateRequiredProperty (target: object, propertyKey: string): void {
|
|
13
|
-
const privatePropertyKey = `#${propertyKey}`;
|
|
14
|
-
const hasBeenSetKey = `#${propertyKey}HasBeenSet`;
|
|
15
|
-
const hasWarnedKey = `#${propertyKey}HasWarned`;
|
|
16
|
-
|
|
17
|
-
Object.defineProperty(target, propertyKey, {
|
|
18
|
-
get (): T {
|
|
19
|
-
return this[privatePropertyKey];
|
|
20
|
-
},
|
|
21
|
-
set (value: T): void {
|
|
22
|
-
this[hasBeenSetKey] = true;
|
|
23
|
-
|
|
24
|
-
if (isMissing(value)) {
|
|
25
|
-
console.error(`<${componentName}> Missing required attribute "${propertyKey}"`);
|
|
26
|
-
}
|
|
27
|
-
this[privatePropertyKey] = value;
|
|
28
|
-
},
|
|
29
|
-
configurable: true,
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
const elementProto = target as { connectedCallback?: (this: Record<string, unknown>) => void };
|
|
33
|
-
const originalConnectedCallback = elementProto.connectedCallback;
|
|
34
|
-
|
|
35
|
-
elementProto.connectedCallback = function connectedCallback (this: Record<string, unknown>): void {
|
|
36
|
-
originalConnectedCallback?.call(this);
|
|
37
|
-
|
|
38
|
-
// Guard with a dedicated "has warned" flag (rather than reusing hasBeenSetKey) so an
|
|
39
|
-
// element that reconnects repeatedly while still missing the prop (e.g. a virtualised
|
|
40
|
-
// list recycling DOM nodes) only logs once, instead of on every reconnect.
|
|
41
|
-
if (!this[hasBeenSetKey] && !this[hasWarnedKey]) {
|
|
42
|
-
this[hasWarnedKey] = true;
|
|
43
|
-
console.error(`<${componentName}> Missing required attribute "${propertyKey}"`);
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
};
|