@vonage/vivid 3.0.0-next.16 → 3.0.0-next.19

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/shared/focus2.js CHANGED
@@ -1,5 +1,468 @@
1
- import { F as FoundationElement } from './index.js';
1
+ import { e as emptyArray, D as DOM, a as attr, o as observable, h as html } from './index.js';
2
+ import { F as Focus } from './focus.js';
2
3
 
3
- class Focus extends FoundationElement {}
4
+ /**
5
+ * Key Code values
6
+ * @deprecated - KeyCodes are deprecated, use individual string key exports
7
+ */
8
+ var KeyCodes;
9
+ (function (KeyCodes) {
10
+ KeyCodes[KeyCodes["alt"] = 18] = "alt";
11
+ KeyCodes[KeyCodes["arrowDown"] = 40] = "arrowDown";
12
+ KeyCodes[KeyCodes["arrowLeft"] = 37] = "arrowLeft";
13
+ KeyCodes[KeyCodes["arrowRight"] = 39] = "arrowRight";
14
+ KeyCodes[KeyCodes["arrowUp"] = 38] = "arrowUp";
15
+ KeyCodes[KeyCodes["back"] = 8] = "back";
16
+ KeyCodes[KeyCodes["backSlash"] = 220] = "backSlash";
17
+ KeyCodes[KeyCodes["break"] = 19] = "break";
18
+ KeyCodes[KeyCodes["capsLock"] = 20] = "capsLock";
19
+ KeyCodes[KeyCodes["closeBracket"] = 221] = "closeBracket";
20
+ KeyCodes[KeyCodes["colon"] = 186] = "colon";
21
+ KeyCodes[KeyCodes["colon2"] = 59] = "colon2";
22
+ KeyCodes[KeyCodes["comma"] = 188] = "comma";
23
+ KeyCodes[KeyCodes["ctrl"] = 17] = "ctrl";
24
+ KeyCodes[KeyCodes["delete"] = 46] = "delete";
25
+ KeyCodes[KeyCodes["end"] = 35] = "end";
26
+ KeyCodes[KeyCodes["enter"] = 13] = "enter";
27
+ KeyCodes[KeyCodes["equals"] = 187] = "equals";
28
+ KeyCodes[KeyCodes["equals2"] = 61] = "equals2";
29
+ KeyCodes[KeyCodes["equals3"] = 107] = "equals3";
30
+ KeyCodes[KeyCodes["escape"] = 27] = "escape";
31
+ KeyCodes[KeyCodes["forwardSlash"] = 191] = "forwardSlash";
32
+ KeyCodes[KeyCodes["function1"] = 112] = "function1";
33
+ KeyCodes[KeyCodes["function10"] = 121] = "function10";
34
+ KeyCodes[KeyCodes["function11"] = 122] = "function11";
35
+ KeyCodes[KeyCodes["function12"] = 123] = "function12";
36
+ KeyCodes[KeyCodes["function2"] = 113] = "function2";
37
+ KeyCodes[KeyCodes["function3"] = 114] = "function3";
38
+ KeyCodes[KeyCodes["function4"] = 115] = "function4";
39
+ KeyCodes[KeyCodes["function5"] = 116] = "function5";
40
+ KeyCodes[KeyCodes["function6"] = 117] = "function6";
41
+ KeyCodes[KeyCodes["function7"] = 118] = "function7";
42
+ KeyCodes[KeyCodes["function8"] = 119] = "function8";
43
+ KeyCodes[KeyCodes["function9"] = 120] = "function9";
44
+ KeyCodes[KeyCodes["home"] = 36] = "home";
45
+ KeyCodes[KeyCodes["insert"] = 45] = "insert";
46
+ KeyCodes[KeyCodes["menu"] = 93] = "menu";
47
+ KeyCodes[KeyCodes["minus"] = 189] = "minus";
48
+ KeyCodes[KeyCodes["minus2"] = 109] = "minus2";
49
+ KeyCodes[KeyCodes["numLock"] = 144] = "numLock";
50
+ KeyCodes[KeyCodes["numPad0"] = 96] = "numPad0";
51
+ KeyCodes[KeyCodes["numPad1"] = 97] = "numPad1";
52
+ KeyCodes[KeyCodes["numPad2"] = 98] = "numPad2";
53
+ KeyCodes[KeyCodes["numPad3"] = 99] = "numPad3";
54
+ KeyCodes[KeyCodes["numPad4"] = 100] = "numPad4";
55
+ KeyCodes[KeyCodes["numPad5"] = 101] = "numPad5";
56
+ KeyCodes[KeyCodes["numPad6"] = 102] = "numPad6";
57
+ KeyCodes[KeyCodes["numPad7"] = 103] = "numPad7";
58
+ KeyCodes[KeyCodes["numPad8"] = 104] = "numPad8";
59
+ KeyCodes[KeyCodes["numPad9"] = 105] = "numPad9";
60
+ KeyCodes[KeyCodes["numPadDivide"] = 111] = "numPadDivide";
61
+ KeyCodes[KeyCodes["numPadDot"] = 110] = "numPadDot";
62
+ KeyCodes[KeyCodes["numPadMinus"] = 109] = "numPadMinus";
63
+ KeyCodes[KeyCodes["numPadMultiply"] = 106] = "numPadMultiply";
64
+ KeyCodes[KeyCodes["numPadPlus"] = 107] = "numPadPlus";
65
+ KeyCodes[KeyCodes["openBracket"] = 219] = "openBracket";
66
+ KeyCodes[KeyCodes["pageDown"] = 34] = "pageDown";
67
+ KeyCodes[KeyCodes["pageUp"] = 33] = "pageUp";
68
+ KeyCodes[KeyCodes["period"] = 190] = "period";
69
+ KeyCodes[KeyCodes["print"] = 44] = "print";
70
+ KeyCodes[KeyCodes["quote"] = 222] = "quote";
71
+ KeyCodes[KeyCodes["scrollLock"] = 145] = "scrollLock";
72
+ KeyCodes[KeyCodes["shift"] = 16] = "shift";
73
+ KeyCodes[KeyCodes["space"] = 32] = "space";
74
+ KeyCodes[KeyCodes["tab"] = 9] = "tab";
75
+ KeyCodes[KeyCodes["tilde"] = 192] = "tilde";
76
+ KeyCodes[KeyCodes["windowsLeft"] = 91] = "windowsLeft";
77
+ KeyCodes[KeyCodes["windowsOpera"] = 219] = "windowsOpera";
78
+ KeyCodes[KeyCodes["windowsRight"] = 92] = "windowsRight";
79
+ })(KeyCodes || (KeyCodes = {}));
80
+ const keyEnter = "Enter";
4
81
 
5
- export { Focus as F };
82
+ const proxySlotName = "form-associated-proxy";
83
+ const ElementInternalsKey = "ElementInternals";
84
+ /**
85
+ * @alpha
86
+ */
87
+ const supportsElementInternals = ElementInternalsKey in window &&
88
+ "setFormValue" in window[ElementInternalsKey].prototype;
89
+ const InternalsMap = new WeakMap();
90
+ /**
91
+ * Base function for providing Custom Element Form Association.
92
+ *
93
+ * @alpha
94
+ */
95
+ function FormAssociated(BaseCtor) {
96
+ const C = class extends BaseCtor {
97
+ constructor(...args) {
98
+ super(...args);
99
+ /**
100
+ * Track whether the value has been changed from the initial value
101
+ */
102
+ this.dirtyValue = false;
103
+ /**
104
+ * Sets the element's disabled state. A disabled element will not be included during form submission.
105
+ *
106
+ * @remarks
107
+ * HTML Attribute: disabled
108
+ */
109
+ this.disabled = false;
110
+ /**
111
+ * These are events that are still fired by the proxy
112
+ * element based on user / programmatic interaction.
113
+ *
114
+ * The proxy implementation should be transparent to
115
+ * the app author, so block these events from emitting.
116
+ */
117
+ this.proxyEventsToBlock = ["change", "click"];
118
+ this.proxyInitialized = false;
119
+ this.required = false;
120
+ this.initialValue = this.initialValue || "";
121
+ if (!this.elementInternals) {
122
+ // When elementInternals is not supported, formResetCallback is
123
+ // bound to an event listener, so ensure the handler's `this`
124
+ // context is correct.
125
+ this.formResetCallback = this.formResetCallback.bind(this);
126
+ }
127
+ }
128
+ /**
129
+ * Must evaluate to true to enable elementInternals.
130
+ * Feature detects API support and resolve respectively
131
+ *
132
+ * @internal
133
+ */
134
+ static get formAssociated() {
135
+ return supportsElementInternals;
136
+ }
137
+ /**
138
+ * Returns the validity state of the element
139
+ *
140
+ * @alpha
141
+ */
142
+ get validity() {
143
+ return this.elementInternals
144
+ ? this.elementInternals.validity
145
+ : this.proxy.validity;
146
+ }
147
+ /**
148
+ * Retrieve a reference to the associated form.
149
+ * Returns null if not associated to any form.
150
+ *
151
+ * @alpha
152
+ */
153
+ get form() {
154
+ return this.elementInternals ? this.elementInternals.form : this.proxy.form;
155
+ }
156
+ /**
157
+ * Retrieve the localized validation message,
158
+ * or custom validation message if set.
159
+ *
160
+ * @alpha
161
+ */
162
+ get validationMessage() {
163
+ return this.elementInternals
164
+ ? this.elementInternals.validationMessage
165
+ : this.proxy.validationMessage;
166
+ }
167
+ /**
168
+ * Whether the element will be validated when the
169
+ * form is submitted
170
+ */
171
+ get willValidate() {
172
+ return this.elementInternals
173
+ ? this.elementInternals.willValidate
174
+ : this.proxy.willValidate;
175
+ }
176
+ /**
177
+ * A reference to all associated label elements
178
+ */
179
+ get labels() {
180
+ if (this.elementInternals) {
181
+ return Object.freeze(Array.from(this.elementInternals.labels));
182
+ }
183
+ else if (this.proxy instanceof HTMLElement &&
184
+ this.proxy.ownerDocument &&
185
+ this.id) {
186
+ // Labels associated by wrapping the element: <label><custom-element></custom-element></label>
187
+ const parentLabels = this.proxy.labels;
188
+ // Labels associated using the `for` attribute
189
+ const forLabels = Array.from(this.proxy.getRootNode().querySelectorAll(`[for='${this.id}']`));
190
+ const labels = parentLabels
191
+ ? forLabels.concat(Array.from(parentLabels))
192
+ : forLabels;
193
+ return Object.freeze(labels);
194
+ }
195
+ else {
196
+ return emptyArray;
197
+ }
198
+ }
199
+ /**
200
+ * Invoked when the `value` property changes
201
+ * @param previous - the previous value
202
+ * @param next - the new value
203
+ *
204
+ * @remarks
205
+ * If elements extending `FormAssociated` implement a `valueChanged` method
206
+ * They must be sure to invoke `super.valueChanged(previous, next)` to ensure
207
+ * proper functioning of `FormAssociated`
208
+ */
209
+ valueChanged(previous, next) {
210
+ this.dirtyValue = true;
211
+ if (this.proxy instanceof HTMLElement) {
212
+ this.proxy.value = this.value;
213
+ }
214
+ this.currentValue = this.value;
215
+ this.setFormValue(this.value);
216
+ this.validate();
217
+ }
218
+ currentValueChanged() {
219
+ this.value = this.currentValue;
220
+ }
221
+ /**
222
+ * Invoked when the `initialValue` property changes
223
+ *
224
+ * @param previous - the previous value
225
+ * @param next - the new value
226
+ *
227
+ * @remarks
228
+ * If elements extending `FormAssociated` implement a `initialValueChanged` method
229
+ * They must be sure to invoke `super.initialValueChanged(previous, next)` to ensure
230
+ * proper functioning of `FormAssociated`
231
+ */
232
+ initialValueChanged(previous, next) {
233
+ // If the value is clean and the component is connected to the DOM
234
+ // then set value equal to the attribute value.
235
+ if (!this.dirtyValue) {
236
+ this.value = this.initialValue;
237
+ this.dirtyValue = false;
238
+ }
239
+ }
240
+ /**
241
+ * Invoked when the `disabled` property changes
242
+ *
243
+ * @param previous - the previous value
244
+ * @param next - the new value
245
+ *
246
+ * @remarks
247
+ * If elements extending `FormAssociated` implement a `disabledChanged` method
248
+ * They must be sure to invoke `super.disabledChanged(previous, next)` to ensure
249
+ * proper functioning of `FormAssociated`
250
+ */
251
+ disabledChanged(previous, next) {
252
+ if (this.proxy instanceof HTMLElement) {
253
+ this.proxy.disabled = this.disabled;
254
+ }
255
+ DOM.queueUpdate(() => this.classList.toggle("disabled", this.disabled));
256
+ }
257
+ /**
258
+ * Invoked when the `name` property changes
259
+ *
260
+ * @param previous - the previous value
261
+ * @param next - the new value
262
+ *
263
+ * @remarks
264
+ * If elements extending `FormAssociated` implement a `nameChanged` method
265
+ * They must be sure to invoke `super.nameChanged(previous, next)` to ensure
266
+ * proper functioning of `FormAssociated`
267
+ */
268
+ nameChanged(previous, next) {
269
+ if (this.proxy instanceof HTMLElement) {
270
+ this.proxy.name = this.name;
271
+ }
272
+ }
273
+ /**
274
+ * Invoked when the `required` property changes
275
+ *
276
+ * @param previous - the previous value
277
+ * @param next - the new value
278
+ *
279
+ * @remarks
280
+ * If elements extending `FormAssociated` implement a `requiredChanged` method
281
+ * They must be sure to invoke `super.requiredChanged(previous, next)` to ensure
282
+ * proper functioning of `FormAssociated`
283
+ */
284
+ requiredChanged(prev, next) {
285
+ if (this.proxy instanceof HTMLElement) {
286
+ this.proxy.required = this.required;
287
+ }
288
+ DOM.queueUpdate(() => this.classList.toggle("required", this.required));
289
+ this.validate();
290
+ }
291
+ /**
292
+ * The element internals object. Will only exist
293
+ * in browsers supporting the attachInternals API
294
+ */
295
+ get elementInternals() {
296
+ if (!supportsElementInternals) {
297
+ return null;
298
+ }
299
+ let internals = InternalsMap.get(this);
300
+ if (!internals) {
301
+ internals = this.attachInternals();
302
+ InternalsMap.set(this, internals);
303
+ }
304
+ return internals;
305
+ }
306
+ /**
307
+ * @internal
308
+ */
309
+ connectedCallback() {
310
+ super.connectedCallback();
311
+ this.addEventListener("keypress", this._keypressHandler);
312
+ if (!this.value) {
313
+ this.value = this.initialValue;
314
+ this.dirtyValue = false;
315
+ }
316
+ if (!this.elementInternals) {
317
+ this.attachProxy();
318
+ if (this.form) {
319
+ this.form.addEventListener("reset", this.formResetCallback);
320
+ }
321
+ }
322
+ }
323
+ /**
324
+ * @internal
325
+ */
326
+ disconnectedCallback() {
327
+ this.proxyEventsToBlock.forEach(name => this.proxy.removeEventListener(name, this.stopPropagation));
328
+ if (!this.elementInternals && this.form) {
329
+ this.form.removeEventListener("reset", this.formResetCallback);
330
+ }
331
+ }
332
+ /**
333
+ * Return the current validity of the element.
334
+ */
335
+ checkValidity() {
336
+ return this.elementInternals
337
+ ? this.elementInternals.checkValidity()
338
+ : this.proxy.checkValidity();
339
+ }
340
+ /**
341
+ * Return the current validity of the element.
342
+ * If false, fires an invalid event at the element.
343
+ */
344
+ reportValidity() {
345
+ return this.elementInternals
346
+ ? this.elementInternals.reportValidity()
347
+ : this.proxy.reportValidity();
348
+ }
349
+ /**
350
+ * Set the validity of the control. In cases when the elementInternals object is not
351
+ * available (and the proxy element is used to report validity), this function will
352
+ * do nothing unless a message is provided, at which point the setCustomValidity method
353
+ * of the proxy element will be invoked with the provided message.
354
+ * @param flags - Validity flags
355
+ * @param message - Optional message to supply
356
+ * @param anchor - Optional element used by UA to display an interactive validation UI
357
+ */
358
+ setValidity(flags, message, anchor) {
359
+ if (this.elementInternals) {
360
+ this.elementInternals.setValidity(flags, message, anchor);
361
+ }
362
+ else if (typeof message === "string") {
363
+ this.proxy.setCustomValidity(message);
364
+ }
365
+ }
366
+ /**
367
+ * Invoked when a connected component's form or fieldset has its disabled
368
+ * state changed.
369
+ * @param disabled - the disabled value of the form / fieldset
370
+ */
371
+ formDisabledCallback(disabled) {
372
+ this.disabled = disabled;
373
+ }
374
+ formResetCallback() {
375
+ this.value = this.initialValue;
376
+ this.dirtyValue = false;
377
+ }
378
+ /**
379
+ * Attach the proxy element to the DOM
380
+ */
381
+ attachProxy() {
382
+ var _a;
383
+ if (!this.proxyInitialized) {
384
+ this.proxyInitialized = true;
385
+ this.proxy.style.display = "none";
386
+ this.proxyEventsToBlock.forEach(name => this.proxy.addEventListener(name, this.stopPropagation));
387
+ // These are typically mapped to the proxy during
388
+ // property change callbacks, but during initialization
389
+ // on the initial call of the callback, the proxy is
390
+ // still undefined. We should find a better way to address this.
391
+ this.proxy.disabled = this.disabled;
392
+ this.proxy.required = this.required;
393
+ if (typeof this.name === "string") {
394
+ this.proxy.name = this.name;
395
+ }
396
+ if (typeof this.value === "string") {
397
+ this.proxy.value = this.value;
398
+ }
399
+ this.proxy.setAttribute("slot", proxySlotName);
400
+ this.proxySlot = document.createElement("slot");
401
+ this.proxySlot.setAttribute("name", proxySlotName);
402
+ }
403
+ (_a = this.shadowRoot) === null || _a === void 0 ? void 0 : _a.appendChild(this.proxySlot);
404
+ this.appendChild(this.proxy);
405
+ }
406
+ /**
407
+ * Detach the proxy element from the DOM
408
+ */
409
+ detachProxy() {
410
+ var _a;
411
+ this.removeChild(this.proxy);
412
+ (_a = this.shadowRoot) === null || _a === void 0 ? void 0 : _a.removeChild(this.proxySlot);
413
+ }
414
+ /**
415
+ * Sets the validity of the custom element. By default this uses the proxy element to determine
416
+ * validity, but this can be extended or replaced in implementation.
417
+ */
418
+ validate() {
419
+ if (this.proxy instanceof HTMLElement) {
420
+ this.setValidity(this.proxy.validity, this.proxy.validationMessage);
421
+ }
422
+ }
423
+ /**
424
+ * Associates the provided value (and optional state) with the parent form.
425
+ * @param value - The value to set
426
+ * @param state - The state object provided to during session restores and when autofilling.
427
+ */
428
+ setFormValue(value, state) {
429
+ if (this.elementInternals) {
430
+ this.elementInternals.setFormValue(value, state || value);
431
+ }
432
+ }
433
+ _keypressHandler(e) {
434
+ switch (e.key) {
435
+ case keyEnter:
436
+ if (this.form instanceof HTMLFormElement) {
437
+ // Implicit submission
438
+ const defaultButton = this.form.querySelector("[type=submit]");
439
+ defaultButton === null || defaultButton === void 0 ? void 0 : defaultButton.click();
440
+ }
441
+ break;
442
+ }
443
+ }
444
+ /**
445
+ * Used to stop propagation of proxy element events
446
+ * @param e - Event object
447
+ */
448
+ stopPropagation(e) {
449
+ e.stopPropagation();
450
+ }
451
+ };
452
+ attr({ mode: "boolean" })(C.prototype, "disabled");
453
+ attr({ mode: "fromView", attribute: "value" })(C.prototype, "initialValue");
454
+ attr({ attribute: "current-value" })(C.prototype, "currentValue");
455
+ attr(C.prototype, "name");
456
+ attr({ mode: "boolean" })(C.prototype, "required");
457
+ observable(C.prototype, "value");
458
+ return C;
459
+ }
460
+
461
+ let _ = t => t,
462
+ _t;
463
+ const focusTemplateFactory = context => {
464
+ const focusTag = context.tagFor(Focus);
465
+ return html(_t || (_t = _`<${0} class="focus-indicator"></${0}>`), focusTag, focusTag);
466
+ };
467
+
468
+ export { FormAssociated as F, focusTemplateFactory as f };
package/shared/index.js CHANGED
@@ -707,6 +707,21 @@ const Observable = FAST.getById(2 /* observable */, () => {
707
707
  function observable(target, nameOrAccessor) {
708
708
  Observable.defineProperty(target, nameOrAccessor);
709
709
  }
710
+ /**
711
+ * Decorator: Marks a property getter as having volatile observable dependencies.
712
+ * @param target - The target that the property is defined on.
713
+ * @param name - The property name.
714
+ * @param name - The existing descriptor.
715
+ * @public
716
+ */
717
+ function volatile(target, name, descriptor) {
718
+ return Object.assign({}, descriptor, {
719
+ get: function () {
720
+ Observable.trackVolatile();
721
+ return descriptor.get.apply(this);
722
+ },
723
+ });
724
+ }
710
725
  const contextEvent = FAST.getById(3 /* contextEvent */, () => {
711
726
  let current = null;
712
727
  return {
@@ -4995,4 +5010,4 @@ function provideVividDesignSystem(element) {
4995
5010
  }
4996
5011
  const designSystem = provideVividDesignSystem();
4997
5012
 
4998
- export { AttachedBehaviorHTMLDirective as A, DOM as D, FoundationElement as F, HTMLDirective as H, Observable as O, SubscriberSet as S, __decorate as _, attr as a, __metadata as b, __classPrivateFieldGet as c, designSystem as d, emptyArray as e, HTMLView as f, __classPrivateFieldSet as g, html as h, nullableNumberConverter as n, observable as o, provideVividDesignSystem as p };
5013
+ export { AttachedBehaviorHTMLDirective as A, DOM as D, FoundationElement as F, HTMLDirective as H, Observable as O, SubscriberSet as S, __decorate as _, attr as a, __metadata as b, __classPrivateFieldGet as c, designSystem as d, emptyArray as e, HTMLView as f, __classPrivateFieldSet as g, html as h, nullableNumberConverter as n, observable as o, provideVividDesignSystem as p, volatile as v };