@justeattakeaway/pie-webc-core 16.0.0 → 16.1.1

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,7 +1,12 @@
1
1
  import { customElement as d } from "lit/decorators.js";
2
- const p = (t, s, i) => function(n, r) {
2
+ /**
3
+ * @license
4
+ * Copyright 2021 Google LLC
5
+ * SPDX-License-Identifier: BSD-3-Clause
6
+ */
7
+ const p = Symbol("pie-aria"), m = Symbol("pie-parent-disabled"), v = (t, s, n) => function(i, r) {
3
8
  const o = `#${r}`;
4
- Object.defineProperty(n, r, {
9
+ Object.defineProperty(i, r, {
5
10
  get() {
6
11
  return this[o];
7
12
  },
@@ -9,41 +14,41 @@ const p = (t, s, i) => function(n, r) {
9
14
  s.includes(a) ? this[o] = a : (console.error(
10
15
  `<${t}> Invalid value "${a}" provided for property "${r}".`,
11
16
  `Must be one of: ${s.join(" | ")}.`,
12
- `Falling back to default value: "${i}"`
13
- ), this[o] = i);
17
+ `Falling back to default value: "${n}"`
18
+ ), this[o] = n);
14
19
  },
15
20
  configurable: !0
16
21
  });
17
- }, u = (t) => t == null || typeof t == "string" && t.trim() === "", v = (t) => function(i, e) {
18
- const n = `#${e}`, r = `#${e}HasBeenSet`, o = `#${e}HasWarned`;
19
- Object.defineProperty(i, e, {
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, {
20
25
  get() {
21
- return this[n];
26
+ return this[i];
22
27
  },
23
28
  set(l) {
24
- this[r] = !0, u(l) && console.error(`<${t}> Missing required attribute "${e}"`), this[n] = l;
29
+ this[r] = !0, u(l) && console.error(`<${t}> Missing required attribute "${e}"`), this[i] = l;
25
30
  },
26
31
  configurable: !0
27
32
  });
28
- const a = i, c = a.connectedCallback;
33
+ const a = n, c = a.connectedCallback;
29
34
  a.connectedCallback = function() {
30
35
  c == null || c.call(this), !this[r] && !this[o] && (this[o] = !0, console.error(`<${t}> Missing required attribute "${e}"`));
31
36
  };
32
37
  };
33
- function m(t) {
38
+ function x(t) {
34
39
  return (s) => {
35
40
  try {
36
41
  d(t)(s);
37
- } catch (i) {
38
- const e = customElements.get(t), n = e == null ? void 0 : e.v;
39
- s.v !== n && console.warn(
40
- `PIE Web Component: "${t}" was already registered with version: ${n ?? "No version data found. Icon components do not contain version data. If the component is not an icon, please report the missing version data."}.`,
41
- i
42
+ } catch (n) {
43
+ const e = customElements.get(t), i = e == null ? void 0 : e.v;
44
+ s.v !== i && console.warn(
45
+ `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
+ n
42
47
  );
43
48
  }
44
49
  };
45
50
  }
46
- function g(t) {
51
+ function L(t) {
47
52
  return new CustomEvent(t.type, {
48
53
  detail: {
49
54
  sourceEvent: t
@@ -52,19 +57,19 @@ function g(t) {
52
57
  cancelable: t.cancelable
53
58
  });
54
59
  }
55
- function x(t, s, i) {
60
+ function M(t, s, n) {
56
61
  s.startsWith("pie-") || console.warn("A custom event name should start with `pie-`");
57
62
  const e = new CustomEvent(s, {
58
63
  bubbles: !0,
59
64
  composed: !0,
60
- detail: i
65
+ detail: n
61
66
  });
62
67
  t.dispatchEvent(e);
63
68
  }
64
69
  function b() {
65
70
  return typeof navigator < "u" && /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
66
71
  }
67
- const L = (t) => {
72
+ const T = (t) => {
68
73
  class s extends t {
69
74
  constructor() {
70
75
  super(...arguments), this._isRTL = !1, this.observer = null;
@@ -96,23 +101,23 @@ const L = (t) => {
96
101
  }
97
102
  }
98
103
  return s;
99
- }, M = (t) => {
100
- const i = class i extends t {
104
+ }, $ = (t) => {
105
+ const n = class n extends t {
101
106
  get form() {
102
107
  return this._internals.form;
103
108
  }
104
109
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
105
- constructor(...n) {
106
- super(...n), this._internals = this.attachInternals();
110
+ constructor(...i) {
111
+ super(...i), this._internals = this.attachInternals();
107
112
  }
108
113
  };
109
- i.formAssociated = !0;
110
- let s = i;
114
+ n.formAssociated = !0;
115
+ let s = n;
111
116
  return s;
112
- }, T = (t) => {
113
- const i = class i extends t {
117
+ }, E = (t) => {
118
+ const n = class n extends t {
114
119
  };
115
- i.shadowRootOptions = {
120
+ n.shadowRootOptions = {
116
121
  // The `as any` cast is a safe way to access the static property
117
122
  // from the generic superclass constructor. LitElement provides a default.
118
123
  // This is unfortunately unavoidable and a common issue with mixins in TS.
@@ -120,12 +125,12 @@ const L = (t) => {
120
125
  ...t.shadowRootOptions,
121
126
  delegatesFocus: !0
122
127
  };
123
- let s = i;
128
+ let s = n;
124
129
  return s;
125
- }, h = (t) => Array.from(t).map((i) => {
130
+ }, h = (t) => Array.from(t).map((n) => {
126
131
  var e;
127
- return ((e = i.textContent) == null ? void 0 : e.replace(/\s+/g, " ").trim()) ?? "";
128
- }).filter(Boolean).join(" ").trim() || void 0, $ = (t) => {
132
+ return ((e = n.textContent) == null ? void 0 : e.replace(/\s+/g, " ").trim()) ?? "";
133
+ }).filter(Boolean).join(" ").trim() || void 0, w = (t) => {
129
134
  class s extends t {
130
135
  get associatedLabelText() {
131
136
  return this._associatedLabelText;
@@ -142,23 +147,25 @@ const L = (t) => {
142
147
  }
143
148
  observeAssociatedLabels() {
144
149
  const { labels: e } = this._internals;
145
- !b() || !e.length || (this.updateAssociatedLabelText(), this._labelMutationObserver = new MutationObserver(() => this.updateAssociatedLabelText()), e.forEach((n) => {
150
+ !b() || !e.length || (this.updateAssociatedLabelText(), this._labelMutationObserver = new MutationObserver(() => this.updateAssociatedLabelText()), e.forEach((i) => {
146
151
  var r;
147
- (r = this._labelMutationObserver) == null || r.observe(n, { childList: !0, characterData: !0, subtree: !0 });
152
+ (r = this._labelMutationObserver) == null || r.observe(i, { childList: !0, characterData: !0, subtree: !0 });
148
153
  }));
149
154
  }
150
155
  }
151
156
  return s;
152
157
  };
153
158
  export {
154
- $ as AssociatedLabelMixin,
155
- T as DelegatesFocusMixin,
156
- M as FormControlMixin,
157
- L as RtlMixin,
158
- x as dispatchCustomEvent,
159
+ w as AssociatedLabelMixin,
160
+ E as DelegatesFocusMixin,
161
+ $ as FormControlMixin,
162
+ T as RtlMixin,
163
+ p as ariaContext,
164
+ M as dispatchCustomEvent,
159
165
  b as isSafari,
160
- v as requiredProperty,
161
- m as safeCustomElement,
162
- p as validPropertyValues,
163
- g as wrapNativeEvent
166
+ m as parentDisabledContext,
167
+ g as requiredProperty,
168
+ x as safeCustomElement,
169
+ v as validPropertyValues,
170
+ L as wrapNativeEvent
164
171
  };
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "@justeattakeaway/pie-webc-core",
3
- "version": "16.0.0",
3
+ "version": "16.1.1",
4
4
  "description": "PIE design system base classes, mixins and utilities for web components",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "author": "Just Eat Takeaway.com - Design System Team",
8
8
  "license": "Apache-2.0",
9
9
  "files": [
10
+ "src/context",
10
11
  "src/decorators",
11
12
  "src/functions",
12
13
  "src/interfaces",
@@ -25,7 +26,8 @@
25
26
  "test:watch": "run -T vitest"
26
27
  },
27
28
  "dependencies": {
28
- "lit": "3.2.0"
29
+ "@lit/context": "1.1.6",
30
+ "lit": "3.3.3"
29
31
  },
30
32
  "peerDependencies": {
31
33
  "@justeattakeaway/pie-css": "1.x"
@@ -0,0 +1,35 @@
1
+ import { createContext } from '@lit/context';
2
+
3
+ /**
4
+ * A bag of accessible-name/description values an ancestor component can supply to a descendant
5
+ * across the shadow boundary (where `aria-labelledby` / `aria-describedby` IDREFs cannot reach).
6
+ * Restricted to string ARIA that can be applied directly to an element.
7
+ *
8
+ * This is deliberately an extensible bag: any provider can set it (for example a `pie-list-item`
9
+ * stitching its text), and any component can consume it and decide for itself what to do with each
10
+ * field, applying it to whichever element carries its semantics. Extend it with further optional
11
+ * string/boolean ARIA as needed; a consumer simply ignores fields it does not apply. There is no
12
+ * shared "apply" helper on purpose: where and how each field maps is component-specific (a radio
13
+ * names its host, a checkbox its internal input), so each subscriber owns that logic even if a
14
+ * little set/remove code is repeated. That keeps the contract open to new ARIA without a central
15
+ * mapper having to know how every component applies it.
16
+ */
17
+ export interface ContextualAria {
18
+ label?: string;
19
+ description?: string;
20
+ }
21
+
22
+ /**
23
+ * Context carrying a `ContextualAria` from a provider down to a consuming component. `undefined`
24
+ * when no ancestor provides ARIA (for example a standalone control).
25
+ *
26
+ * Why a context rather than ARIA props on each component:
27
+ * - it lets a wrapper name a control it does not own, carrying a resolved string across the shadow
28
+ * boundary that `aria-labelledby` / `aria-describedby` IDREFs cannot cross;
29
+ * - it reaches consumers at any depth below the provider without prop drilling through the layers
30
+ * in between;
31
+ * - it decouples provider from consumer (neither needs a reference to, or knowledge of, the other)
32
+ * and is extensible by adding optional fields that consumers opt into.
33
+ * It is always a fallback behind a control's own ARIA props.
34
+ */
35
+ export const ariaContext = createContext<ContextualAria | undefined>(Symbol('pie-aria'));
@@ -0,0 +1,12 @@
1
+ import { createContext } from '@lit/context';
2
+
3
+ /**
4
+ * Context a container uses to tell its descendants it is disabled, so they can reflect it (for
5
+ * example a disabled `pie-radio-group` / `pie-checkbox-group` suppressing a `pie-list-item`'s
6
+ * interactive hover and active states). Defaults to `false` when no ancestor provides it.
7
+ *
8
+ * This is deliberately generic: any disabling ancestor can provide it and any descendant can
9
+ * consume it. Like `ariaContext`, it crosses shadow boundaries and reaches descendants at any depth
10
+ * without prop drilling, and decouples the provider from the consumer.
11
+ */
12
+ export const parentDisabledContext = createContext<boolean>(Symbol('pie-parent-disabled'));
@@ -0,0 +1,2 @@
1
+ export * from './aria-context';
2
+ export * from './disabled-context';
package/src/index.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export * from './context';
1
2
  export * from './decorators';
2
3
  export * from './functions';
3
4
  export * from './interfaces';