@descope/web-components-ui 1.0.419 → 1.0.421
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 +1 -0
- package/dist/cjs/index.cjs.js +1439 -1353
- package/dist/cjs/index.cjs.js.map +1 -1
- package/dist/index.d.ts +0 -2
- package/dist/index.esm.js +1983 -1091
- package/dist/index.esm.js.map +1 -1
- package/dist/umd/1172.js +240 -0
- package/dist/umd/{8162.js → 1396.js} +3 -3
- package/dist/umd/1402.js +1 -0
- package/dist/umd/1484.js +148 -0
- package/dist/umd/{5026.js → 189.js} +5 -117
- package/dist/umd/{6637.js → 201.js} +5 -5
- package/dist/umd/{1053.js → 2159.js} +13 -13
- package/dist/umd/2540.js +1 -0
- package/dist/umd/2570.js +338 -0
- package/dist/umd/2666.js +148 -0
- package/dist/umd/3110.js +275 -0
- package/dist/umd/{9167.js → 3191.js} +66 -12
- package/dist/umd/3437.js +2 -0
- package/dist/umd/{6418.js → 3638.js} +2 -2
- package/dist/umd/{7212.js → 404.js} +8 -8
- package/dist/umd/4114.js +124 -0
- package/dist/umd/{7607.js → 4127.js} +9 -9
- package/dist/umd/4187.js +2 -0
- package/dist/umd/4218.js +129 -0
- package/dist/umd/4455.js +422 -0
- package/dist/umd/4480.js +1 -1
- package/dist/umd/{5086.js → 4554.js} +5 -5
- package/dist/umd/{4834.js → 4574.js} +5 -5
- package/dist/umd/4619.js +1 -1
- package/dist/umd/4902.js +170 -0
- package/dist/umd/{5273.js → 507.js} +5 -5
- package/dist/umd/5096.js +109 -0
- package/dist/umd/5318.js +1 -0
- package/dist/umd/5414.js +2 -0
- package/dist/umd/5414.js.LICENSE.txt +1 -0
- package/dist/umd/{8164.js → 5563.js} +5 -5
- package/dist/umd/{7824.js → 7097.js} +5 -117
- package/dist/umd/7150.js +2 -0
- package/dist/umd/7150.js.LICENSE.txt +485 -0
- package/dist/umd/731.js +832 -0
- package/dist/umd/742.js +2 -0
- package/dist/umd/{351.js → 7979.js} +10 -10
- package/dist/umd/8823.js +1 -0
- package/dist/umd/{6474.js → 9030.js} +12 -12
- package/dist/umd/9243.js +202 -0
- package/dist/umd/9243.js.LICENSE.txt +51 -0
- package/dist/umd/{5443.js → 9478.js} +5 -117
- package/dist/umd/DescopeDev.js +1 -2
- package/dist/umd/boolean-fields-descope-checkbox-index-js.js +1 -1
- package/dist/umd/boolean-fields-descope-switch-toggle-index-js.js +1 -1
- package/dist/umd/button-selection-group-fields-descope-button-multi-selection-group-index-js.js +1 -1
- package/dist/umd/button-selection-group-fields-descope-button-selection-group-index-js.js +1 -1
- package/dist/umd/button-selection-group-fields-descope-button-selection-group-item-index-js.js +1 -1
- package/dist/umd/descope-alert-index-js.js +1 -1
- package/dist/umd/descope-apps-list-index-js.js +1 -1
- package/dist/umd/descope-avatar.js +1 -0
- package/dist/umd/descope-button-index-js.js +4 -116
- package/dist/umd/descope-code-snippet-index-js.js +1 -1
- package/dist/umd/descope-combo-box-index-js.js +5 -5
- package/dist/umd/descope-date-field-descope-calendar-index-js.js +1 -1
- package/dist/umd/descope-date-field-index-js.js +1 -1
- package/dist/umd/descope-divider-index-js.js +1 -1
- package/dist/umd/descope-email-field-index-js.js +4 -4
- package/dist/umd/descope-enriched-text-index-js.js +1 -1
- package/dist/umd/descope-grid-descope-grid-custom-column-index-js.js +4 -4
- package/dist/umd/descope-grid-descope-grid-item-details-column-index-js.js +19 -4
- package/dist/umd/descope-grid-descope-grid-item-details-column-index-js.js.LICENSE.txt +12 -0
- package/dist/umd/descope-grid-descope-grid-selection-column-index-js.js +1 -1
- package/dist/umd/descope-grid-descope-grid-text-column-index-js.js +4 -4
- package/dist/umd/descope-grid-index-js.js +1 -1
- package/dist/umd/descope-hybrid-field-index-js.js +3 -3
- package/dist/umd/descope-icon-index-js.js +1 -1
- package/dist/umd/descope-link-index-js.js +1 -1
- package/dist/umd/descope-modal-index-js.js +1 -1
- package/dist/umd/descope-multi-select-combo-box-index-js.js +1 -1
- package/dist/umd/descope-new-password-index-js.js +1 -1
- package/dist/umd/descope-notification-descope-notification-card-index-js.js +1 -1
- package/dist/umd/descope-notification-index-js.js +1 -1
- package/dist/umd/descope-number-field-index-js.js +1 -1
- package/dist/umd/descope-passcode-descope-passcode-internal-index-js.js +1 -1
- package/dist/umd/descope-passcode-index-js.js +1 -1
- package/dist/umd/descope-password-index-js.js +1 -1
- package/dist/umd/descope-radio-group-index-js.js +1 -1
- package/dist/umd/descope-scopes-list-index-js.js +1 -1
- package/dist/umd/descope-security-questions-setup-index-js.js +1 -1
- package/dist/umd/descope-security-questions-verify-index-js.js +2 -2
- package/dist/umd/descope-text-area-index-js.js +1 -1
- package/dist/umd/descope-text-field-index-js.js +2 -2
- package/dist/umd/descope-text.js +1 -0
- package/dist/umd/descope-third-party-app-logo-index-js.js +1 -1
- package/dist/umd/descope-upload-file-index-js.js +1 -1
- package/dist/umd/descope-user-attribute-index-js.js +1 -1
- package/dist/umd/descope-user-auth-method-index-js.js +1 -1
- package/dist/umd/index.js +1 -1
- package/dist/umd/mapping-fields-descope-mappings-field-index-js.js +1 -1
- package/dist/umd/mapping-fields-descope-saml-group-mappings-index-js.js +1 -1
- package/dist/umd/phone-fields-descope-phone-field-descope-phone-field-internal-index-js.js +1 -1
- package/dist/umd/phone-fields-descope-phone-field-index-js.js +1 -1
- package/dist/umd/phone-fields-descope-phone-input-box-field-descope-phone-input-box-internal-index-js.js +2 -2
- package/dist/umd/phone-fields-descope-phone-input-box-field-index-js.js +7 -7
- package/node_modules/common/.eslintrc.json +18 -0
- package/node_modules/common/README.md +7 -0
- package/node_modules/common/package.json +34 -0
- package/node_modules/common/project.json +7 -0
- package/node_modules/common/src/baseClasses/baseClasses/createBaseClass.js +66 -0
- package/node_modules/common/src/baseClasses/baseClasses/createBaseInputClass.js +14 -0
- package/node_modules/common/src/baseClasses/baseClasses/createCssVarImageClass.js +55 -0
- package/node_modules/common/src/baseClasses/index.js +3 -0
- package/node_modules/common/src/componentsHelpers/index.js +95 -0
- package/node_modules/common/src/componentsMixins/helpers/mixinsHelpers.js +10 -0
- package/node_modules/common/src/componentsMixins/index.js +1 -0
- package/node_modules/common/src/componentsMixins/mixins/activableMixin.js +14 -0
- package/node_modules/common/src/componentsMixins/mixins/changeMixin.js +22 -0
- package/node_modules/common/src/componentsMixins/mixins/componentNameValidationMixin.js +23 -0
- package/node_modules/common/src/componentsMixins/mixins/componentsContextMixin.js +12 -0
- package/node_modules/common/src/componentsMixins/mixins/createDynamicDataMixin.js +100 -0
- package/node_modules/common/src/componentsMixins/mixins/createProxy.js +58 -0
- package/node_modules/common/src/componentsMixins/mixins/createStyleMixin/helpers.js +106 -0
- package/node_modules/common/src/componentsMixins/mixins/createStyleMixin/index.js +167 -0
- package/node_modules/common/src/componentsMixins/mixins/draggableMixin.js +62 -0
- package/node_modules/common/src/componentsMixins/mixins/externalInputHelpers.js +93 -0
- package/node_modules/common/src/componentsMixins/mixins/externalInputMixin.js +170 -0
- package/node_modules/common/src/componentsMixins/mixins/hoverableMixin.js +13 -0
- package/node_modules/common/src/componentsMixins/mixins/index.js +14 -0
- package/node_modules/common/src/componentsMixins/mixins/inputEventsDispatchingMixin.js +76 -0
- package/node_modules/common/src/componentsMixins/mixins/inputValidationMixin.js +210 -0
- package/node_modules/common/src/componentsMixins/mixins/lifecycleEventsMixin.js +23 -0
- package/node_modules/common/src/componentsMixins/mixins/normalizeBooleanAttributesMixin.js +57 -0
- package/node_modules/common/src/componentsMixins/mixins/portalMixin.js +112 -0
- package/node_modules/common/src/componentsMixins/mixins/proxyInputMixin.js +242 -0
- package/node_modules/common/src/constants.js +4 -0
- package/node_modules/common/src/icons/errorMessageIconBase64.js +1 -0
- package/node_modules/common/src/sbControls.js +302 -0
- package/node_modules/common/src/themeHelpers/colorsHelpers.js +94 -0
- package/node_modules/common/src/themeHelpers/index.js +176 -0
- package/node_modules/common/src/utils/index.js +68 -0
- package/node_modules/descope-avatar/e2e/descope-avatar.spec.ts +54 -0
- package/node_modules/descope-avatar/package.json +34 -0
- package/node_modules/descope-avatar/project.json +7 -0
- package/{src/components/descope-avatar → node_modules/descope-avatar/src/component}/AvatarClass.js +4 -4
- package/{src/theme/components/avatar.js → node_modules/descope-avatar/src/theme.js} +3 -3
- package/node_modules/descope-avatar/stories/avatar.jpeg +0 -0
- package/node_modules/descope-avatar/stories/descope-avatar.stories.js +32 -0
- package/node_modules/descope-text/e2e/descope-text.spec.ts +35 -0
- package/node_modules/descope-text/package.json +31 -0
- package/node_modules/descope-text/project.json +7 -0
- package/{src/components/descope-text → node_modules/descope-text/src/component}/TextClass.js +4 -4
- package/{src/theme/components/text.js → node_modules/descope-text/src/theme.js} +3 -3
- package/node_modules/descope-text/stories/descope-text.stories.js +55 -0
- package/node_modules/theme-globals/package.json +16 -0
- package/node_modules/theme-globals/project.json +7 -0
- package/node_modules/theme-globals/src/index.js +180 -0
- package/package.json +54 -43
- package/src/components/descope-apps-list/AppsListClass.js +1 -1
- package/src/components/descope-apps-list/index.js +2 -2
- package/src/components/descope-divider/DividerClass.js +1 -1
- package/src/components/descope-divider/index.js +1 -1
- package/src/components/descope-link/LinkClass.js +1 -1
- package/src/components/descope-link/index.js +1 -1
- package/src/components/descope-security-questions-verify/SecurityQuestionsVerifyClass.js +1 -1
- package/src/components/descope-security-questions-verify/index.js +1 -1
- package/src/components/descope-user-attribute/UserAttributeClass.js +1 -1
- package/src/components/descope-user-attribute/index.js +1 -1
- package/src/components/descope-user-auth-method/UserAuthMethodClass.js +1 -1
- package/src/components/descope-user-auth-method/index.js +1 -1
- package/src/components/mapping-fields/descope-mappings-field/MappingsFieldClass.js +1 -1
- package/src/components/mapping-fields/descope-mappings-field/index.js +1 -1
- package/src/helpers/themeHelpers/index.js +1 -1
- package/src/index.cjs.js +2 -2
- package/src/index.d.ts +0 -2
- package/src/index.js +2 -2
- package/src/index.umd.js +3 -1
- package/src/mixins/createStyleMixin/index.js +1 -1
- package/src/theme/components/alert.js +1 -1
- package/src/theme/components/comboBox.js +2 -2
- package/src/theme/components/enrichedText.js +1 -1
- package/src/theme/components/index.js +2 -2
- package/dist/umd/1033.js +0 -2
- package/dist/umd/1414.js +0 -352
- package/dist/umd/1437.js +0 -422
- package/dist/umd/1672.js +0 -1
- package/dist/umd/2566.js +0 -2
- package/dist/umd/2838.js +0 -2
- package/dist/umd/2838.js.LICENSE.txt +0 -1
- package/dist/umd/286.js +0 -148
- package/dist/umd/2919.js +0 -832
- package/dist/umd/3222.js +0 -282
- package/dist/umd/3607.js +0 -2
- package/dist/umd/3711.js +0 -123
- package/dist/umd/5412.js +0 -109
- package/dist/umd/650.js +0 -1
- package/dist/umd/6726.js +0 -148
- package/dist/umd/7407.js +0 -450
- package/dist/umd/8980.js +0 -143
- package/dist/umd/8980.js.LICENSE.txt +0 -29
- package/dist/umd/9632.js +0 -275
- package/dist/umd/9878.js +0 -1
- package/dist/umd/9895.js +0 -17
- package/dist/umd/DescopeDev.js.LICENSE.txt +0 -1
- package/dist/umd/bcdfe87ae253c2cf789c9a737f8d8c22.woff +0 -0
- package/dist/umd/descope-avatar-index-js.js +0 -1
- package/dist/umd/descope-text-index-js.js +0 -1
- /package/dist/umd/{1414.js.LICENSE.txt → 1172.js.LICENSE.txt} +0 -0
- /package/dist/umd/{1437.js.LICENSE.txt → 1396.js.LICENSE.txt} +0 -0
- /package/dist/umd/{6726.js.LICENSE.txt → 1484.js.LICENSE.txt} +0 -0
- /package/dist/umd/{286.js.LICENSE.txt → 189.js.LICENSE.txt} +0 -0
- /package/dist/umd/{6637.js.LICENSE.txt → 201.js.LICENSE.txt} +0 -0
- /package/dist/umd/{1053.js.LICENSE.txt → 2159.js.LICENSE.txt} +0 -0
- /package/dist/umd/{351.js.LICENSE.txt → 2570.js.LICENSE.txt} +0 -0
- /package/dist/umd/{5026.js.LICENSE.txt → 2666.js.LICENSE.txt} +0 -0
- /package/dist/umd/{9632.js.LICENSE.txt → 3110.js.LICENSE.txt} +0 -0
- /package/dist/umd/{9167.js.LICENSE.txt → 3191.js.LICENSE.txt} +0 -0
- /package/dist/umd/{1033.js.LICENSE.txt → 3437.js.LICENSE.txt} +0 -0
- /package/dist/umd/{6418.js.LICENSE.txt → 3638.js.LICENSE.txt} +0 -0
- /package/dist/umd/{7212.js.LICENSE.txt → 404.js.LICENSE.txt} +0 -0
- /package/dist/umd/{3711.js.LICENSE.txt → 4114.js.LICENSE.txt} +0 -0
- /package/dist/umd/{7607.js.LICENSE.txt → 4127.js.LICENSE.txt} +0 -0
- /package/dist/umd/{3607.js.LICENSE.txt → 4187.js.LICENSE.txt} +0 -0
- /package/dist/umd/{3222.js.LICENSE.txt → 4218.js.LICENSE.txt} +0 -0
- /package/dist/umd/{5086.js.LICENSE.txt → 4455.js.LICENSE.txt} +0 -0
- /package/dist/umd/{5273.js.LICENSE.txt → 4554.js.LICENSE.txt} +0 -0
- /package/dist/umd/{4834.js.LICENSE.txt → 4574.js.LICENSE.txt} +0 -0
- /package/dist/umd/{9895.js.LICENSE.txt → 4902.js.LICENSE.txt} +0 -0
- /package/dist/umd/{5443.js.LICENSE.txt → 507.js.LICENSE.txt} +0 -0
- /package/dist/umd/{5412.js.LICENSE.txt → 5096.js.LICENSE.txt} +0 -0
- /package/dist/umd/{8164.js.LICENSE.txt → 5563.js.LICENSE.txt} +0 -0
- /package/dist/umd/{7407.js.LICENSE.txt → 7097.js.LICENSE.txt} +0 -0
- /package/dist/umd/{2919.js.LICENSE.txt → 731.js.LICENSE.txt} +0 -0
- /package/dist/umd/{2566.js.LICENSE.txt → 742.js.LICENSE.txt} +0 -0
- /package/dist/umd/{7824.js.LICENSE.txt → 7979.js.LICENSE.txt} +0 -0
- /package/dist/umd/{6474.js.LICENSE.txt → 9030.js.LICENSE.txt} +0 -0
- /package/dist/umd/{8162.js.LICENSE.txt → 9478.js.LICENSE.txt} +0 -0
- /package/{src/helpers → node_modules/common/src}/themeHelpers/componentsThemeManager.js +0 -0
- /package/{src/components/descope-avatar → node_modules/descope-avatar/src/component}/index.js +0 -0
- /package/{src/components/descope-text → node_modules/descope-text/src/component}/index.js +0 -0
@@ -0,0 +1,76 @@
|
|
1
|
+
import { createDispatchEvent } from '../helpers/mixinsHelpers';
|
2
|
+
|
3
|
+
export const inputEventsDispatchingMixin = (superclass) =>
|
4
|
+
class InputEventsDispatchingMixinClass extends superclass {
|
5
|
+
init() {
|
6
|
+
this.#blockNativeEvents();
|
7
|
+
|
8
|
+
super.init?.();
|
9
|
+
}
|
10
|
+
|
11
|
+
// we want to block the native (trusted) events and control when these events are being dispatched
|
12
|
+
#blockNativeEvents() {
|
13
|
+
['blur', 'focus', 'focusin', 'focusout'].forEach((event) => {
|
14
|
+
this.addEventListener(event, (e) => {
|
15
|
+
e.isTrusted && e.target === this && e.stopImmediatePropagation();
|
16
|
+
});
|
17
|
+
});
|
18
|
+
}
|
19
|
+
|
20
|
+
handleFocusEventsDispatching(inputs) {
|
21
|
+
let timerId;
|
22
|
+
|
23
|
+
// in order to simulate blur & focusout on root input element
|
24
|
+
// we are checking if focus on one of the inner elements happened immediately after blur
|
25
|
+
// if not, the component is no longer focused and we should dispatch blur & focusout
|
26
|
+
inputs?.forEach((input) => {
|
27
|
+
input?.addEventListener('focusout', (e) => {
|
28
|
+
e.stopImmediatePropagation();
|
29
|
+
timerId = setTimeout(() => {
|
30
|
+
timerId = null;
|
31
|
+
|
32
|
+
createDispatchEvent.call(this, 'blur');
|
33
|
+
createDispatchEvent.call(this, 'focusout', { bubbles: true });
|
34
|
+
});
|
35
|
+
});
|
36
|
+
|
37
|
+
// in order to simulate focus & focusin on the root input element
|
38
|
+
// we are holding a timer id and clearing it on focusin
|
39
|
+
// if there is a timer id, it means that the root input is still focused
|
40
|
+
// otherwise, it was not focused before, and we should dispatch focus & focusin
|
41
|
+
const onFocus = (e) => {
|
42
|
+
e.stopImmediatePropagation();
|
43
|
+
clearTimeout(timerId);
|
44
|
+
if (!timerId) {
|
45
|
+
createDispatchEvent.call(this, 'focus');
|
46
|
+
createDispatchEvent.call(this, 'focusin', { bubbles: true });
|
47
|
+
}
|
48
|
+
};
|
49
|
+
|
50
|
+
// some components are not dispatching focusin but only focus
|
51
|
+
input?.addEventListener('focusin', onFocus);
|
52
|
+
input?.addEventListener('focus', onFocus);
|
53
|
+
});
|
54
|
+
}
|
55
|
+
|
56
|
+
// we want to block the input events from propagating in case the value of the root input wasn't change
|
57
|
+
// this can happen if we are sanitizing characters on the internal inputs and do not want it to affect the root input element value
|
58
|
+
// in this case, on each input event, we are comparing the root input value to the previous one, and only if it does not match, we are allowing the input event to propagate
|
59
|
+
handleInputEventDispatching() {
|
60
|
+
let previousRootComponentValue = this.value;
|
61
|
+
|
62
|
+
// we are comparing the previous value to the new one,
|
63
|
+
// and if they have the same value, we are blocking the input event
|
64
|
+
this.addEventListener('input', (e) => {
|
65
|
+
// We don't want to block our own event that we fire from handleInputEventDispatching
|
66
|
+
if (this !== e.target) {
|
67
|
+
e.stopImmediatePropagation();
|
68
|
+
|
69
|
+
if (previousRootComponentValue !== this.value) {
|
70
|
+
previousRootComponentValue = this.value;
|
71
|
+
createDispatchEvent.call(this, 'input', { bubbles: true, composed: true });
|
72
|
+
}
|
73
|
+
}
|
74
|
+
});
|
75
|
+
}
|
76
|
+
};
|
@@ -0,0 +1,210 @@
|
|
1
|
+
import 'element-internals-polyfill'; // this is needed in order to support older browsers
|
2
|
+
|
3
|
+
const observedAttributes = ['required', 'pattern'];
|
4
|
+
|
5
|
+
const errorAttributes = {
|
6
|
+
valueMissing: 'data-errormessage-value-missing',
|
7
|
+
patternMismatch: 'data-errormessage-pattern-mismatch',
|
8
|
+
tooShort: 'data-errormessage-pattern-mismatch-too-short',
|
9
|
+
tooLong: 'data-errormessage-pattern-mismatch-too-long',
|
10
|
+
rangeUnderflow: 'data-errormessage-pattern-range-underflow',
|
11
|
+
rangeOverflow: 'data-errormessage-pattern-range-overflow',
|
12
|
+
typeMismatch: 'data-errormessage-type-mismatch',
|
13
|
+
};
|
14
|
+
|
15
|
+
const validationTargetSymbol = Symbol('validationTarget');
|
16
|
+
|
17
|
+
export const inputValidationMixin = (superclass) =>
|
18
|
+
class InputValidationMixinClass extends superclass {
|
19
|
+
#validationTarget = validationTargetSymbol;
|
20
|
+
|
21
|
+
static get observedAttributes() {
|
22
|
+
return [...(superclass.observedAttributes || []), ...observedAttributes];
|
23
|
+
}
|
24
|
+
|
25
|
+
static get formAssociated() {
|
26
|
+
return true;
|
27
|
+
}
|
28
|
+
|
29
|
+
#internals;
|
30
|
+
|
31
|
+
get internals() {
|
32
|
+
return this.#internals;
|
33
|
+
}
|
34
|
+
|
35
|
+
set internals(value) {
|
36
|
+
this.#internals = value;
|
37
|
+
}
|
38
|
+
|
39
|
+
constructor() {
|
40
|
+
super();
|
41
|
+
|
42
|
+
this.#internals = this.attachInternals();
|
43
|
+
}
|
44
|
+
|
45
|
+
// eslint-disable-next-line class-methods-use-this
|
46
|
+
get defaultErrorMsgValueMissing() {
|
47
|
+
return 'Please fill out this field.';
|
48
|
+
}
|
49
|
+
|
50
|
+
// eslint-disable-next-line class-methods-use-this
|
51
|
+
get defaultErrorMsgPatternMismatch() {
|
52
|
+
return 'Please match the requested format.';
|
53
|
+
}
|
54
|
+
|
55
|
+
get defaultErrorMsgTooShort() {
|
56
|
+
return `Minimum length is ${this.getAttribute('minlength')}.`;
|
57
|
+
}
|
58
|
+
|
59
|
+
get defaultErrorMsgTooLong() {
|
60
|
+
return `Maximum length is ${this.getAttribute('maxlength')}. `;
|
61
|
+
}
|
62
|
+
|
63
|
+
get defaultErrorMsgRangeUnderflow() {
|
64
|
+
return `At least ${this.getAttribute('min-items-selection')} items are required.`;
|
65
|
+
}
|
66
|
+
|
67
|
+
get defaultErrorMsgRangeOverflow() {
|
68
|
+
return `At most ${this.getAttribute('max-items-selection')} items are allowed.`;
|
69
|
+
}
|
70
|
+
|
71
|
+
// eslint-disable-next-line class-methods-use-this
|
72
|
+
get defaultErrorMsgTypeMismatch() {
|
73
|
+
return `Please match the requested type.`;
|
74
|
+
}
|
75
|
+
|
76
|
+
getErrorMessage(flags) {
|
77
|
+
const {
|
78
|
+
valueMissing,
|
79
|
+
patternMismatch,
|
80
|
+
typeMismatch,
|
81
|
+
stepMismatch,
|
82
|
+
tooShort,
|
83
|
+
tooLong,
|
84
|
+
rangeOverflow,
|
85
|
+
rangeUnderflow,
|
86
|
+
badInput,
|
87
|
+
customError,
|
88
|
+
} = flags;
|
89
|
+
|
90
|
+
switch (true) {
|
91
|
+
case valueMissing:
|
92
|
+
return (
|
93
|
+
this.getAttribute(errorAttributes.valueMissing) || this.defaultErrorMsgValueMissing
|
94
|
+
);
|
95
|
+
case patternMismatch || stepMismatch || badInput:
|
96
|
+
return (
|
97
|
+
this.getAttribute(errorAttributes.patternMismatch) ||
|
98
|
+
this.defaultErrorMsgPatternMismatch
|
99
|
+
);
|
100
|
+
case typeMismatch:
|
101
|
+
return (
|
102
|
+
this.getAttribute(errorAttributes.typeMismatch) ||
|
103
|
+
this.getAttribute(errorAttributes.patternMismatch) ||
|
104
|
+
this.defaultErrorMsgTypeMismatch
|
105
|
+
);
|
106
|
+
case tooShort:
|
107
|
+
return this.getAttribute(errorAttributes.tooShort) || this.defaultErrorMsgTooShort;
|
108
|
+
case tooLong:
|
109
|
+
return this.getAttribute(errorAttributes.tooLong) || this.defaultErrorMsgTooLong;
|
110
|
+
case rangeUnderflow:
|
111
|
+
return (
|
112
|
+
this.getAttribute(errorAttributes.rangeUnderflow) || this.defaultErrorMsgRangeUnderflow
|
113
|
+
);
|
114
|
+
case rangeOverflow:
|
115
|
+
return (
|
116
|
+
this.getAttribute(errorAttributes.rangeOverflow) || this.defaultErrorMsgRangeOverflow
|
117
|
+
);
|
118
|
+
case customError:
|
119
|
+
return this.validationMessage;
|
120
|
+
default:
|
121
|
+
return '';
|
122
|
+
}
|
123
|
+
}
|
124
|
+
|
125
|
+
#setValidity() {
|
126
|
+
const validity = this.isReadOnly ? {} : this.getValidity();
|
127
|
+
this.#internals.setValidity(validity, this.getErrorMessage(validity), this.validationTarget);
|
128
|
+
}
|
129
|
+
|
130
|
+
get validationMessage() {
|
131
|
+
return this.#internals.validationMessage;
|
132
|
+
}
|
133
|
+
|
134
|
+
// eslint-disable-next-line class-methods-use-this
|
135
|
+
getValidity() {
|
136
|
+
// eslint-disable-next-line no-console
|
137
|
+
console.warn('getValidity', 'is not implemented');
|
138
|
+
}
|
139
|
+
|
140
|
+
checkValidity() {
|
141
|
+
return this.#internals.validity.valid;
|
142
|
+
}
|
143
|
+
|
144
|
+
reportValidity() {
|
145
|
+
return this.#internals.reportValidity();
|
146
|
+
}
|
147
|
+
|
148
|
+
get validity() {
|
149
|
+
return this.#internals.validity;
|
150
|
+
}
|
151
|
+
|
152
|
+
get validationTarget() {
|
153
|
+
return this.#validationTarget === validationTargetSymbol
|
154
|
+
? this.inputElement
|
155
|
+
: this.#validationTarget;
|
156
|
+
}
|
157
|
+
|
158
|
+
set validationTarget(val) {
|
159
|
+
this.#validationTarget = val;
|
160
|
+
}
|
161
|
+
|
162
|
+
setCustomValidity(errorMessage) {
|
163
|
+
if (errorMessage) {
|
164
|
+
this.#internals.setValidity({ customError: true }, errorMessage, this.validationTarget);
|
165
|
+
} else {
|
166
|
+
this.#internals.setValidity({});
|
167
|
+
this.#setValidity();
|
168
|
+
}
|
169
|
+
}
|
170
|
+
|
171
|
+
get isRequired() {
|
172
|
+
return this.hasAttribute('required') && this.getAttribute('required') !== 'false';
|
173
|
+
}
|
174
|
+
|
175
|
+
get isReadOnly() {
|
176
|
+
return this.hasAttribute('readonly') && this.getAttribute('readonly') !== 'false';
|
177
|
+
}
|
178
|
+
|
179
|
+
get isDisabled() {
|
180
|
+
return this.hasAttribute('disabled') && this.getAttribute('disabled') !== 'false';
|
181
|
+
}
|
182
|
+
|
183
|
+
get pattern() {
|
184
|
+
return this.getAttribute('pattern');
|
185
|
+
}
|
186
|
+
|
187
|
+
get form() {
|
188
|
+
return this.#internals.form;
|
189
|
+
}
|
190
|
+
|
191
|
+
attributeChangedCallback(attrName, oldValue, newValue) {
|
192
|
+
super.attributeChangedCallback?.(attrName, oldValue, newValue);
|
193
|
+
|
194
|
+
if (observedAttributes.includes(attrName)) {
|
195
|
+
this.#setValidity();
|
196
|
+
}
|
197
|
+
}
|
198
|
+
|
199
|
+
init() {
|
200
|
+
super.init?.();
|
201
|
+
this.addEventListener('change', this.#setValidity);
|
202
|
+
this.addEventListener('invalid', (e) => e.stopPropagation());
|
203
|
+
this.addEventListener('input', this.#setValidity);
|
204
|
+
|
205
|
+
// The attribute sync takes time, so getValidity returns valid,
|
206
|
+
// even when it shouldn't. This way allows all attributes to sync
|
207
|
+
// after render, before checking the validity.
|
208
|
+
setTimeout(() => this.#setValidity());
|
209
|
+
}
|
210
|
+
};
|
@@ -0,0 +1,23 @@
|
|
1
|
+
import { createDispatchEvent } from '../helpers/mixinsHelpers';
|
2
|
+
|
3
|
+
export const lifecycleEventsMixin = (superclass) =>
|
4
|
+
class LifecycleEventsMixinClass extends superclass {
|
5
|
+
#dispatchConnected = createDispatchEvent.bind(this, 'connected');
|
6
|
+
|
7
|
+
#dispatchDisconnected = createDispatchEvent.bind(this, 'disconnected');
|
8
|
+
|
9
|
+
connectedCallback() {
|
10
|
+
if (this.rootElement.isConnected) {
|
11
|
+
super.connectedCallback?.();
|
12
|
+
|
13
|
+
// we are waiting for all components to listen before dispatching
|
14
|
+
setTimeout(this.#dispatchConnected);
|
15
|
+
}
|
16
|
+
}
|
17
|
+
|
18
|
+
disconnectedCallback() {
|
19
|
+
super.disconnectedCallback?.();
|
20
|
+
|
21
|
+
this.#dispatchDisconnected();
|
22
|
+
}
|
23
|
+
};
|
@@ -0,0 +1,57 @@
|
|
1
|
+
import { observeAttributes } from '../../componentsHelpers';
|
2
|
+
|
3
|
+
const booleanAttributesList = [
|
4
|
+
'readonly',
|
5
|
+
'focused',
|
6
|
+
'invalid',
|
7
|
+
'has-label',
|
8
|
+
'required',
|
9
|
+
'disabled',
|
10
|
+
'checked',
|
11
|
+
'has-helper',
|
12
|
+
'has-value',
|
13
|
+
'step-buttons-visible',
|
14
|
+
'hover',
|
15
|
+
'has-error-message',
|
16
|
+
'focus-ring',
|
17
|
+
'opened',
|
18
|
+
'active',
|
19
|
+
'password-visible',
|
20
|
+
'opening',
|
21
|
+
'closing',
|
22
|
+
'has-no-options',
|
23
|
+
];
|
24
|
+
|
25
|
+
const isBooleanAttribute = (attr) => {
|
26
|
+
return booleanAttributesList.includes(attr);
|
27
|
+
};
|
28
|
+
// we want all the valueless attributes to have "true" value
|
29
|
+
// and all the falsy attribute to be removed
|
30
|
+
export const normalizeBooleanAttributesMixin = (superclass) =>
|
31
|
+
class NormalizeBooleanAttributesMixinClass extends superclass {
|
32
|
+
init() {
|
33
|
+
super.init?.();
|
34
|
+
|
35
|
+
observeAttributes(
|
36
|
+
this,
|
37
|
+
(attrs) =>
|
38
|
+
attrs.forEach((attr) => {
|
39
|
+
const attrVal = this.getAttribute(attr);
|
40
|
+
|
41
|
+
if (isBooleanAttribute(attr)) {
|
42
|
+
if (attrVal === '') {
|
43
|
+
this.setAttribute(attr, 'true');
|
44
|
+
} else if (attrVal === 'false') {
|
45
|
+
this.removeAttribute(attr);
|
46
|
+
}
|
47
|
+
} else if (!attrVal) {
|
48
|
+
// eslint-disable-next-line no-console
|
49
|
+
console.debug(
|
50
|
+
`attribute "${attr}" has no value, should it be added to the boolean attributes list?`
|
51
|
+
);
|
52
|
+
}
|
53
|
+
}),
|
54
|
+
{}
|
55
|
+
);
|
56
|
+
}
|
57
|
+
};
|
@@ -0,0 +1,112 @@
|
|
1
|
+
import { kebabCaseJoin } from '../../utils';
|
2
|
+
import { forwardAttrs } from '../../componentsHelpers';
|
3
|
+
import { createStyleMixin } from '../mixins/createStyleMixin';
|
4
|
+
import { createCssVarsList } from './createStyleMixin/helpers';
|
5
|
+
|
6
|
+
// this is needed because we might generate the same css vars names
|
7
|
+
// e.g. "overlayColor" attribute in style mixin's mapping,
|
8
|
+
// will generate the same var as "color" attribute in portals's mapping
|
9
|
+
// when the portal name is "overlay".
|
10
|
+
// because of that, we are adding this separator that is also used as a differentiator
|
11
|
+
const DISPLAY_NAME_SEPARATOR = '_';
|
12
|
+
const PORTAL_THEME_PREFIX = '@';
|
13
|
+
|
14
|
+
|
15
|
+
const sanitizeSelector = (selector) => selector.replace(/[^\w\s]/gi, '');
|
16
|
+
|
17
|
+
const withWaitForShadowRoot = (getRootElementFn) => async (that) => {
|
18
|
+
const ele = await getRootElementFn(that);
|
19
|
+
|
20
|
+
return new Promise((res) => {
|
21
|
+
const MAX_RETRIES = 20;
|
22
|
+
let counter = 0;
|
23
|
+
|
24
|
+
const check = () => {
|
25
|
+
if (counter > MAX_RETRIES) {
|
26
|
+
// eslint-disable-next-line no-console
|
27
|
+
console.error('could not get shadow root for element', ele);
|
28
|
+
res(ele);
|
29
|
+
return;
|
30
|
+
}
|
31
|
+
|
32
|
+
counter++;
|
33
|
+
|
34
|
+
if (!ele?.shadowRoot) {
|
35
|
+
setTimeout(check);
|
36
|
+
} else {
|
37
|
+
res(ele.shadowRoot);
|
38
|
+
}
|
39
|
+
};
|
40
|
+
check();
|
41
|
+
});
|
42
|
+
};
|
43
|
+
|
44
|
+
export const portalMixin =
|
45
|
+
({ name, selector, mappings = {}, forward: { attributes = [], include = true } = {} }) =>
|
46
|
+
(superclass) => {
|
47
|
+
const eleDisplayName = name || sanitizeSelector(selector);
|
48
|
+
|
49
|
+
const BaseClass = createStyleMixin({
|
50
|
+
mappings,
|
51
|
+
})(superclass);
|
52
|
+
|
53
|
+
return class PortalMixinClass extends BaseClass {
|
54
|
+
static get cssVarList() {
|
55
|
+
return {
|
56
|
+
...BaseClass.cssVarList,
|
57
|
+
[eleDisplayName]: createCssVarsList(
|
58
|
+
kebabCaseJoin(superclass.componentName, DISPLAY_NAME_SEPARATOR + eleDisplayName),
|
59
|
+
mappings
|
60
|
+
),
|
61
|
+
};
|
62
|
+
}
|
63
|
+
|
64
|
+
#portalEle;
|
65
|
+
|
66
|
+
constructor() {
|
67
|
+
// we cannot use "this" before calling "super"
|
68
|
+
const getRootElement = async (that) => {
|
69
|
+
const baseEle = (that.shadowRoot || that).querySelector(that.baseSelector);
|
70
|
+
if (!selector) {
|
71
|
+
return baseEle;
|
72
|
+
}
|
73
|
+
|
74
|
+
// in case we have a selector, we should first wait for the base element shadow root
|
75
|
+
// and then look for the internal element
|
76
|
+
const baseEleShadowRoot = await withWaitForShadowRoot(() => baseEle)(that);
|
77
|
+
return baseEleShadowRoot.querySelector(selector);
|
78
|
+
};
|
79
|
+
|
80
|
+
const getPortalElement = withWaitForShadowRoot(getRootElement);
|
81
|
+
|
82
|
+
super({
|
83
|
+
getRootElement: getPortalElement,
|
84
|
+
componentNameSuffix: DISPLAY_NAME_SEPARATOR + eleDisplayName,
|
85
|
+
themeSection: PORTAL_THEME_PREFIX + eleDisplayName,
|
86
|
+
baseSelector: ':host',
|
87
|
+
});
|
88
|
+
|
89
|
+
this.#portalEle = getPortalElement(this).then((ele) => ele.host);
|
90
|
+
}
|
91
|
+
|
92
|
+
async #handleHoverAttribute() {
|
93
|
+
const portalEle = await this.#portalEle;
|
94
|
+
portalEle.onmouseenter = (e) => {
|
95
|
+
e.target.setAttribute('hover', 'true');
|
96
|
+
};
|
97
|
+
portalEle.onmouseleave = (e) => {
|
98
|
+
e.target.removeAttribute('hover');
|
99
|
+
};
|
100
|
+
}
|
101
|
+
|
102
|
+
async init() {
|
103
|
+
super.init?.();
|
104
|
+
const portalEle = await this.#portalEle;
|
105
|
+
forwardAttrs(this, portalEle, {
|
106
|
+
[include ? 'includeAttrs' : 'excludeAttrs']: attributes,
|
107
|
+
});
|
108
|
+
|
109
|
+
this.#handleHoverAttribute();
|
110
|
+
}
|
111
|
+
};
|
112
|
+
};
|