@justeattakeaway/pie-webc-core 18.0.0 → 19.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/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 { RequiredProperty, RtlMixin } from '@justeattakeaway/pie-webc-core';
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 d } from "lit/decorators.js";
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 p = Symbol("pie-aria"), m = Symbol("pie-parent-disabled"), v = (t, s, n) => function(i, r) {
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
- s.includes(a) ? this[o] = a : (console.error(
14
+ e.includes(a) ? this[o] = a : (console.error(
15
15
  `<${t}> Invalid value "${a}" provided for property "${r}".`,
16
- `Must be one of: ${s.join(" | ")}.`,
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 x(t) {
39
- return (s) => {
23
+ function m(t) {
24
+ return (e) => {
40
25
  try {
41
- d(t)(s);
26
+ c(t)(e);
42
27
  } catch (n) {
43
- const e = customElements.get(t), i = e == null ? void 0 : e.v;
44
- s.v !== i && console.warn(
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 L(t) {
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 M(t, s, n) {
61
- s.startsWith("pie-") || console.warn("A custom event name should start with `pie-`");
62
- const e = new CustomEvent(s, {
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(e);
52
+ t.dispatchEvent(s);
68
53
  }
69
- function b() {
54
+ function l() {
70
55
  return typeof navigator < "u" && /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
71
56
  }
72
- const T = (t) => {
73
- class s extends t {
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(e) {
81
- this._isRTL = e, this.requestUpdate();
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 s;
104
- }, $ = (t) => {
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 s = n;
116
- return s;
117
- }, E = (t) => {
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 s = n;
129
- return s;
130
- }, h = (t) => Array.from(t).map((n) => {
131
- var e;
132
- return ((e = n.textContent) == null ? void 0 : e.replace(/\s+/g, " ").trim()) ?? "";
133
- }).filter(Boolean).join(" ").trim() || void 0, w = (t) => {
134
- class s extends t {
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(e) {
139
- super.firstUpdated(e), this.observeAssociatedLabels();
123
+ firstUpdated(s) {
124
+ super.firstUpdated(s), this.observeAssociatedLabels();
140
125
  }
141
126
  disconnectedCallback() {
142
- var e;
143
- super.disconnectedCallback(), (e = this._labelMutationObserver) == null || e.disconnect();
127
+ var s;
128
+ super.disconnectedCallback(), (s = this._labelMutationObserver) == null || s.disconnect();
144
129
  }
145
130
  updateAssociatedLabelText() {
146
- this._associatedLabelText = h(this._internals.labels), this.requestUpdate();
131
+ this._associatedLabelText = d(this._internals.labels), this.requestUpdate();
147
132
  }
148
133
  observeAssociatedLabels() {
149
- const { labels: e } = this._internals;
150
- !b() || !e.length || (this.updateAssociatedLabelText(), this._labelMutationObserver = new MutationObserver(() => this.updateAssociatedLabelText()), e.forEach((i) => {
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 s;
141
+ return e;
157
142
  };
158
143
  export {
159
- w as AssociatedLabelMixin,
160
- E as DelegatesFocusMixin,
161
- $ as FormControlMixin,
162
- T as RtlMixin,
163
- p as ariaContext,
164
- M as dispatchCustomEvent,
165
- b as isSafari,
166
- m as parentDisabledContext,
167
- g as requiredProperty,
168
- x as safeCustomElement,
169
- v as validPropertyValues,
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@justeattakeaway/pie-webc-core",
3
- "version": "18.0.0",
3
+ "version": "19.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",
@@ -1,3 +1,2 @@
1
1
  export * from './valid-property-values';
2
- export * from './required-property';
3
2
  export * from './safe-custom-element';
@@ -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
- };