@viasat/beam-web-components 2.69.0 → 2.71.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.
@@ -20,11 +20,26 @@ export declare class FormField extends LitElement {
20
20
  value: string;
21
21
  validationRules: Array<FormValidator>;
22
22
  inputAriaLabel: Optional<string>;
23
+ /**
24
+ * Specify error text and display error state.
25
+ * Pass a string to show an error message, or `true` to show the error
26
+ * state without a message.
27
+ */
28
+ error?: Optional<boolean | string>;
23
29
  formContext: BmFormContext;
24
30
  private _validationErrors;
25
31
  protected validationErrors: () => Array<Optional<string>>;
32
+ protected resolveError: () => {
33
+ invalid: boolean;
34
+ errorMessage: Optional<string>;
35
+ };
26
36
  protected setAssociatedValue(value: FormValue): void;
27
37
  protected requestAssociatedSubmit(): void;
38
+ get validity(): ValidityState;
39
+ get validationMessage(): string;
40
+ get willValidate(): boolean;
41
+ checkValidity(): boolean;
42
+ reportValidity(): boolean;
28
43
  protected setValidationErrors: (errors: Array<Optional<string>>) => void;
29
44
  protected validationErrorShown: () => boolean;
30
45
  connectedCallback(): void;
@@ -37,11 +52,13 @@ export declare class FormField extends LitElement {
37
52
  protected forwardLabelFocus: () => void;
38
53
  protected validateFieldOnBlur: (event: FocusEvent) => void;
39
54
  protected validateFieldOnChange: (event: Event) => void;
55
+ protected syncValidity: () => void;
56
+ updated(cP: Map<string, unknown>): void;
40
57
  protected getContextValue: () => string;
41
58
  protected setContextValue: () => void;
42
59
  protected setContextValidation: () => void;
43
60
  protected contextInitialsChanged: () => boolean;
44
- protected renderError: (error: Optional<string>, disabled: boolean) => typeof nothing | import('lit').TemplateResult<1>;
45
- protected renderValidationErrors: () => typeof nothing | import('lit').TemplateResult<1>;
61
+ protected renderError: (error: Optional<string>, disabled: boolean) => import('lit').TemplateResult<1> | typeof nothing;
62
+ protected renderValidationErrors: () => import('lit').TemplateResult<1> | typeof nothing;
46
63
  }
47
64
  //# sourceMappingURL=Form.decorator.d.ts.map
@@ -1,65 +1,88 @@
1
- var V = (a) => {
2
- throw TypeError(a);
1
+ var C = (e) => {
2
+ throw TypeError(e);
3
3
  };
4
- var y = (a, r, t) => r.has(a) || V("Cannot " + t);
5
- var f = (a, r, t) => (y(a, r, "read from private field"), t ? t.call(a) : r.get(a)), b = (a, r, t) => r.has(a) ? V("Cannot add the same private member more than once") : r instanceof WeakSet ? r.add(a) : r.set(a, t), m = (a, r, t, e) => (y(a, r, "write to private field"), e ? e.call(a, t) : r.set(a, t), t);
6
- import { consume as E } from "@lit/context";
7
- import { LitElement as k, nothing as v, html as x } from "lit";
8
- import { property as d, state as A } from "lit/decorators.js";
9
- import { createRef as F } from "lit/directives/ref.js";
10
- import { b as I } from "../../chunks/tokens.CTW8Tt94.js";
11
- import { bmFormInitials as u, bmFormContext as S } from "./Form.context.js";
12
- import { createId as p } from "./Form.utils.js";
4
+ var E = (e, s, t) => s.has(e) || C("Cannot " + t);
5
+ var h = (e, s, t) => (E(e, s, "read from private field"), t ? t.call(e) : s.get(e)), y = (e, s, t) => s.has(e) ? C("Cannot add the same private member more than once") : s instanceof WeakSet ? s.add(e) : s.set(e, t), f = (e, s, t, i) => (E(e, s, "write to private field"), i ? i.call(e, t) : s.set(e, t), t);
6
+ import { consume as k } from "@lit/context";
7
+ import { LitElement as F, nothing as V, html as g } from "lit";
8
+ import { property as u, state as A } from "lit/decorators.js";
9
+ import { createRef as I } from "lit/directives/ref.js";
10
+ import { b as S } from "../../chunks/tokens.CTW8Tt94.js";
11
+ import { bmFormInitials as p, bmFormContext as R } from "./Form.context.js";
12
+ import { createId as b } from "./Form.utils.js";
13
13
  import "../../chunks/HelperText.Cc_6DlKP.js";
14
- var R = Object.defineProperty, l = (a, r, t, e) => {
15
- for (var i = void 0, s = a.length - 1, c; s >= 0; s--)
16
- (c = a[s]) && (i = c(r, t, i) || i);
17
- return i && R(r, t, i), i;
18
- }, n, h;
19
- const C = class C extends k {
14
+ var w = Object.defineProperty, l = (e, s, t, i) => {
15
+ for (var r = void 0, a = e.length - 1, n; a >= 0; a--)
16
+ (n = e[a]) && (r = n(s, t, r) || r);
17
+ return r && w(s, t, r), r;
18
+ }, d, c, m;
19
+ const x = class x extends F {
20
20
  constructor() {
21
21
  super(...arguments);
22
- b(this, n);
23
- b(this, h);
24
- this.labelId = p(), this.errorId = p(), this.helperTextId = p(), this.validationErrorsId = p(), this.internals = this.attachInternals(), this.formFieldRef = F(), this.id = "", this.name = "", this.value = "", this.validationRules = [], this._validationErrors = [], this.validationErrors = () => this._validationErrors, m(this, n, !1), this.setValidationErrors = (t) => {
25
- this._validationErrors = t;
26
- }, this.validationErrorShown = () => this.validationErrors().some((t) => !!(t != null && t.length)), m(this, h, /* @__PURE__ */ new WeakMap()), this.submitFormByEnter = ({ key: t }) => {
22
+ y(this, d);
23
+ // Captured once, on first form association. Native reset restores this
24
+ // value; bm-form's initialValues seed is a separate concern, handled in
25
+ // formResetCallback below.
26
+ y(this, c);
27
+ y(this, m);
28
+ this.labelId = b(), this.errorId = b(), this.helperTextId = b(), this.validationErrorsId = b(), this.internals = this.attachInternals(), this.formFieldRef = I(), this.id = "", this.name = "", this.value = "", this.validationRules = [], this._validationErrors = [], this.validationErrors = () => this._validationErrors, this.resolveError = () => ({
29
+ invalid: !!this.error,
30
+ errorMessage: typeof this.error == "string" && this.error.length ? this.error : void 0
31
+ }), f(this, d, !1), this.setValidationErrors = (t) => {
32
+ this._validationErrors = t, this.syncValidity();
33
+ }, this.validationErrorShown = () => this.validationErrors().some((t) => !!(t != null && t.length)), f(this, m, /* @__PURE__ */ new WeakMap()), this.submitFormByEnter = ({ key: t }) => {
27
34
  t === "Enter" && this.requestAssociatedSubmit();
28
35
  }, this.forwardLabelFocus = () => {
29
36
  const { value: t } = this.formFieldRef;
30
37
  t.focus();
31
38
  }, this.validateFieldOnBlur = (t) => {
32
- const { formBlurHandler: e } = this.formContext || u;
33
- e(t);
39
+ const { formBlurHandler: i } = this.formContext || p;
40
+ i(t);
34
41
  }, this.validateFieldOnChange = (t) => {
35
- const { value: e } = t.target, { formChangeHandler: i } = this.formContext || u;
36
- i(t), this.setAssociatedValue(e);
42
+ const { value: i } = t.target, { formChangeHandler: r } = this.formContext || p;
43
+ r(t), this.setAssociatedValue(i), this.syncValidity();
44
+ }, this.syncValidity = () => {
45
+ const { value: t } = this.formFieldRef;
46
+ if (!t) return;
47
+ const i = t, { validity: r, validationMessage: a } = i;
48
+ if (!r.valid) {
49
+ this.internals.setValidity(r, a, i);
50
+ return;
51
+ }
52
+ const n = this.validationErrors().find(
53
+ (v) => !!v
54
+ );
55
+ if (n) {
56
+ this.internals.setValidity({ customError: !0 }, n, i);
57
+ return;
58
+ }
59
+ this.internals.setValidity({});
37
60
  }, this.getContextValue = () => {
38
- const { initialValues: t } = this.formContext || u;
61
+ const { initialValues: t } = this.formContext || p;
39
62
  return (t == null ? void 0 : t[this.name]) || this.value;
40
63
  }, this.setContextValue = () => {
41
- const { value: t } = this.formFieldRef, { ctxValue: e, finalizeCallback: i = () => {
42
- } } = this.finalizeAssociatedCallback(this.getContextValue()), s = t;
43
- s.value !== e && (s.value = e), this.setAssociatedValue(e), i();
64
+ const { value: t } = this.formFieldRef, { ctxValue: i, finalizeCallback: r = () => {
65
+ } } = this.finalizeAssociatedCallback(this.getContextValue()), a = t;
66
+ a.value !== i && (a.value = i, r()), this.setAssociatedValue(i), this.syncValidity();
44
67
  }, this.setContextValidation = () => {
45
- const { value: t } = this.formFieldRef, { registerField: e } = this.formContext || u;
46
- e({
68
+ const { value: t } = this.formFieldRef, { registerField: i } = this.formContext || p;
69
+ i({
47
70
  field: t,
48
71
  validators: this.validationRules,
49
72
  initializer: this.setContextValue,
50
73
  errorSetter: this.setValidationErrors
51
74
  });
52
75
  }, this.contextInitialsChanged = () => {
53
- const { initialValues: t } = this.formContext || u, e = t == null ? void 0 : t[this.name], i = e !== this.contextInitialValue;
54
- return i && (this.contextInitialValue = e), i;
55
- }, this.renderError = (t, e) => t ? x`
76
+ const { initialValues: t } = this.formContext || p, i = t == null ? void 0 : t[this.name], r = i !== this.contextInitialValue;
77
+ return r && (this.contextInitialValue = i), r;
78
+ }, this.renderError = (t, i) => t ? g`
56
79
  <bm-helper-text
57
80
  text="${t}"
58
81
  id="${this.errorId}"
59
82
  appearance="negative"
60
- .disabled="${e}"
83
+ .disabled="${i}"
61
84
  ></bm-helper-text>
62
- ` : v, this.renderValidationErrors = () => this.validationErrorShown() ? x`
85
+ ` : V, this.renderValidationErrors = () => this.validationErrorShown() ? g`
63
86
  <div
64
87
  role="log"
65
88
  aria-live="polite"
@@ -68,78 +91,111 @@ const C = class C extends k {
68
91
  id="${this.validationErrorsId}"
69
92
  >
70
93
  ${this.validationErrors().map(
71
- (t) => t ? x`
94
+ (t) => t ? g`
72
95
  <bm-helper-text
73
96
  text="${t}"
74
97
  appearance="negative"
75
- style="display: block; margin-top: ${I};"
98
+ style="display: block; margin-top: ${S};"
76
99
  ></bm-helper-text>
77
- ` : v
100
+ ` : V
78
101
  )}
79
102
  </div>
80
- ` : v;
103
+ ` : V;
81
104
  }
82
105
  setAssociatedValue(t) {
83
106
  if (typeof t == "string") {
84
- if (this.value === t && f(this, n)) return;
107
+ if (this.value === t && h(this, d)) return;
85
108
  this.value = t;
86
109
  }
87
- let e = null;
110
+ let i = null;
88
111
  if (typeof t == "boolean")
89
- e = t ? "on" : null;
112
+ i = t ? "on" : null;
90
113
  else if (typeof t == "number")
91
- e = t.toString();
114
+ i = t.toString();
92
115
  else if (Array.isArray(t)) {
93
- const i = new FormData();
94
- t.forEach((s) => i.append(this.name, s.toString())), e = i;
116
+ const r = new FormData();
117
+ t.forEach((a) => r.append(this.name, a.toString())), i = r;
95
118
  } else
96
- e = t;
97
- m(this, n, !0), this.internals.form && this.internals.setFormValue(e);
119
+ i = t;
120
+ f(this, d, !0), this.internals.form && this.internals.setFormValue(i);
98
121
  }
99
122
  requestAssociatedSubmit() {
100
123
  this.internals.form && this.internals.form.requestSubmit();
101
124
  }
125
+ // ElementInternals holds the real validity state, but nothing exposes it
126
+ // on the element unless we delegate it. Without this, field.checkValidity()
127
+ // and field.validity.valueMissing throw, even though :invalid CSS and
128
+ // native form submission already work.
129
+ get validity() {
130
+ return this.internals.validity;
131
+ }
132
+ get validationMessage() {
133
+ return this.internals.validationMessage;
134
+ }
135
+ get willValidate() {
136
+ return this.internals.willValidate;
137
+ }
138
+ checkValidity() {
139
+ return this.internals.checkValidity();
140
+ }
141
+ reportValidity() {
142
+ return this.internals.reportValidity();
143
+ }
102
144
  connectedCallback() {
103
145
  super.connectedCallback(), this.addEventListener("bm-label-click", this.forwardLabelFocus);
104
146
  }
105
- ctxValueChanged(t, e) {
106
- const { value: i } = e, s = f(this, h).get(i), { initialValues: { [this.name]: c } = {} } = t, g = c !== s;
107
- return g && f(this, h).set(i, c), g;
147
+ ctxValueChanged(t, i) {
148
+ const { value: r } = i, a = h(this, m).get(r), { initialValues: { [this.name]: n } = {} } = t, v = n !== a;
149
+ return v && h(this, m).set(r, n), v;
108
150
  }
109
151
  disconnectedCallback() {
110
152
  super.disconnectedCallback(), this.removeEventListener("bm-label-click", this.forwardLabelFocus);
111
153
  }
112
154
  formAssociatedCallback() {
113
- m(this, n, !1), this.setAssociatedValue(this.value);
155
+ f(this, d, !1), h(this, c) === void 0 && f(this, c, this.value), this.setAssociatedValue(this.value), this.syncValidity();
114
156
  }
115
157
  formResetCallback() {
116
- this.setContextValue();
158
+ !this.formContext && h(this, c) !== void 0 && (this.value = h(this, c)), this.setContextValue();
117
159
  }
118
160
  finalizeAssociatedCallback(t) {
119
161
  return { ctxValue: t, finalizeCallback: () => {
120
162
  } };
121
163
  }
164
+ // Any reactive prop can change what's valid (required, minLength,
165
+ // maxLength), not just a keystroke. Owning this here, not in each
166
+ // subclass's updated(), means every FormField subclass that opts in
167
+ // gets it as long as it calls super.updated(cP) — see TextField.ts/TextArea.ts.
168
+ updated(t) {
169
+ super.updated(t), this.syncValidity();
170
+ }
122
171
  };
123
- n = new WeakMap(), h = new WeakMap(), C.formAssociated = !0;
124
- let o = C;
172
+ d = new WeakMap(), c = new WeakMap(), m = new WeakMap(), x.formAssociated = !0;
173
+ let o = x;
125
174
  l([
126
- d({ type: String })
175
+ u({ type: String })
127
176
  ], o.prototype, "id");
128
177
  l([
129
- d({ type: String, reflect: !0 })
178
+ u({ type: String, reflect: !0 })
130
179
  ], o.prototype, "name");
131
180
  l([
132
- d({ type: String })
181
+ u({ type: String })
133
182
  ], o.prototype, "value");
134
183
  l([
135
- d({ type: Array })
184
+ u({ type: Array })
136
185
  ], o.prototype, "validationRules");
137
186
  l([
138
- d({ type: String, attribute: "input-aria-label" })
187
+ u({ type: String, attribute: "input-aria-label" })
139
188
  ], o.prototype, "inputAriaLabel");
140
189
  l([
141
- E({ context: S, subscribe: !0 }),
142
- d({ attribute: !1 })
190
+ u({
191
+ converter: {
192
+ fromAttribute: (e) => e === null ? void 0 : e === "" ? !0 : e
193
+ }
194
+ })
195
+ ], o.prototype, "error");
196
+ l([
197
+ k({ context: R, subscribe: !0 }),
198
+ u({ attribute: !1 })
143
199
  ], o.prototype, "formContext");
144
200
  l([
145
201
  A()
@@ -28,10 +28,6 @@ export declare class BmNativeSelect extends FormField {
28
28
  * @default false
29
29
  */
30
30
  disabled: boolean;
31
- /**
32
- * Specify error text and display error state of a NativeSelect
33
- */
34
- error: Optional<string>;
35
31
  /**
36
32
  * Specify if NativeSelect is fluid
37
33
  * @default false