@vonage/vivid 3.48.0 → 3.49.0-preview.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/accordion/index.cjs +21 -0
- package/accordion-item/index.cjs +18 -0
- package/action-group/index.cjs +7 -0
- package/alert/index.cjs +30 -0
- package/appearance-ui/index.cjs +96 -0
- package/audio-player/index.cjs +34 -0
- package/avatar/index.cjs +11 -0
- package/badge/index.cjs +14 -0
- package/banner/index.cjs +29 -0
- package/breadcrumb/index.cjs +13 -0
- package/breadcrumb-item/index.cjs +22 -0
- package/button/index.cjs +25 -0
- package/calendar/index.cjs +9 -0
- package/calendar-event/index.cjs +9 -0
- package/card/index.cjs +14 -0
- package/checkbox/index.cjs +21 -0
- package/combobox/index.cjs +39 -0
- package/data-grid/index.cjs +18 -0
- package/date-picker/index.cjs +40 -0
- package/date-range-picker/index.cjs +40 -0
- package/dialog/index.cjs +31 -0
- package/divider/index.cjs +8 -0
- package/elevation/index.cjs +7 -0
- package/empty-state/index.cjs +12 -0
- package/fab/index.cjs +22 -0
- package/file-picker/index.cjs +30 -0
- package/focus/index.cjs +7 -0
- package/header/index.cjs +8 -0
- package/icon/index.cjs +10 -0
- package/index.cjs +296 -0
- package/layout/index.cjs +7 -0
- package/listbox/index.cjs +77 -0
- package/locales/en-GB.cjs +106 -0
- package/locales/en-US.cjs +106 -0
- package/locales/ja-JP.cjs +106 -0
- package/locales/zh-CN.cjs +106 -0
- package/menu/index.cjs +32 -0
- package/menu-item/index.cjs +22 -0
- package/nav/index.cjs +6 -0
- package/nav-disclosure/index.cjs +17 -0
- package/nav-item/index.cjs +22 -0
- package/note/index.cjs +16 -0
- package/number-field/index.cjs +33 -0
- package/option/index.cjs +23 -0
- package/package.json +20 -2
- package/pagination/index.cjs +28 -0
- package/popup/index.cjs +27 -0
- package/progress/index.cjs +9 -0
- package/progress-ring/index.cjs +9 -0
- package/radio/index.cjs +14 -0
- package/radio-group/index.cjs +14 -0
- package/select/index.cjs +38 -0
- package/selectable-box/index.cjs +25 -0
- package/shared/Reflector.cjs +67 -0
- package/shared/_has.cjs +62 -0
- package/shared/affix.cjs +64 -0
- package/shared/affix.js +8 -4
- package/shared/anchor.cjs +90 -0
- package/shared/anchored.cjs +78 -0
- package/shared/apply-mixins.cjs +25 -0
- package/shared/aria-global.cjs +74 -0
- package/shared/aria.cjs +11 -0
- package/shared/aria2.cjs +11 -0
- package/shared/base-progress.cjs +72 -0
- package/shared/breadcrumb-item.cjs +27 -0
- package/shared/button.cjs +202 -0
- package/shared/calendar-event.cjs +41 -0
- package/shared/children.cjs +61 -0
- package/shared/class-names.cjs +17 -0
- package/shared/definition.cjs +165 -0
- package/shared/definition10.cjs +102 -0
- package/shared/definition11.cjs +164 -0
- package/shared/definition11.js +38 -36
- package/shared/definition12.cjs +50 -0
- package/shared/definition13.cjs +779 -0
- package/shared/definition14.cjs +157 -0
- package/shared/definition15.cjs +249 -0
- package/shared/definition16.cjs +746 -0
- package/shared/definition17.cjs +1372 -0
- package/shared/definition18.cjs +175 -0
- package/shared/definition19.cjs +416 -0
- package/shared/definition2.cjs +232 -0
- package/shared/definition20.cjs +278 -0
- package/shared/definition21.cjs +83 -0
- package/shared/definition22.cjs +74 -0
- package/shared/definition23.cjs +106 -0
- package/shared/definition24.cjs +2392 -0
- package/shared/definition25.cjs +75 -0
- package/shared/definition26.cjs +39 -0
- package/shared/definition27.cjs +66 -0
- package/shared/definition28.cjs +849 -0
- package/shared/definition29.cjs +72 -0
- package/shared/definition3.cjs +72 -0
- package/shared/definition30.cjs +98 -0
- package/shared/definition31.cjs +37 -0
- package/shared/definition32.cjs +24 -0
- package/shared/definition33.cjs +64 -0
- package/shared/definition34.cjs +533 -0
- package/shared/definition35.cjs +295 -0
- package/shared/definition36.cjs +219 -0
- package/shared/definition37.cjs +109 -0
- package/shared/definition38.cjs +92 -0
- package/shared/definition39.cjs +448 -0
- package/shared/definition4.cjs +198 -0
- package/shared/definition40.cjs +49 -0
- package/shared/definition41.cjs +694 -0
- package/shared/definition42.cjs +152 -0
- package/shared/definition43.cjs +113 -0
- package/shared/definition44.cjs +607 -0
- package/shared/definition45.cjs +152 -0
- package/shared/definition46.cjs +166 -0
- package/shared/definition47.cjs +35 -0
- package/shared/definition48.cjs +98 -0
- package/shared/definition49.cjs +543 -0
- package/shared/definition5.cjs +199 -0
- package/shared/definition50.cjs +52 -0
- package/shared/definition51.cjs +150 -0
- package/shared/definition52.cjs +304 -0
- package/shared/definition53.cjs +309 -0
- package/shared/definition54.cjs +146 -0
- package/shared/definition55.cjs +128 -0
- package/shared/definition56.cjs +99 -0
- package/shared/definition57.cjs +310 -0
- package/shared/definition58.cjs +20 -0
- package/shared/definition59.cjs +51 -0
- package/shared/definition6.cjs +83 -0
- package/shared/definition60.cjs +1810 -0
- package/shared/definition7.cjs +72 -0
- package/shared/definition8.cjs +152 -0
- package/shared/definition9.cjs +69 -0
- package/shared/dialog-polyfill.esm.cjs +862 -0
- package/shared/direction.cjs +22 -0
- package/shared/dom.cjs +23 -0
- package/shared/enums.cjs +87 -0
- package/shared/focus.cjs +8 -0
- package/shared/focus2.cjs +11 -0
- package/shared/form-associated.cjs +470 -0
- package/shared/icon.cjs +237 -0
- package/shared/index.cjs +5061 -0
- package/shared/index2.cjs +231 -0
- package/shared/key-codes.cjs +115 -0
- package/shared/key-codes2.cjs +14 -0
- package/shared/listbox.cjs +1072 -0
- package/shared/localized.cjs +11 -0
- package/shared/numbers.cjs +38 -0
- package/shared/patterns/affix.d.ts +5 -1
- package/shared/presentationDate.cjs +6192 -0
- package/shared/radio.cjs +153 -0
- package/shared/ref.cjs +43 -0
- package/shared/repeat.cjs +767 -0
- package/shared/select.options.cjs +12 -0
- package/shared/slotted.cjs +123 -0
- package/shared/start-end.cjs +52 -0
- package/shared/strings.cjs +11 -0
- package/shared/text-anchor.cjs +33 -0
- package/shared/text-anchor.template.cjs +48 -0
- package/shared/text-field.cjs +5 -0
- package/shared/text-field2.cjs +228 -0
- package/shared/tree-item.cjs +154 -0
- package/shared/when.cjs +31 -0
- package/side-drawer/index.cjs +8 -0
- package/slider/index.cjs +16 -0
- package/split-button/index.cjs +20 -0
- package/styles/core/all.css +1 -1
- package/styles/core/theme.css +1 -1
- package/styles/core/typography.css +1 -1
- package/styles/tokens/theme-dark.css +4 -4
- package/styles/tokens/theme-light.css +4 -4
- package/styles/tokens/vivid-2-compat.css +1 -1
- package/switch/index.cjs +15 -0
- package/tab/index.cjs +17 -0
- package/tab-panel/index.cjs +6 -0
- package/tabs/index.cjs +24 -0
- package/tag/index.cjs +17 -0
- package/tag-group/index.cjs +7 -0
- package/text-anchor/index.cjs +24 -0
- package/text-area/index.cjs +25 -0
- package/text-field/index.cjs +27 -0
- package/toggletip/index.cjs +29 -0
- package/tooltip/index.cjs +29 -0
- package/tree-item/index.cjs +22 -0
- package/tree-view/index.cjs +14 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Expose ltr and rtl strings
|
|
5
|
+
*/
|
|
6
|
+
exports.Direction = void 0;
|
|
7
|
+
(function (Direction) {
|
|
8
|
+
Direction["ltr"] = "ltr";
|
|
9
|
+
Direction["rtl"] = "rtl";
|
|
10
|
+
})(exports.Direction || (exports.Direction = {}));
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* a method to determine the current localization direction of the view
|
|
14
|
+
* @param rootNode - the HTMLElement to begin the query from, usually "this" when used in a component controller
|
|
15
|
+
* @public
|
|
16
|
+
*/
|
|
17
|
+
const getDirection = (rootNode) => {
|
|
18
|
+
const dirNode = rootNode.closest("[dir]");
|
|
19
|
+
return dirNode !== null && dirNode.dir === "rtl" ? exports.Direction.rtl : exports.Direction.ltr;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
exports.getDirection = getDirection;
|
package/shared/dom.cjs
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A test that ensures that all arguments are HTML Elements
|
|
5
|
+
*/
|
|
6
|
+
function isHTMLElement(...args) {
|
|
7
|
+
return args.every((arg) => arg instanceof HTMLElement);
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Returns all displayed elements inside of a root node that match a provided selector
|
|
11
|
+
*/
|
|
12
|
+
function getDisplayedNodes(rootNode, selector) {
|
|
13
|
+
if (!rootNode || !selector || !isHTMLElement(rootNode)) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
const nodes = Array.from(rootNode.querySelectorAll(selector));
|
|
17
|
+
// offsetParent will be null if the element isn't currently displayed,
|
|
18
|
+
// so this will allow us to operate only on visible nodes
|
|
19
|
+
return nodes.filter((node) => node.offsetParent !== null);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
exports.getDisplayedNodes = getDisplayedNodes;
|
|
23
|
+
exports.isHTMLElement = isHTMLElement;
|
package/shared/enums.cjs
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var Connotation = /* @__PURE__ */ ((Connotation2) => {
|
|
4
|
+
Connotation2["Accent"] = "accent";
|
|
5
|
+
Connotation2["CTA"] = "cta";
|
|
6
|
+
Connotation2["Success"] = "success";
|
|
7
|
+
Connotation2["Alert"] = "alert";
|
|
8
|
+
Connotation2["Warning"] = "warning";
|
|
9
|
+
Connotation2["Information"] = "information";
|
|
10
|
+
Connotation2["Announcement"] = "announcement";
|
|
11
|
+
return Connotation2;
|
|
12
|
+
})(Connotation || {});
|
|
13
|
+
var ConnotationDecorative = /* @__PURE__ */ ((ConnotationDecorative2) => {
|
|
14
|
+
ConnotationDecorative2["Pacific"] = "pacific";
|
|
15
|
+
return ConnotationDecorative2;
|
|
16
|
+
})(ConnotationDecorative || {});
|
|
17
|
+
var Shape = /* @__PURE__ */ ((Shape2) => {
|
|
18
|
+
Shape2["Rounded"] = "rounded";
|
|
19
|
+
Shape2["Pill"] = "pill";
|
|
20
|
+
Shape2["Circled"] = "circled";
|
|
21
|
+
Shape2["Sharp"] = "sharp";
|
|
22
|
+
return Shape2;
|
|
23
|
+
})(Shape || {});
|
|
24
|
+
var Appearance = /* @__PURE__ */ ((Appearance2) => {
|
|
25
|
+
Appearance2["Filled"] = "filled";
|
|
26
|
+
Appearance2["Outlined"] = "outlined";
|
|
27
|
+
Appearance2["Duotone"] = "duotone";
|
|
28
|
+
Appearance2["Fieldset"] = "fieldset";
|
|
29
|
+
Appearance2["Subtle"] = "subtle";
|
|
30
|
+
Appearance2["Ghost"] = "ghost";
|
|
31
|
+
Appearance2["Listitem"] = "listitem";
|
|
32
|
+
Appearance2["Elevated"] = "elevated";
|
|
33
|
+
return Appearance2;
|
|
34
|
+
})(Appearance || {});
|
|
35
|
+
var Size = /* @__PURE__ */ ((Size2) => {
|
|
36
|
+
Size2["UltraCondensed"] = "ultra-condensed";
|
|
37
|
+
Size2["SuperCondensed"] = "super-condensed";
|
|
38
|
+
Size2["ExtraCondensed"] = "extra-condensed";
|
|
39
|
+
Size2["SemiCondensed"] = "semi-condensed";
|
|
40
|
+
Size2["Condensed"] = "condensed";
|
|
41
|
+
Size2["Normal"] = "normal";
|
|
42
|
+
Size2["SemiExpanded"] = "semi-expanded";
|
|
43
|
+
Size2["Expanded"] = "expanded";
|
|
44
|
+
Size2["ExtraExpanded"] = "extra-expanded";
|
|
45
|
+
Size2["SuperExpanded"] = "super-expanded";
|
|
46
|
+
Size2["UltraExpanded"] = "ultra-expanded";
|
|
47
|
+
return Size2;
|
|
48
|
+
})(Size || {});
|
|
49
|
+
var LayoutSize = /* @__PURE__ */ ((LayoutSize2) => {
|
|
50
|
+
LayoutSize2["Small"] = "small";
|
|
51
|
+
LayoutSize2["Medium"] = "medium";
|
|
52
|
+
LayoutSize2["Large"] = "large";
|
|
53
|
+
return LayoutSize2;
|
|
54
|
+
})(LayoutSize || {});
|
|
55
|
+
var TabsSize = /* @__PURE__ */ ((TabsSize2) => {
|
|
56
|
+
TabsSize2["Small"] = "small";
|
|
57
|
+
return TabsSize2;
|
|
58
|
+
})(TabsSize || {});
|
|
59
|
+
var Position = /* @__PURE__ */ ((Position2) => {
|
|
60
|
+
Position2["Top"] = "TOP";
|
|
61
|
+
Position2["Bottom"] = "BOTTOM";
|
|
62
|
+
Position2["Start"] = "START";
|
|
63
|
+
Position2["Center"] = "CENTER";
|
|
64
|
+
Position2["End"] = "END";
|
|
65
|
+
return Position2;
|
|
66
|
+
})(Position || {});
|
|
67
|
+
var Role = /* @__PURE__ */ ((Role2) => {
|
|
68
|
+
Role2["Status"] = "status";
|
|
69
|
+
Role2["Alert"] = "alert";
|
|
70
|
+
return Role2;
|
|
71
|
+
})(Role || {});
|
|
72
|
+
var AriaLive = /* @__PURE__ */ ((AriaLive2) => {
|
|
73
|
+
AriaLive2["Polite"] = "polite";
|
|
74
|
+
AriaLive2["Assertive"] = "assertive";
|
|
75
|
+
return AriaLive2;
|
|
76
|
+
})(AriaLive || {});
|
|
77
|
+
|
|
78
|
+
exports.Appearance = Appearance;
|
|
79
|
+
exports.AriaLive = AriaLive;
|
|
80
|
+
exports.Connotation = Connotation;
|
|
81
|
+
exports.ConnotationDecorative = ConnotationDecorative;
|
|
82
|
+
exports.LayoutSize = LayoutSize;
|
|
83
|
+
exports.Position = Position;
|
|
84
|
+
exports.Role = Role;
|
|
85
|
+
exports.Shape = Shape;
|
|
86
|
+
exports.Size = Size;
|
|
87
|
+
exports.TabsSize = TabsSize;
|
package/shared/focus.cjs
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const focus = require('./focus.cjs');
|
|
4
|
+
const index = require('./index.cjs');
|
|
5
|
+
|
|
6
|
+
const focusTemplateFactory = (context) => {
|
|
7
|
+
const focusTag = context.tagFor(focus.Focus);
|
|
8
|
+
return index.html`<${focusTag} class="focus-indicator"></${focusTag}>`;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
exports.focusTemplateFactory = focusTemplateFactory;
|
|
@@ -0,0 +1,470 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const index = require('./index.cjs');
|
|
4
|
+
const keyCodes = require('./key-codes.cjs');
|
|
5
|
+
|
|
6
|
+
const proxySlotName = "form-associated-proxy";
|
|
7
|
+
const ElementInternalsKey = "ElementInternals";
|
|
8
|
+
/**
|
|
9
|
+
* @alpha
|
|
10
|
+
*/
|
|
11
|
+
const supportsElementInternals = ElementInternalsKey in window &&
|
|
12
|
+
"setFormValue" in window[ElementInternalsKey].prototype;
|
|
13
|
+
const InternalsMap = new WeakMap();
|
|
14
|
+
/**
|
|
15
|
+
* Base function for providing Custom Element Form Association.
|
|
16
|
+
*
|
|
17
|
+
* @alpha
|
|
18
|
+
*/
|
|
19
|
+
function FormAssociated(BaseCtor) {
|
|
20
|
+
const C = class extends BaseCtor {
|
|
21
|
+
constructor(...args) {
|
|
22
|
+
super(...args);
|
|
23
|
+
/**
|
|
24
|
+
* Track whether the value has been changed from the initial value
|
|
25
|
+
*/
|
|
26
|
+
this.dirtyValue = false;
|
|
27
|
+
/**
|
|
28
|
+
* Sets the element's disabled state. A disabled element will not be included during form submission.
|
|
29
|
+
*
|
|
30
|
+
* @remarks
|
|
31
|
+
* HTML Attribute: disabled
|
|
32
|
+
*/
|
|
33
|
+
this.disabled = false;
|
|
34
|
+
/**
|
|
35
|
+
* These are events that are still fired by the proxy
|
|
36
|
+
* element based on user / programmatic interaction.
|
|
37
|
+
*
|
|
38
|
+
* The proxy implementation should be transparent to
|
|
39
|
+
* the app author, so block these events from emitting.
|
|
40
|
+
*/
|
|
41
|
+
this.proxyEventsToBlock = ["change", "click"];
|
|
42
|
+
this.proxyInitialized = false;
|
|
43
|
+
this.required = false;
|
|
44
|
+
this.initialValue = this.initialValue || "";
|
|
45
|
+
if (!this.elementInternals) {
|
|
46
|
+
// When elementInternals is not supported, formResetCallback is
|
|
47
|
+
// bound to an event listener, so ensure the handler's `this`
|
|
48
|
+
// context is correct.
|
|
49
|
+
this.formResetCallback = this.formResetCallback.bind(this);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Must evaluate to true to enable elementInternals.
|
|
54
|
+
* Feature detects API support and resolve respectively
|
|
55
|
+
*
|
|
56
|
+
* @internal
|
|
57
|
+
*/
|
|
58
|
+
static get formAssociated() {
|
|
59
|
+
return supportsElementInternals;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Returns the validity state of the element
|
|
63
|
+
*
|
|
64
|
+
* @alpha
|
|
65
|
+
*/
|
|
66
|
+
get validity() {
|
|
67
|
+
return this.elementInternals
|
|
68
|
+
? this.elementInternals.validity
|
|
69
|
+
: this.proxy.validity;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Retrieve a reference to the associated form.
|
|
73
|
+
* Returns null if not associated to any form.
|
|
74
|
+
*
|
|
75
|
+
* @alpha
|
|
76
|
+
*/
|
|
77
|
+
get form() {
|
|
78
|
+
return this.elementInternals ? this.elementInternals.form : this.proxy.form;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Retrieve the localized validation message,
|
|
82
|
+
* or custom validation message if set.
|
|
83
|
+
*
|
|
84
|
+
* @alpha
|
|
85
|
+
*/
|
|
86
|
+
get validationMessage() {
|
|
87
|
+
return this.elementInternals
|
|
88
|
+
? this.elementInternals.validationMessage
|
|
89
|
+
: this.proxy.validationMessage;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Whether the element will be validated when the
|
|
93
|
+
* form is submitted
|
|
94
|
+
*/
|
|
95
|
+
get willValidate() {
|
|
96
|
+
return this.elementInternals
|
|
97
|
+
? this.elementInternals.willValidate
|
|
98
|
+
: this.proxy.willValidate;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* A reference to all associated label elements
|
|
102
|
+
*/
|
|
103
|
+
get labels() {
|
|
104
|
+
if (this.elementInternals) {
|
|
105
|
+
return Object.freeze(Array.from(this.elementInternals.labels));
|
|
106
|
+
}
|
|
107
|
+
else if (this.proxy instanceof HTMLElement &&
|
|
108
|
+
this.proxy.ownerDocument &&
|
|
109
|
+
this.id) {
|
|
110
|
+
// Labels associated by wrapping the element: <label><custom-element></custom-element></label>
|
|
111
|
+
const parentLabels = this.proxy.labels;
|
|
112
|
+
// Labels associated using the `for` attribute
|
|
113
|
+
const forLabels = Array.from(this.proxy.getRootNode().querySelectorAll(`[for='${this.id}']`));
|
|
114
|
+
const labels = parentLabels
|
|
115
|
+
? forLabels.concat(Array.from(parentLabels))
|
|
116
|
+
: forLabels;
|
|
117
|
+
return Object.freeze(labels);
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
return index.emptyArray;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Invoked when the `value` property changes
|
|
125
|
+
* @param previous - the previous value
|
|
126
|
+
* @param next - the new value
|
|
127
|
+
*
|
|
128
|
+
* @remarks
|
|
129
|
+
* If elements extending `FormAssociated` implement a `valueChanged` method
|
|
130
|
+
* They must be sure to invoke `super.valueChanged(previous, next)` to ensure
|
|
131
|
+
* proper functioning of `FormAssociated`
|
|
132
|
+
*/
|
|
133
|
+
valueChanged(previous, next) {
|
|
134
|
+
this.dirtyValue = true;
|
|
135
|
+
if (this.proxy instanceof HTMLElement) {
|
|
136
|
+
this.proxy.value = this.value;
|
|
137
|
+
}
|
|
138
|
+
this.currentValue = this.value;
|
|
139
|
+
this.setFormValue(this.value);
|
|
140
|
+
this.validate();
|
|
141
|
+
}
|
|
142
|
+
currentValueChanged() {
|
|
143
|
+
this.value = this.currentValue;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Invoked when the `initialValue` property changes
|
|
147
|
+
*
|
|
148
|
+
* @param previous - the previous value
|
|
149
|
+
* @param next - the new value
|
|
150
|
+
*
|
|
151
|
+
* @remarks
|
|
152
|
+
* If elements extending `FormAssociated` implement a `initialValueChanged` method
|
|
153
|
+
* They must be sure to invoke `super.initialValueChanged(previous, next)` to ensure
|
|
154
|
+
* proper functioning of `FormAssociated`
|
|
155
|
+
*/
|
|
156
|
+
initialValueChanged(previous, next) {
|
|
157
|
+
// If the value is clean and the component is connected to the DOM
|
|
158
|
+
// then set value equal to the attribute value.
|
|
159
|
+
if (!this.dirtyValue) {
|
|
160
|
+
this.value = this.initialValue;
|
|
161
|
+
this.dirtyValue = false;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Invoked when the `disabled` property changes
|
|
166
|
+
*
|
|
167
|
+
* @param previous - the previous value
|
|
168
|
+
* @param next - the new value
|
|
169
|
+
*
|
|
170
|
+
* @remarks
|
|
171
|
+
* If elements extending `FormAssociated` implement a `disabledChanged` method
|
|
172
|
+
* They must be sure to invoke `super.disabledChanged(previous, next)` to ensure
|
|
173
|
+
* proper functioning of `FormAssociated`
|
|
174
|
+
*/
|
|
175
|
+
disabledChanged(previous, next) {
|
|
176
|
+
if (this.proxy instanceof HTMLElement) {
|
|
177
|
+
this.proxy.disabled = this.disabled;
|
|
178
|
+
}
|
|
179
|
+
index.DOM.queueUpdate(() => this.classList.toggle("disabled", this.disabled));
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Invoked when the `name` property changes
|
|
183
|
+
*
|
|
184
|
+
* @param previous - the previous value
|
|
185
|
+
* @param next - the new value
|
|
186
|
+
*
|
|
187
|
+
* @remarks
|
|
188
|
+
* If elements extending `FormAssociated` implement a `nameChanged` method
|
|
189
|
+
* They must be sure to invoke `super.nameChanged(previous, next)` to ensure
|
|
190
|
+
* proper functioning of `FormAssociated`
|
|
191
|
+
*/
|
|
192
|
+
nameChanged(previous, next) {
|
|
193
|
+
if (this.proxy instanceof HTMLElement) {
|
|
194
|
+
this.proxy.name = this.name;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Invoked when the `required` property changes
|
|
199
|
+
*
|
|
200
|
+
* @param previous - the previous value
|
|
201
|
+
* @param next - the new value
|
|
202
|
+
*
|
|
203
|
+
* @remarks
|
|
204
|
+
* If elements extending `FormAssociated` implement a `requiredChanged` method
|
|
205
|
+
* They must be sure to invoke `super.requiredChanged(previous, next)` to ensure
|
|
206
|
+
* proper functioning of `FormAssociated`
|
|
207
|
+
*/
|
|
208
|
+
requiredChanged(prev, next) {
|
|
209
|
+
if (this.proxy instanceof HTMLElement) {
|
|
210
|
+
this.proxy.required = this.required;
|
|
211
|
+
}
|
|
212
|
+
index.DOM.queueUpdate(() => this.classList.toggle("required", this.required));
|
|
213
|
+
this.validate();
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* The element internals object. Will only exist
|
|
217
|
+
* in browsers supporting the attachInternals API
|
|
218
|
+
*/
|
|
219
|
+
get elementInternals() {
|
|
220
|
+
if (!supportsElementInternals) {
|
|
221
|
+
return null;
|
|
222
|
+
}
|
|
223
|
+
let internals = InternalsMap.get(this);
|
|
224
|
+
if (!internals) {
|
|
225
|
+
internals = this.attachInternals();
|
|
226
|
+
InternalsMap.set(this, internals);
|
|
227
|
+
}
|
|
228
|
+
return internals;
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* @internal
|
|
232
|
+
*/
|
|
233
|
+
connectedCallback() {
|
|
234
|
+
super.connectedCallback();
|
|
235
|
+
this.addEventListener("keypress", this._keypressHandler);
|
|
236
|
+
if (!this.value) {
|
|
237
|
+
this.value = this.initialValue;
|
|
238
|
+
this.dirtyValue = false;
|
|
239
|
+
}
|
|
240
|
+
if (!this.elementInternals) {
|
|
241
|
+
this.attachProxy();
|
|
242
|
+
if (this.form) {
|
|
243
|
+
this.form.addEventListener("reset", this.formResetCallback);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* @internal
|
|
249
|
+
*/
|
|
250
|
+
disconnectedCallback() {
|
|
251
|
+
super.disconnectedCallback();
|
|
252
|
+
this.proxyEventsToBlock.forEach(name => this.proxy.removeEventListener(name, this.stopPropagation));
|
|
253
|
+
if (!this.elementInternals && this.form) {
|
|
254
|
+
this.form.removeEventListener("reset", this.formResetCallback);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Return the current validity of the element.
|
|
259
|
+
*/
|
|
260
|
+
checkValidity() {
|
|
261
|
+
return this.elementInternals
|
|
262
|
+
? this.elementInternals.checkValidity()
|
|
263
|
+
: this.proxy.checkValidity();
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Return the current validity of the element.
|
|
267
|
+
* If false, fires an invalid event at the element.
|
|
268
|
+
*/
|
|
269
|
+
reportValidity() {
|
|
270
|
+
return this.elementInternals
|
|
271
|
+
? this.elementInternals.reportValidity()
|
|
272
|
+
: this.proxy.reportValidity();
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Set the validity of the control. In cases when the elementInternals object is not
|
|
276
|
+
* available (and the proxy element is used to report validity), this function will
|
|
277
|
+
* do nothing unless a message is provided, at which point the setCustomValidity method
|
|
278
|
+
* of the proxy element will be invoked with the provided message.
|
|
279
|
+
* @param flags - Validity flags
|
|
280
|
+
* @param message - Optional message to supply
|
|
281
|
+
* @param anchor - Optional element used by UA to display an interactive validation UI
|
|
282
|
+
*/
|
|
283
|
+
setValidity(flags, message, anchor) {
|
|
284
|
+
if (this.elementInternals) {
|
|
285
|
+
this.elementInternals.setValidity(flags, message, anchor);
|
|
286
|
+
}
|
|
287
|
+
else if (typeof message === "string") {
|
|
288
|
+
this.proxy.setCustomValidity(message);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Invoked when a connected component's form or fieldset has its disabled
|
|
293
|
+
* state changed.
|
|
294
|
+
* @param disabled - the disabled value of the form / fieldset
|
|
295
|
+
*/
|
|
296
|
+
formDisabledCallback(disabled) {
|
|
297
|
+
this.disabled = disabled;
|
|
298
|
+
}
|
|
299
|
+
formResetCallback() {
|
|
300
|
+
this.value = this.initialValue;
|
|
301
|
+
this.dirtyValue = false;
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Attach the proxy element to the DOM
|
|
305
|
+
*/
|
|
306
|
+
attachProxy() {
|
|
307
|
+
var _a;
|
|
308
|
+
if (!this.proxyInitialized) {
|
|
309
|
+
this.proxyInitialized = true;
|
|
310
|
+
this.proxy.style.display = "none";
|
|
311
|
+
this.proxyEventsToBlock.forEach(name => this.proxy.addEventListener(name, this.stopPropagation));
|
|
312
|
+
// These are typically mapped to the proxy during
|
|
313
|
+
// property change callbacks, but during initialization
|
|
314
|
+
// on the initial call of the callback, the proxy is
|
|
315
|
+
// still undefined. We should find a better way to address this.
|
|
316
|
+
this.proxy.disabled = this.disabled;
|
|
317
|
+
this.proxy.required = this.required;
|
|
318
|
+
if (typeof this.name === "string") {
|
|
319
|
+
this.proxy.name = this.name;
|
|
320
|
+
}
|
|
321
|
+
if (typeof this.value === "string") {
|
|
322
|
+
this.proxy.value = this.value;
|
|
323
|
+
}
|
|
324
|
+
this.proxy.setAttribute("slot", proxySlotName);
|
|
325
|
+
this.proxySlot = document.createElement("slot");
|
|
326
|
+
this.proxySlot.setAttribute("name", proxySlotName);
|
|
327
|
+
}
|
|
328
|
+
(_a = this.shadowRoot) === null || _a === void 0 ? void 0 : _a.appendChild(this.proxySlot);
|
|
329
|
+
this.appendChild(this.proxy);
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* Detach the proxy element from the DOM
|
|
333
|
+
*/
|
|
334
|
+
detachProxy() {
|
|
335
|
+
var _a;
|
|
336
|
+
this.removeChild(this.proxy);
|
|
337
|
+
(_a = this.shadowRoot) === null || _a === void 0 ? void 0 : _a.removeChild(this.proxySlot);
|
|
338
|
+
}
|
|
339
|
+
/** {@inheritDoc (FormAssociated:interface).validate} */
|
|
340
|
+
validate(anchor) {
|
|
341
|
+
if (this.proxy instanceof HTMLElement) {
|
|
342
|
+
this.setValidity(this.proxy.validity, this.proxy.validationMessage, anchor);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* Associates the provided value (and optional state) with the parent form.
|
|
347
|
+
* @param value - The value to set
|
|
348
|
+
* @param state - The state object provided to during session restores and when autofilling.
|
|
349
|
+
*/
|
|
350
|
+
setFormValue(value, state) {
|
|
351
|
+
if (this.elementInternals) {
|
|
352
|
+
this.elementInternals.setFormValue(value, state || value);
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
_keypressHandler(e) {
|
|
356
|
+
switch (e.key) {
|
|
357
|
+
case keyCodes.keyEnter:
|
|
358
|
+
if (this.form instanceof HTMLFormElement) {
|
|
359
|
+
// Implicit submission
|
|
360
|
+
const defaultButton = this.form.querySelector("[type=submit]");
|
|
361
|
+
defaultButton === null || defaultButton === void 0 ? void 0 : defaultButton.click();
|
|
362
|
+
}
|
|
363
|
+
break;
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* Used to stop propagation of proxy element events
|
|
368
|
+
* @param e - Event object
|
|
369
|
+
*/
|
|
370
|
+
stopPropagation(e) {
|
|
371
|
+
e.stopPropagation();
|
|
372
|
+
}
|
|
373
|
+
};
|
|
374
|
+
index.attr({ mode: "boolean" })(C.prototype, "disabled");
|
|
375
|
+
index.attr({ mode: "fromView", attribute: "value" })(C.prototype, "initialValue");
|
|
376
|
+
index.attr({ attribute: "current-value" })(C.prototype, "currentValue");
|
|
377
|
+
index.attr(C.prototype, "name");
|
|
378
|
+
index.attr({ mode: "boolean" })(C.prototype, "required");
|
|
379
|
+
index.observable(C.prototype, "value");
|
|
380
|
+
return C;
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* @alpha
|
|
384
|
+
*/
|
|
385
|
+
function CheckableFormAssociated(BaseCtor) {
|
|
386
|
+
class C extends FormAssociated(BaseCtor) {
|
|
387
|
+
}
|
|
388
|
+
class D extends C {
|
|
389
|
+
constructor(...args) {
|
|
390
|
+
super(args);
|
|
391
|
+
/**
|
|
392
|
+
* Tracks whether the "checked" property has been changed.
|
|
393
|
+
* This is necessary to provide consistent behavior with
|
|
394
|
+
* normal input checkboxes
|
|
395
|
+
*/
|
|
396
|
+
this.dirtyChecked = false;
|
|
397
|
+
/**
|
|
398
|
+
* Provides the default checkedness of the input element
|
|
399
|
+
* Passed down to proxy
|
|
400
|
+
*
|
|
401
|
+
* @public
|
|
402
|
+
* @remarks
|
|
403
|
+
* HTML Attribute: checked
|
|
404
|
+
*/
|
|
405
|
+
this.checkedAttribute = false;
|
|
406
|
+
/**
|
|
407
|
+
* The checked state of the control.
|
|
408
|
+
*
|
|
409
|
+
* @public
|
|
410
|
+
*/
|
|
411
|
+
this.checked = false;
|
|
412
|
+
// Re-initialize dirtyChecked because initialization of other values
|
|
413
|
+
// causes it to become true
|
|
414
|
+
this.dirtyChecked = false;
|
|
415
|
+
}
|
|
416
|
+
checkedAttributeChanged() {
|
|
417
|
+
this.defaultChecked = this.checkedAttribute;
|
|
418
|
+
}
|
|
419
|
+
/**
|
|
420
|
+
* @internal
|
|
421
|
+
*/
|
|
422
|
+
defaultCheckedChanged() {
|
|
423
|
+
if (!this.dirtyChecked) {
|
|
424
|
+
// Setting this.checked will cause us to enter a dirty state,
|
|
425
|
+
// but if we are clean when defaultChecked is changed, we want to stay
|
|
426
|
+
// in a clean state, so reset this.dirtyChecked
|
|
427
|
+
this.checked = this.defaultChecked;
|
|
428
|
+
this.dirtyChecked = false;
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
checkedChanged(prev, next) {
|
|
432
|
+
if (!this.dirtyChecked) {
|
|
433
|
+
this.dirtyChecked = true;
|
|
434
|
+
}
|
|
435
|
+
this.currentChecked = this.checked;
|
|
436
|
+
this.updateForm();
|
|
437
|
+
if (this.proxy instanceof HTMLInputElement) {
|
|
438
|
+
this.proxy.checked = this.checked;
|
|
439
|
+
}
|
|
440
|
+
if (prev !== undefined) {
|
|
441
|
+
this.$emit("change");
|
|
442
|
+
}
|
|
443
|
+
this.validate();
|
|
444
|
+
}
|
|
445
|
+
currentCheckedChanged(prev, next) {
|
|
446
|
+
this.checked = this.currentChecked;
|
|
447
|
+
}
|
|
448
|
+
updateForm() {
|
|
449
|
+
const value = this.checked ? this.value : null;
|
|
450
|
+
this.setFormValue(value, value);
|
|
451
|
+
}
|
|
452
|
+
connectedCallback() {
|
|
453
|
+
super.connectedCallback();
|
|
454
|
+
this.updateForm();
|
|
455
|
+
}
|
|
456
|
+
formResetCallback() {
|
|
457
|
+
super.formResetCallback();
|
|
458
|
+
this.checked = !!this.checkedAttribute;
|
|
459
|
+
this.dirtyChecked = false;
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
index.attr({ attribute: "checked", mode: "boolean" })(D.prototype, "checkedAttribute");
|
|
463
|
+
index.attr({ attribute: "current-checked", converter: index.booleanConverter })(D.prototype, "currentChecked");
|
|
464
|
+
index.observable(D.prototype, "defaultChecked");
|
|
465
|
+
index.observable(D.prototype, "checked");
|
|
466
|
+
return D;
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
exports.CheckableFormAssociated = CheckableFormAssociated;
|
|
470
|
+
exports.FormAssociated = FormAssociated;
|