@descope/web-components-ui 1.0.426 → 1.0.428
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 +0 -1
- package/dist/cjs/index.cjs.js +2520 -5270
- package/dist/cjs/index.cjs.js.map +1 -1
- package/dist/index.esm.js +2022 -4815
- package/dist/index.esm.js.map +1 -1
- package/package.json +7 -15
- package/src/components/descope-apps-list/AppsListClass.js +1 -1
- package/src/components/descope-apps-list/index.js +2 -2
- package/src/components/descope-date-field/descope-calendar/index.js +1 -1
- 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-setup/SecurityQuestionsSetupClass.js +1 -1
- package/src/components/descope-security-questions-setup/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 +2 -2
- package/src/components/phone-fields/descope-phone-field/PhoneFieldClass.js +1 -1
- package/src/components/phone-fields/descope-phone-field/descope-phone-field-internal/index.js +1 -1
- package/src/components/phone-fields/descope-phone-field/index.js +1 -1
- package/src/components/phone-fields/descope-phone-input-box-field/index.js +1 -1
- package/src/helpers/themeHelpers/index.js +1 -1
- package/src/theme/components/alert.js +1 -1
- package/src/theme/components/enrichedText.js +1 -1
- package/src/theme/components/index.js +3 -3
- package/dist/index.d.ts +0 -72
- package/node_modules/common/.eslintrc.json +0 -18
- package/node_modules/common/README.md +0 -7
- package/node_modules/common/package.json +0 -37
- package/node_modules/common/project.json +0 -7
- package/node_modules/common/src/baseClasses/baseClasses/createBaseClass.js +0 -66
- package/node_modules/common/src/baseClasses/baseClasses/createBaseInputClass.js +0 -14
- package/node_modules/common/src/baseClasses/baseClasses/createCssVarImageClass.js +0 -55
- package/node_modules/common/src/baseClasses/index.js +0 -3
- package/node_modules/common/src/componentsHelpers/index.js +0 -95
- package/node_modules/common/src/componentsMixins/helpers/mixinsHelpers.js +0 -10
- package/node_modules/common/src/componentsMixins/index.js +0 -1
- package/node_modules/common/src/componentsMixins/mixins/activableMixin.js +0 -14
- package/node_modules/common/src/componentsMixins/mixins/changeMixin.js +0 -22
- package/node_modules/common/src/componentsMixins/mixins/componentNameValidationMixin.js +0 -23
- package/node_modules/common/src/componentsMixins/mixins/componentsContextMixin.js +0 -12
- package/node_modules/common/src/componentsMixins/mixins/createDynamicDataMixin.js +0 -100
- package/node_modules/common/src/componentsMixins/mixins/createProxy.js +0 -58
- package/node_modules/common/src/componentsMixins/mixins/createStyleMixin/helpers.js +0 -106
- package/node_modules/common/src/componentsMixins/mixins/createStyleMixin/index.js +0 -167
- package/node_modules/common/src/componentsMixins/mixins/draggableMixin.js +0 -62
- package/node_modules/common/src/componentsMixins/mixins/externalInputHelpers.js +0 -93
- package/node_modules/common/src/componentsMixins/mixins/externalInputMixin.js +0 -170
- package/node_modules/common/src/componentsMixins/mixins/hoverableMixin.js +0 -13
- package/node_modules/common/src/componentsMixins/mixins/index.js +0 -14
- package/node_modules/common/src/componentsMixins/mixins/inputEventsDispatchingMixin.js +0 -76
- package/node_modules/common/src/componentsMixins/mixins/inputValidationMixin.js +0 -210
- package/node_modules/common/src/componentsMixins/mixins/lifecycleEventsMixin.js +0 -23
- package/node_modules/common/src/componentsMixins/mixins/normalizeBooleanAttributesMixin.js +0 -59
- package/node_modules/common/src/componentsMixins/mixins/portalMixin.js +0 -112
- package/node_modules/common/src/componentsMixins/mixins/proxyInputMixin.js +0 -242
- package/node_modules/common/src/constants.js +0 -4
- package/node_modules/common/src/icons/errorMessageIconBase64.js +0 -1
- package/node_modules/common/src/sbControls.js +0 -302
- package/node_modules/common/src/sbHelpers.js +0 -53
- package/node_modules/common/src/themeHelpers/colorsHelpers.js +0 -94
- package/node_modules/common/src/themeHelpers/componentsThemeManager.js +0 -45
- package/node_modules/common/src/themeHelpers/index.js +0 -191
- package/node_modules/common/src/themeHelpers/resetHelpers.js +0 -144
- package/node_modules/common/src/utils/index.js +0 -68
- package/node_modules/descope-avatar/e2e/descope-avatar.spec.ts +0 -54
- package/node_modules/descope-avatar/package.json +0 -34
- package/node_modules/descope-avatar/project.json +0 -7
- package/node_modules/descope-avatar/src/component/AvatarClass.js +0 -109
- package/node_modules/descope-avatar/src/component/index.js +0 -8
- package/node_modules/descope-avatar/src/theme.js +0 -44
- package/node_modules/descope-avatar/stories/avatar.jpeg +0 -0
- package/node_modules/descope-avatar/stories/descope-avatar.stories.js +0 -32
- package/node_modules/descope-combo-box/e2e/descope-combo-box.spec.ts +0 -462
- package/node_modules/descope-combo-box/package.json +0 -34
- package/node_modules/descope-combo-box/project.json +0 -7
- package/node_modules/descope-combo-box/src/component/ComboBoxClass.js +0 -619
- package/node_modules/descope-combo-box/src/component/index.js +0 -6
- package/node_modules/descope-combo-box/src/theme.js +0 -93
- package/node_modules/descope-combo-box/stories/descope-combo-box.stories.js +0 -180
- package/node_modules/descope-text/e2e/descope-text.spec.ts +0 -35
- package/node_modules/descope-text/package.json +0 -31
- package/node_modules/descope-text/project.json +0 -7
- package/node_modules/descope-text/src/component/TextClass.js +0 -63
- package/node_modules/descope-text/src/component/index.js +0 -5
- package/node_modules/descope-text/src/theme.js +0 -91
- package/node_modules/descope-text/stories/descope-text.stories.js +0 -55
- package/node_modules/theme-globals/package.json +0 -16
- package/node_modules/theme-globals/project.json +0 -7
- package/node_modules/theme-globals/src/index.js +0 -180
- package/node_modules/theme-input-wrapper/package.json +0 -17
- package/node_modules/theme-input-wrapper/project.json +0 -7
- package/node_modules/theme-input-wrapper/src/index.js +0 -130
- package/src/index.d.ts +0 -72
@@ -1,93 +0,0 @@
|
|
1
|
-
// since on load we can only sample the color of the placeholder,
|
2
|
-
// we need to temporarily populate the input in order to sample the value color
|
3
|
-
const getValueColor = (ele, computedStyle) => {
|
4
|
-
// to support setting dynamic values, we have to store the existing value
|
5
|
-
// and re-set it if we are returning from this hack
|
6
|
-
const origVal = ele.value;
|
7
|
-
|
8
|
-
// eslint-disable-next-line no-param-reassign
|
9
|
-
ele.value = '_';
|
10
|
-
|
11
|
-
const valueColor = computedStyle.getPropertyValue('color');
|
12
|
-
|
13
|
-
if (ele.value === '_') {
|
14
|
-
// eslint-disable-next-line no-param-reassign
|
15
|
-
ele.value = origVal;
|
16
|
-
}
|
17
|
-
|
18
|
-
return valueColor;
|
19
|
-
};
|
20
|
-
|
21
|
-
export const createExternalInputSlot = (slotName, targetSlotName) => {
|
22
|
-
const slotEle = document.createElement('slot');
|
23
|
-
|
24
|
-
slotEle.setAttribute('name', slotName);
|
25
|
-
slotEle.setAttribute('slot', targetSlotName);
|
26
|
-
|
27
|
-
return slotEle;
|
28
|
-
};
|
29
|
-
|
30
|
-
export const createExternalInputEle = (targetSlotName, type, autocompleteType, inputName) => {
|
31
|
-
const inputEle = document.createElement('input');
|
32
|
-
|
33
|
-
inputEle.setAttribute('slot', targetSlotName);
|
34
|
-
inputEle.setAttribute('type', type);
|
35
|
-
inputEle.setAttribute('name', inputName);
|
36
|
-
inputEle.setAttribute('data-hidden-input', 'true');
|
37
|
-
inputEle.setAttribute('autocomplete', autocompleteType);
|
38
|
-
|
39
|
-
return inputEle;
|
40
|
-
};
|
41
|
-
|
42
|
-
// We apply the original input's style to the external-input.
|
43
|
-
// Eventually, the user should interact directly with the external input.
|
44
|
-
// We keep the original input
|
45
|
-
export const applyExternalInputStyles = (sourceInputEle, targetInputEle, labelType) => {
|
46
|
-
// We set a timeout here to avoid "Double Print" cases,
|
47
|
-
// caused by sampling the computed style before it's ready.
|
48
|
-
setTimeout(() => {
|
49
|
-
const computedStyle = getComputedStyle(sourceInputEle);
|
50
|
-
// Get minimal set of computed theme properties to set on external input
|
51
|
-
const height = computedStyle.getPropertyValue('height');
|
52
|
-
const paddingLeft = computedStyle.getPropertyValue('padding-left');
|
53
|
-
const paddingRight = computedStyle.getPropertyValue('padding-right');
|
54
|
-
const fontSize = computedStyle.getPropertyValue('font-size');
|
55
|
-
const fontFamily = computedStyle.getPropertyValue('font-family');
|
56
|
-
const letterSpacing = computedStyle.getPropertyValue('letter-spacing');
|
57
|
-
const caretColor = computedStyle.getPropertyValue('caret-color');
|
58
|
-
|
59
|
-
const valueColor = getValueColor(sourceInputEle, computedStyle);
|
60
|
-
|
61
|
-
const commonThemeStyles = [
|
62
|
-
['all', 'unset'],
|
63
|
-
['position', 'absolute'],
|
64
|
-
['background-color', 'transparent'],
|
65
|
-
['height', height],
|
66
|
-
['left', paddingLeft],
|
67
|
-
['right', paddingRight],
|
68
|
-
['font-size', fontSize],
|
69
|
-
['font-family', fontFamily],
|
70
|
-
['letter-spacing', letterSpacing],
|
71
|
-
['caret-color', caretColor], // this is for seeing caret when focusing on external input
|
72
|
-
['color', valueColor],
|
73
|
-
];
|
74
|
-
|
75
|
-
commonThemeStyles.forEach(([key, val]) =>
|
76
|
-
targetInputEle.style.setProperty(key, val, 'important')
|
77
|
-
);
|
78
|
-
|
79
|
-
// Handle floating label theme properties
|
80
|
-
if (labelType === 'floating') {
|
81
|
-
const marginBottom = computedStyle.getPropertyValue('margin-bottom');
|
82
|
-
targetInputEle.style.setProperty('margin-bottom', marginBottom, 'important');
|
83
|
-
}
|
84
|
-
|
85
|
-
// sample and apply width only after original input is ready and fully rendered
|
86
|
-
const width = computedStyle.getPropertyValue('width');
|
87
|
-
targetInputEle.style.setProperty(
|
88
|
-
'width',
|
89
|
-
`calc(${width} - ${paddingLeft} - ${paddingRight}`,
|
90
|
-
'important'
|
91
|
-
);
|
92
|
-
}, 0);
|
93
|
-
};
|
@@ -1,170 +0,0 @@
|
|
1
|
-
import { syncAttrs } from '../../componentsHelpers';
|
2
|
-
import {
|
3
|
-
applyExternalInputStyles,
|
4
|
-
createExternalInputEle,
|
5
|
-
createExternalInputSlot,
|
6
|
-
} from './externalInputHelpers';
|
7
|
-
|
8
|
-
export const externalInputMixin =
|
9
|
-
({ inputType, inputName, autocompleteType, includeAttrs = [], noBlurDispatch = false }) =>
|
10
|
-
(superclass) =>
|
11
|
-
class ExternalInputMixinClass extends superclass {
|
12
|
-
#timers = [];
|
13
|
-
|
14
|
-
get isExternalInput() {
|
15
|
-
return this.getAttribute('external-input') === 'true';
|
16
|
-
}
|
17
|
-
|
18
|
-
createExternalInput() {
|
19
|
-
if (!this.isExternalInput || this.isReadOnly || this.isDisabled) {
|
20
|
-
return null;
|
21
|
-
}
|
22
|
-
|
23
|
-
// use original input element as reference
|
24
|
-
const origInput = this.baseElement.querySelector('input');
|
25
|
-
|
26
|
-
if (!origInput) {
|
27
|
-
return null;
|
28
|
-
}
|
29
|
-
|
30
|
-
// to avoid focus loop between external-input and origInput
|
31
|
-
// we set origInput's tabindex to -1
|
32
|
-
// otherwise, shift-tab will never leave the component focus
|
33
|
-
origInput.setAttribute('tabindex', '-1');
|
34
|
-
|
35
|
-
// create external slot
|
36
|
-
const externalInputSlot = createExternalInputSlot('external-input', 'suffix');
|
37
|
-
|
38
|
-
// append external slot to base element
|
39
|
-
this.baseElement.appendChild(externalInputSlot);
|
40
|
-
|
41
|
-
this.externalInput = createExternalInputEle(
|
42
|
-
'external-input',
|
43
|
-
inputType,
|
44
|
-
this.getAutocompleteType(),
|
45
|
-
inputName
|
46
|
-
);
|
47
|
-
|
48
|
-
// apply original input's styles to external input
|
49
|
-
setTimeout(() => {
|
50
|
-
applyExternalInputStyles(origInput, this.externalInput, this.getAttribute('label-type'));
|
51
|
-
});
|
52
|
-
|
53
|
-
// 1Password catches the internal input, so we forward the value to the external input
|
54
|
-
this.forwardInputValue(origInput, this.externalInput);
|
55
|
-
|
56
|
-
syncAttrs(origInput, this.externalInput, {
|
57
|
-
includeAttrs,
|
58
|
-
});
|
59
|
-
|
60
|
-
// We disable Vaadin's original `_setFocused` function, and use handleFocusEvents
|
61
|
-
// and handleBlurEvents functions
|
62
|
-
this.baseElement
|
63
|
-
.querySelector('input')
|
64
|
-
.addEventListener('focusout', (e) => e.stopImmediatePropagation(), true);
|
65
|
-
|
66
|
-
// In order to manage focus/blur events when moving between parts of the component
|
67
|
-
// we're managing the event dispatching by ourselves, with the following strategy:
|
68
|
-
// - If one of the component parts is focused - it means that the component is still focused - so we stop the blur events.
|
69
|
-
// - When none of the component parts is focused, we dispatch blur event.
|
70
|
-
this.handleFocusEvents();
|
71
|
-
this.handleBlurEvents();
|
72
|
-
|
73
|
-
// sync input value
|
74
|
-
this.handlelInputEvents(this.externalInput);
|
75
|
-
|
76
|
-
// append external input to component's DOM
|
77
|
-
this.appendChild(this.externalInput);
|
78
|
-
|
79
|
-
return this.externalInput;
|
80
|
-
}
|
81
|
-
|
82
|
-
clearBlurTimers() {
|
83
|
-
this.#timers.forEach((timer) => clearTimeout(timer));
|
84
|
-
this.#timers.length = 0;
|
85
|
-
}
|
86
|
-
|
87
|
-
dispatchBlur() {
|
88
|
-
return setTimeout(() => {
|
89
|
-
this.dispatchEvent(new Event('blur', { bubbles: true, composed: true }));
|
90
|
-
this.removeAttribute('focused');
|
91
|
-
});
|
92
|
-
}
|
93
|
-
|
94
|
-
handleFocusEvents() {
|
95
|
-
// on baseElement `focus` we forward the focus to the external input.
|
96
|
-
// also, in order to avoid any blur within the component, we clear the blur timers.
|
97
|
-
this.baseElement.addEventListener('focus', () => {
|
98
|
-
this.externalInput.focus();
|
99
|
-
this.clearBlurTimers();
|
100
|
-
});
|
101
|
-
|
102
|
-
// on `focus` of the external input, we manually set the `focused` attribute
|
103
|
-
this.externalInput.addEventListener('focus', () => {
|
104
|
-
this.clearBlurTimers();
|
105
|
-
setTimeout(() => this.baseElement.setAttribute('focused', 'true'));
|
106
|
-
});
|
107
|
-
}
|
108
|
-
|
109
|
-
handleBlurEvents() {
|
110
|
-
this.baseElement.addEventListener(
|
111
|
-
'blur',
|
112
|
-
(e) => {
|
113
|
-
e.stopImmediatePropagation();
|
114
|
-
// some components do not require this synthetic blur dispatch (e.g. Password)
|
115
|
-
// so we allow them to override this dispatch
|
116
|
-
if (noBlurDispatch) return;
|
117
|
-
this.#timers.push(this.dispatchBlur());
|
118
|
-
},
|
119
|
-
true
|
120
|
-
);
|
121
|
-
|
122
|
-
this.externalInput.addEventListener(
|
123
|
-
'blur',
|
124
|
-
(e) => {
|
125
|
-
e.stopImmediatePropagation();
|
126
|
-
this.#timers.push(this.dispatchBlur());
|
127
|
-
},
|
128
|
-
true
|
129
|
-
);
|
130
|
-
}
|
131
|
-
|
132
|
-
handlelInputEvents(externalInput) {
|
133
|
-
// sync value of insible input back to original input
|
134
|
-
externalInput.addEventListener('input', (e) => {
|
135
|
-
this.value = e.target.value;
|
136
|
-
});
|
137
|
-
|
138
|
-
// handle has-value attr
|
139
|
-
externalInput.addEventListener('input', (e) => {
|
140
|
-
if (!e.target.value) {
|
141
|
-
this.removeAttribute('has-value');
|
142
|
-
} else {
|
143
|
-
this.setAttribute('has-value', 'true');
|
144
|
-
}
|
145
|
-
});
|
146
|
-
}
|
147
|
-
|
148
|
-
getAutocompleteType() {
|
149
|
-
return this.getAttribute('autocomplete') || autocompleteType;
|
150
|
-
}
|
151
|
-
|
152
|
-
forwardInputValue(source, target) {
|
153
|
-
// set internal sync events
|
154
|
-
const valueDescriptor = Object.getOwnPropertyDescriptor(
|
155
|
-
this.inputElement.constructor.prototype,
|
156
|
-
'value'
|
157
|
-
);
|
158
|
-
|
159
|
-
Object.defineProperty(source, 'value', {
|
160
|
-
...valueDescriptor,
|
161
|
-
|
162
|
-
set(v) {
|
163
|
-
valueDescriptor.set.call(this, v);
|
164
|
-
// eslint-disable-next-line no-param-reassign
|
165
|
-
target.value = v;
|
166
|
-
},
|
167
|
-
configurable: true,
|
168
|
-
});
|
169
|
-
}
|
170
|
-
};
|
@@ -1,13 +0,0 @@
|
|
1
|
-
export const hoverableMixin = (superclass) =>
|
2
|
-
class HoverableMixinClass extends superclass {
|
3
|
-
init() {
|
4
|
-
super.init?.();
|
5
|
-
|
6
|
-
this.baseElement.addEventListener('mouseover', (e) => {
|
7
|
-
this.setAttribute('hover', 'true');
|
8
|
-
e.target.addEventListener('mouseleave', () => this.removeAttribute('hover'), {
|
9
|
-
once: true,
|
10
|
-
});
|
11
|
-
});
|
12
|
-
}
|
13
|
-
};
|
@@ -1,14 +0,0 @@
|
|
1
|
-
export { createStyleMixin } from './createStyleMixin';
|
2
|
-
export { draggableMixin } from './draggableMixin';
|
3
|
-
export { createProxy } from './createProxy';
|
4
|
-
export { proxyInputMixin } from './proxyInputMixin';
|
5
|
-
export { componentNameValidationMixin } from './componentNameValidationMixin';
|
6
|
-
export { hoverableMixin } from './hoverableMixin';
|
7
|
-
export { inputValidationMixin } from './inputValidationMixin';
|
8
|
-
export { portalMixin } from './portalMixin';
|
9
|
-
export { changeMixin } from './changeMixin';
|
10
|
-
export { normalizeBooleanAttributesMixin } from './normalizeBooleanAttributesMixin';
|
11
|
-
export { lifecycleEventsMixin } from './lifecycleEventsMixin';
|
12
|
-
export { inputEventsDispatchingMixin } from './inputEventsDispatchingMixin';
|
13
|
-
export { externalInputMixin } from './externalInputMixin';
|
14
|
-
export {componentsContextMixin} from './componentsContextMixin'
|
@@ -1,76 +0,0 @@
|
|
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
|
-
};
|
@@ -1,210 +0,0 @@
|
|
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
|
-
};
|
@@ -1,23 +0,0 @@
|
|
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
|
-
};
|
@@ -1,59 +0,0 @@
|
|
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
|
-
'loading',
|
24
|
-
'allow-custom-value',
|
25
|
-
];
|
26
|
-
|
27
|
-
const isBooleanAttribute = (attr) => {
|
28
|
-
return booleanAttributesList.includes(attr);
|
29
|
-
};
|
30
|
-
// we want all the valueless attributes to have "true" value
|
31
|
-
// and all the falsy attribute to be removed
|
32
|
-
export const normalizeBooleanAttributesMixin = (superclass) =>
|
33
|
-
class NormalizeBooleanAttributesMixinClass extends superclass {
|
34
|
-
init() {
|
35
|
-
super.init?.();
|
36
|
-
|
37
|
-
observeAttributes(
|
38
|
-
this,
|
39
|
-
(attrs) =>
|
40
|
-
attrs.forEach((attr) => {
|
41
|
-
const attrVal = this.getAttribute(attr);
|
42
|
-
|
43
|
-
if (isBooleanAttribute(attr)) {
|
44
|
-
if (attrVal === '') {
|
45
|
-
this.setAttribute(attr, 'true');
|
46
|
-
} else if (attrVal === 'false') {
|
47
|
-
this.removeAttribute(attr);
|
48
|
-
}
|
49
|
-
} else if (!attrVal) {
|
50
|
-
// eslint-disable-next-line no-console
|
51
|
-
console.debug(
|
52
|
-
`attribute "${attr}" has no value, should it be added to the boolean attributes list?`
|
53
|
-
);
|
54
|
-
}
|
55
|
-
}),
|
56
|
-
{}
|
57
|
-
);
|
58
|
-
}
|
59
|
-
};
|