@descope/web-components-ui 1.0.135 → 1.0.148
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +77 -56
- package/src/baseClasses/createBaseClass.js +18 -16
- package/src/baseClasses/createBaseInputClass.js +14 -8
- package/src/baseClasses/createCssVarImageClass.js +27 -23
- package/src/components/boolean-fields/booleanFieldMixin.js +18 -29
- package/src/components/boolean-fields/commonStyles.js +1 -1
- package/src/components/boolean-fields/descope-boolean-field-internal/BooleanFieldInternal.js +46 -51
- package/src/components/boolean-fields/descope-boolean-field-internal/index.js +1 -1
- package/src/components/boolean-fields/descope-checkbox/CheckboxClass.js +80 -85
- package/src/components/boolean-fields/descope-checkbox/index.js +2 -2
- package/src/components/boolean-fields/descope-switch-toggle/SwitchToggleClass.js +88 -95
- package/src/components/boolean-fields/descope-switch-toggle/index.js +2 -2
- package/src/components/descope-button/ButtonClass.js +57 -47
- package/src/components/descope-button/clickableMixin.js +10 -0
- package/src/components/descope-combo-box/ComboBoxClass.js +156 -160
- package/src/components/descope-container/ContainerClass.js +32 -42
- package/src/components/descope-date-picker/index.js +9 -14
- package/src/components/descope-divider/DividerClass.js +52 -62
- package/src/components/descope-email-field/EmailFieldClass.js +25 -20
- package/src/components/descope-image/ImageClass.js +21 -24
- package/src/components/descope-link/LinkClass.js +31 -35
- package/src/components/descope-loader-linear/LoaderLinearClass.js +31 -36
- package/src/components/descope-loader-radial/LoaderRadialClass.js +23 -30
- package/src/components/descope-logo/LogoClass.js +5 -1
- package/src/components/descope-new-password/NewPasswordClass.js +63 -81
- package/src/components/descope-new-password/descope-new-password-internal/NewPasswordInternal.js +157 -162
- package/src/components/descope-new-password/descope-new-password-internal/componentName.js +1 -1
- package/src/components/descope-new-password/descope-new-password-internal/index.js +3 -3
- package/src/components/descope-new-password/index.js +3 -3
- package/src/components/descope-number-field/NumberFieldClass.js +25 -20
- package/src/components/descope-passcode/PasscodeClass.js +95 -95
- package/src/components/descope-passcode/descope-passcode-internal/PasscodeInternal.js +151 -157
- package/src/components/descope-passcode/descope-passcode-internal/helpers.js +7 -8
- package/src/components/descope-passcode/descope-passcode-internal/index.js +2 -2
- package/src/components/descope-passcode/index.js +2 -2
- package/src/components/descope-password/PasswordClass.js +75 -83
- package/src/components/descope-password/passwordDraggableMixin.js +28 -27
- package/src/components/descope-phone-field/CountryCodes.js +1210 -1210
- package/src/components/descope-phone-field/PhoneFieldClass.js +139 -141
- package/src/components/descope-phone-field/descope-phone-field-internal/PhoneFieldInternal.js +157 -173
- package/src/components/descope-phone-field/helpers.js +3 -3
- package/src/components/descope-text/TextClass.js +25 -29
- package/src/components/descope-text-area/TextAreaClass.js +68 -67
- package/src/components/descope-text-field/TextFieldClass.js +42 -37
- package/src/components/descope-text-field/textFieldMappings.js +40 -55
- package/src/components/descope-totp-image/TotpImageClass.js +5 -1
- package/src/components/descope-upload-file/UploadFileClass.js +202 -0
- package/src/components/descope-upload-file/helpers.js +11 -0
- package/src/components/descope-upload-file/index.js +6 -0
- package/src/constants.js +3 -3
- package/src/helpers/componentHelpers.js +68 -74
- package/src/helpers/index.js +17 -16
- package/src/helpers/mixinsHelpers.js +21 -10
- package/src/helpers/themeHelpers/colorsHelpers.js +18 -18
- package/src/helpers/themeHelpers/componentsThemeManager.js +7 -6
- package/src/helpers/themeHelpers/index.js +114 -124
- package/src/helpers/themeHelpers/resetHelpers.js +16 -16
- package/src/index.cjs.js +3 -3
- package/src/index.d.ts +22 -21
- package/src/index.js +5 -4
- package/src/index.umd.js +14 -13
- package/src/mixins/changeMixin.js +18 -17
- package/src/mixins/componentNameValidationMixin.js +19 -19
- package/src/mixins/createProxy.js +33 -33
- package/src/mixins/createStyleMixin/helpers.js +54 -64
- package/src/mixins/createStyleMixin/index.js +155 -141
- package/src/mixins/draggableMixin.js +61 -61
- package/src/mixins/hoverableMixin.js +11 -13
- package/src/mixins/index.js +6 -6
- package/src/mixins/inputEventsDispatchingMixin.js +61 -60
- package/src/mixins/inputValidationMixin.js +153 -148
- package/src/mixins/lifecycleEventsMixin.js +17 -15
- package/src/mixins/normalizeBooleanAttributesMixin.js +31 -23
- package/src/mixins/portalMixin.js +58 -52
- package/src/mixins/proxyInputMixin.js +138 -132
- package/src/theme/components/button.js +86 -81
- package/src/theme/components/checkbox.js +26 -28
- package/src/theme/components/comboBox.js +32 -31
- package/src/theme/components/container.js +99 -89
- package/src/theme/components/divider.js +30 -31
- package/src/theme/components/emailField.js +20 -19
- package/src/theme/components/image.js +3 -3
- package/src/theme/components/index.js +33 -25
- package/src/theme/components/inputWrapper.js +28 -25
- package/src/theme/components/link.js +29 -36
- package/src/theme/components/loader/index.js +3 -3
- package/src/theme/components/loader/loaderLinear.js +34 -34
- package/src/theme/components/loader/loaderRadial.js +40 -34
- package/src/theme/components/logo.js +4 -4
- package/src/theme/components/newPassword.js +14 -13
- package/src/theme/components/numberField.js +20 -19
- package/src/theme/components/passcode.js +20 -22
- package/src/theme/components/password.js +22 -21
- package/src/theme/components/phoneField.js +23 -23
- package/src/theme/components/switchToggle.js +47 -46
- package/src/theme/components/text.js +72 -72
- package/src/theme/components/textArea.js +27 -25
- package/src/theme/components/textField.js +23 -22
- package/src/theme/components/totpImage.js +4 -4
- package/src/theme/components/uploadFile.js +60 -0
- package/src/theme/globals.js +123 -124
- package/src/theme/index.js +1 -1
- package/dist/cjs/index.cjs.js +0 -5924
- package/dist/cjs/index.cjs.js.map +0 -1
- package/dist/cjs/package.json +0 -1
- package/dist/index.d.ts +0 -51
- package/dist/index.esm.js +0 -6606
- package/dist/index.esm.js.map +0 -1
- package/dist/umd/1018.js +0 -577
- package/dist/umd/1018.js.LICENSE.txt +0 -23
- package/dist/umd/2481.js +0 -1
- package/dist/umd/3208.js +0 -2
- package/dist/umd/3208.js.LICENSE.txt +0 -5
- package/dist/umd/3585.js +0 -1
- package/dist/umd/3878.js +0 -1
- package/dist/umd/4201.js +0 -1
- package/dist/umd/422.js +0 -2
- package/dist/umd/422.js.LICENSE.txt +0 -5
- package/dist/umd/4447.js +0 -1
- package/dist/umd/4513.js +0 -1
- package/dist/umd/4803.js +0 -1
- package/dist/umd/541.js +0 -744
- package/dist/umd/541.js.LICENSE.txt +0 -21
- package/dist/umd/5767.js +0 -2
- package/dist/umd/5767.js.LICENSE.txt +0 -15
- package/dist/umd/5806.js +0 -109
- package/dist/umd/5806.js.LICENSE.txt +0 -5
- package/dist/umd/7056.js +0 -48
- package/dist/umd/7056.js.LICENSE.txt +0 -5
- package/dist/umd/7101.js +0 -148
- package/dist/umd/7101.js.LICENSE.txt +0 -11
- package/dist/umd/729.js +0 -1
- package/dist/umd/7824.js +0 -229
- package/dist/umd/7824.js.LICENSE.txt +0 -27
- package/dist/umd/7840.js +0 -356
- package/dist/umd/7840.js.LICENSE.txt +0 -61
- package/dist/umd/8725.js +0 -37
- package/dist/umd/8725.js.LICENSE.txt +0 -11
- package/dist/umd/9211.js +0 -312
- package/dist/umd/9211.js.LICENSE.txt +0 -5
- package/dist/umd/9241.js +0 -1
- package/dist/umd/9314.js +0 -283
- package/dist/umd/9314.js.LICENSE.txt +0 -27
- package/dist/umd/9437.js +0 -19
- package/dist/umd/9437.js.LICENSE.txt +0 -5
- package/dist/umd/9515.js +0 -202
- package/dist/umd/9515.js.LICENSE.txt +0 -11
- package/dist/umd/9789.js +0 -1
- package/dist/umd/boolean-fields-descope-boolean-field-internal-index-js.js +0 -1
- package/dist/umd/boolean-fields-descope-checkbox-index-js.js +0 -1
- package/dist/umd/boolean-fields-descope-switch-toggle-index-js.js +0 -1
- package/dist/umd/descope-button-index-js.js +0 -1
- package/dist/umd/descope-combo-box-index-js.js +0 -1
- package/dist/umd/descope-container-index-js.js +0 -1
- package/dist/umd/descope-date-picker-index-js.js +0 -1
- package/dist/umd/descope-divider-index-js.js +0 -1
- package/dist/umd/descope-email-field-index-js.js +0 -1
- package/dist/umd/descope-image-index-js.js +0 -1
- package/dist/umd/descope-link-index-js.js +0 -1
- package/dist/umd/descope-loader-linear-index-js.js +0 -1
- package/dist/umd/descope-loader-radial-index-js.js +0 -1
- package/dist/umd/descope-logo-index-js.js +0 -1
- package/dist/umd/descope-new-password-descope-new-password-internal-index-js.js +0 -1
- package/dist/umd/descope-new-password-index-js.js +0 -1
- package/dist/umd/descope-number-field-index-js.js +0 -1
- package/dist/umd/descope-passcode-descope-passcode-internal-index-js.js +0 -1
- package/dist/umd/descope-passcode-index-js.js +0 -1
- package/dist/umd/descope-password-index-js.js +0 -1
- package/dist/umd/descope-phone-field-descope-phone-field-internal-index-js.js +0 -1
- package/dist/umd/descope-phone-field-index-js.js +0 -1
- package/dist/umd/descope-text-area-index-js.js +0 -1
- package/dist/umd/descope-text-field-index-js.js +0 -1
- package/dist/umd/descope-text-index-js.js +0 -1
- package/dist/umd/descope-totp-image-index-js.js +0 -1
- package/dist/umd/index.js +0 -1
@@ -1,61 +1,66 @@
|
|
1
1
|
import {
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
2
|
+
createStyleMixin,
|
3
|
+
draggableMixin,
|
4
|
+
createProxy,
|
5
|
+
proxyInputMixin,
|
6
|
+
componentNameValidationMixin,
|
7
7
|
} from '../../mixins';
|
8
8
|
import textFieldMappings from './textFieldMappings';
|
9
9
|
import { compose } from '../../helpers';
|
10
10
|
import { getComponentName } from '../../helpers/componentHelpers';
|
11
|
-
import {
|
11
|
+
import {
|
12
|
+
resetInputOverrides,
|
13
|
+
useHostExternalPadding,
|
14
|
+
} from '../../helpers/themeHelpers/resetHelpers';
|
12
15
|
|
13
16
|
export const componentName = getComponentName('text-field');
|
14
17
|
|
15
18
|
const observedAttrs = ['type'];
|
16
19
|
|
17
20
|
const customMixin = (superclass) =>
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
21
|
+
class TextFieldClass extends superclass {
|
22
|
+
static get observedAttributes() {
|
23
|
+
return observedAttrs.concat(superclass.observedAttributes || []);
|
24
|
+
}
|
22
25
|
|
23
|
-
|
24
|
-
|
26
|
+
attributeChangedCallback(attrName, oldVal, newVal) {
|
27
|
+
super.attributeChangeCallback?.(attrName, oldVal, newVal);
|
25
28
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
29
|
+
// Vaadin doesn't allow to change the input type attribute.
|
30
|
+
// We need the ability to do that, so we're overriding their
|
31
|
+
// behavior with their private API.
|
32
|
+
// When receiving a `type` attribute, we use their private API
|
33
|
+
// to set it on the input.
|
34
|
+
if (attrName === 'type') {
|
35
|
+
this.baseElement._setType(newVal);
|
36
|
+
}
|
37
|
+
}
|
38
|
+
};
|
36
39
|
|
37
40
|
export const TextFieldClass = compose(
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
41
|
+
createStyleMixin({
|
42
|
+
mappings: textFieldMappings,
|
43
|
+
}),
|
44
|
+
draggableMixin,
|
45
|
+
proxyInputMixin,
|
46
|
+
componentNameValidationMixin,
|
47
|
+
customMixin
|
45
48
|
)(
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
49
|
+
createProxy({
|
50
|
+
slots: ['prefix', 'suffix'],
|
51
|
+
wrappedEleName: 'vaadin-text-field',
|
52
|
+
style: () => `
|
50
53
|
:host {
|
51
54
|
display: inline-block;
|
52
55
|
max-width: 100%;
|
53
|
-
padding: calc(var(${TextFieldClass.cssVarList.inputOutlineWidth}) + var(${
|
56
|
+
padding: calc(var(${TextFieldClass.cssVarList.inputOutlineWidth}) + var(${
|
57
|
+
TextFieldClass.cssVarList.inputOutlineOffset
|
58
|
+
}));
|
54
59
|
}
|
55
60
|
${useHostExternalPadding(TextFieldClass.cssVarList)}
|
56
61
|
${resetInputOverrides('vaadin-text-field', TextFieldClass.cssVarList)}
|
57
62
|
`,
|
58
|
-
|
59
|
-
|
60
|
-
|
63
|
+
excludeAttrsSync: ['tabindex'],
|
64
|
+
componentName,
|
65
|
+
})
|
61
66
|
);
|
@@ -1,68 +1,53 @@
|
|
1
|
-
const {
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
label: { selector: '::part(label)' },
|
13
|
-
requiredIndicator: { selector: '[required]::part(required-indicator)::after' },
|
14
|
-
placeholder: { selector: '> input:placeholder-shown' },
|
15
|
-
inputField: { selector: '::part(input-field)' },
|
16
|
-
input: { selector: 'input' },
|
17
|
-
helperText: { selector: '::part(helper-text)' },
|
18
|
-
errorMessage: { selector: '::part(error-message)' }
|
19
|
-
};
|
1
|
+
const { host, label, placeholder, requiredIndicator, inputField, input, helperText, errorMessage } =
|
2
|
+
{
|
3
|
+
host: { selector: () => ':host' },
|
4
|
+
label: { selector: '::part(label)' },
|
5
|
+
requiredIndicator: { selector: '[required]::part(required-indicator)::after' },
|
6
|
+
placeholder: { selector: '> input:placeholder-shown' },
|
7
|
+
inputField: { selector: '::part(input-field)' },
|
8
|
+
input: { selector: 'input' },
|
9
|
+
helperText: { selector: '::part(helper-text)' },
|
10
|
+
errorMessage: { selector: '::part(error-message)' },
|
11
|
+
};
|
20
12
|
|
21
13
|
export default {
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
host,
|
26
|
-
],
|
27
|
-
fontFamily: [
|
28
|
-
label,
|
29
|
-
inputField,
|
30
|
-
helperText,
|
31
|
-
errorMessage,
|
32
|
-
],
|
14
|
+
// we apply font-size also on the host so we can set its width with em
|
15
|
+
fontSize: [{}, host],
|
16
|
+
fontFamily: [label, inputField, helperText, errorMessage],
|
33
17
|
|
34
|
-
|
35
|
-
|
18
|
+
hostWidth: { ...host, property: 'width' },
|
19
|
+
hostMinWidth: { ...host, property: 'min-width' },
|
36
20
|
|
37
|
-
|
21
|
+
inputBackgroundColor: { ...inputField, property: 'background-color' },
|
38
22
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
23
|
+
labelTextColor: [
|
24
|
+
{ ...label, property: 'color' },
|
25
|
+
{ ...requiredIndicator, property: 'color' },
|
26
|
+
],
|
27
|
+
errorMessageTextColor: { ...errorMessage, property: 'color' },
|
43
28
|
|
44
|
-
|
45
|
-
|
29
|
+
inputValueTextColor: { ...inputField, property: 'color' },
|
30
|
+
inputCaretTextColor: { ...input, property: 'color' },
|
46
31
|
|
47
|
-
|
32
|
+
labelRequiredIndicator: { ...requiredIndicator, property: 'content' },
|
48
33
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
34
|
+
inputBorderColor: { ...inputField, property: 'border-color' },
|
35
|
+
inputBorderWidth: { ...inputField, property: 'border-width' },
|
36
|
+
inputBorderStyle: { ...inputField, property: 'border-style' },
|
37
|
+
inputBorderRadius: { ...inputField, property: 'border-radius' },
|
53
38
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
39
|
+
inputHeight: { ...inputField, property: 'height' },
|
40
|
+
inputHorizontalPadding: [
|
41
|
+
{ ...input, property: 'padding-left' },
|
42
|
+
{ ...input, property: 'padding-right' },
|
43
|
+
],
|
59
44
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
45
|
+
inputOutlineColor: { ...inputField, property: 'outline-color' },
|
46
|
+
inputOutlineStyle: { ...inputField, property: 'outline-style' },
|
47
|
+
inputOutlineWidth: { ...inputField, property: 'outline-width' },
|
48
|
+
inputOutlineOffset: { ...inputField, property: 'outline-offset' },
|
64
49
|
|
65
|
-
|
50
|
+
inputTextAlign: { ...input, property: 'text-align' },
|
66
51
|
|
67
|
-
|
52
|
+
inputPlaceholderColor: { ...placeholder, property: 'color' },
|
68
53
|
};
|
@@ -3,4 +3,8 @@ import { createCssVarImageClass } from '../../baseClasses/createCssVarImageClass
|
|
3
3
|
|
4
4
|
export const componentName = getComponentName('totp-image');
|
5
5
|
|
6
|
-
export const TotpImageClass = createCssVarImageClass({
|
6
|
+
export const TotpImageClass = createCssVarImageClass({
|
7
|
+
componentName,
|
8
|
+
varName: 'url',
|
9
|
+
fallbackVarName: 'fallbackUrl',
|
10
|
+
});
|
@@ -0,0 +1,202 @@
|
|
1
|
+
import { createStyleMixin, draggableMixin, componentNameValidationMixin } from '../../mixins';
|
2
|
+
import { compose } from '../../helpers';
|
3
|
+
import { getComponentName } from '../../helpers/componentHelpers';
|
4
|
+
import { createBaseInputClass } from '../../baseClasses/createBaseInputClass';
|
5
|
+
import { getFileBase64, getFilename } from './helpers';
|
6
|
+
|
7
|
+
export const componentName = getComponentName('upload-file');
|
8
|
+
|
9
|
+
const observedAttributes = [
|
10
|
+
'title',
|
11
|
+
'description',
|
12
|
+
'button-label',
|
13
|
+
'accept',
|
14
|
+
'button-mode',
|
15
|
+
'button-variant',
|
16
|
+
'required',
|
17
|
+
'size',
|
18
|
+
];
|
19
|
+
|
20
|
+
const BaseInputClass = createBaseInputClass({ componentName, baseSelector: ':host > div.wrapper' });
|
21
|
+
|
22
|
+
class RawUploadFile extends BaseInputClass {
|
23
|
+
static get observedAttributes() {
|
24
|
+
return observedAttributes.concat(BaseInputClass.observedAttributes || []);
|
25
|
+
}
|
26
|
+
|
27
|
+
constructor() {
|
28
|
+
super();
|
29
|
+
|
30
|
+
this.attachShadow({ mode: 'open' }).innerHTML = `
|
31
|
+
<style>
|
32
|
+
.wrapper {
|
33
|
+
display: flex;
|
34
|
+
align-items: center;
|
35
|
+
justify-content: center;
|
36
|
+
text-align: center;
|
37
|
+
flex-direction: column;
|
38
|
+
}
|
39
|
+
.button-wrapper {
|
40
|
+
position: relative;
|
41
|
+
width: fit-content;
|
42
|
+
}
|
43
|
+
input {
|
44
|
+
position: absolute;
|
45
|
+
width: 100%;
|
46
|
+
height: 100%;
|
47
|
+
opacity: 0;
|
48
|
+
}
|
49
|
+
</style>
|
50
|
+
<div class="wrapper">
|
51
|
+
<div class="icon"></div>
|
52
|
+
<div class="title">
|
53
|
+
<span class="title-text"></span>
|
54
|
+
<span class="required-indicator"></span>
|
55
|
+
</div>
|
56
|
+
<div class="description"></div>
|
57
|
+
<div class="button-wrapper">
|
58
|
+
<input type="file" tabindex="-1" />
|
59
|
+
<descope-button></descope-button>
|
60
|
+
</div>
|
61
|
+
</div>
|
62
|
+
`;
|
63
|
+
|
64
|
+
this.wrapperEle = this.shadowRoot.querySelector('.wrapper');
|
65
|
+
this.inputElement = this.shadowRoot.querySelector('input');
|
66
|
+
|
67
|
+
this.button.onclick = () => this.inputElement.click();
|
68
|
+
|
69
|
+
this.inputElement.onchange = async (e) => {
|
70
|
+
const receivedFileList = e.target.files;
|
71
|
+
|
72
|
+
if (!receivedFileList.length) {
|
73
|
+
return;
|
74
|
+
}
|
75
|
+
|
76
|
+
this.value = await getFileBase64(receivedFileList[0]);
|
77
|
+
|
78
|
+
this.updateDescription(getFilename(receivedFileList[0]));
|
79
|
+
};
|
80
|
+
|
81
|
+
this.oninvalid = () => {
|
82
|
+
this.setAttribute('invalid', 'true');
|
83
|
+
};
|
84
|
+
}
|
85
|
+
|
86
|
+
getValidity() {
|
87
|
+
if (this.isRequired && !this.value) {
|
88
|
+
return { valueMissing: true };
|
89
|
+
}
|
90
|
+
return {};
|
91
|
+
}
|
92
|
+
|
93
|
+
initInputs() {
|
94
|
+
const button = this.rootElement.querySelector('descope-button');
|
95
|
+
button.onclick = () => this.inputElement.click();
|
96
|
+
}
|
97
|
+
|
98
|
+
attributeChangedCallback(attrName, oldValue, newValue) {
|
99
|
+
super.attributeChangedCallback?.(attrName, oldValue, newValue);
|
100
|
+
|
101
|
+
if (oldValue !== newValue) {
|
102
|
+
if (attrName === 'title') {
|
103
|
+
this.updateTitle(newValue);
|
104
|
+
} else if (attrName === 'description') {
|
105
|
+
this.updateDescription(newValue);
|
106
|
+
} else if (attrName === 'button-label') {
|
107
|
+
this.updateButtonLabel(newValue);
|
108
|
+
} else if (attrName === 'button-mode') {
|
109
|
+
this.updateButtonMode(newValue);
|
110
|
+
} else if (attrName === 'button-variant') {
|
111
|
+
this.updateButtonVariant(newValue);
|
112
|
+
} else if (attrName === 'size') {
|
113
|
+
this.updateButtonSize(newValue);
|
114
|
+
} else if (attrName === 'accept') {
|
115
|
+
this.updateInputAccept(newValue);
|
116
|
+
}
|
117
|
+
}
|
118
|
+
}
|
119
|
+
|
120
|
+
get button() {
|
121
|
+
return this.shadowRoot.querySelector('descope-button');
|
122
|
+
}
|
123
|
+
|
124
|
+
get input() {
|
125
|
+
return this.shadowRoot.querySelector('input');
|
126
|
+
}
|
127
|
+
|
128
|
+
get title() {
|
129
|
+
return this.shadowRoot.querySelector('.title-text');
|
130
|
+
}
|
131
|
+
|
132
|
+
get description() {
|
133
|
+
return this.shadowRoot.querySelector('.description');
|
134
|
+
}
|
135
|
+
|
136
|
+
updateTitle(val) {
|
137
|
+
this.title.innerHTML = val;
|
138
|
+
}
|
139
|
+
|
140
|
+
updateDescription(val) {
|
141
|
+
this.description.innerHTML = val;
|
142
|
+
}
|
143
|
+
|
144
|
+
updateButtonLabel(val) {
|
145
|
+
this.button.innerHTML = val;
|
146
|
+
}
|
147
|
+
|
148
|
+
updateButtonSize(val) {
|
149
|
+
this.button.setAttribute('size', val);
|
150
|
+
}
|
151
|
+
|
152
|
+
updateButtonMode(val) {
|
153
|
+
this.button.setAttribute('mode', val);
|
154
|
+
}
|
155
|
+
|
156
|
+
updateButtonVariant(val) {
|
157
|
+
this.button.setAttribute('variant', val);
|
158
|
+
}
|
159
|
+
|
160
|
+
updateInputAccept(val) {
|
161
|
+
this.input.setAttribute('accept', val);
|
162
|
+
}
|
163
|
+
}
|
164
|
+
|
165
|
+
const { host, icon, title, description, requiredIndicator } = {
|
166
|
+
host: { selector: () => '.wrapper' },
|
167
|
+
icon: { selector: () => '.icon' },
|
168
|
+
title: { selector: () => '.title' },
|
169
|
+
description: { selector: () => '.description' },
|
170
|
+
requiredIndicator: { selector: () => '.title::after' },
|
171
|
+
};
|
172
|
+
|
173
|
+
export const UploadFileClass = compose(
|
174
|
+
createStyleMixin({ componentNameOverride: getComponentName('input-wrapper') }),
|
175
|
+
createStyleMixin({
|
176
|
+
mappings: {
|
177
|
+
fontSize: {},
|
178
|
+
fontFamily: {},
|
179
|
+
hostWidth: { ...host, property: 'width' },
|
180
|
+
hostHeight: { ...host, property: 'height' },
|
181
|
+
hostPadding: { ...host, property: 'padding' },
|
182
|
+
gap: { ...host },
|
183
|
+
lineHeight: { ...host, property: 'line-height' },
|
184
|
+
borderColor: { ...host, property: 'border-color' },
|
185
|
+
borderWidth: { ...host, property: 'border-width' },
|
186
|
+
borderStyle: { ...host, property: 'border-style' },
|
187
|
+
borderRadius: { ...host, property: 'border-radius' },
|
188
|
+
titleFontSize: { ...title, property: 'font-size' },
|
189
|
+
titleFontWeight: { ...title, property: 'font-weight' },
|
190
|
+
descriptionFontSize: { ...description, property: 'font-size' },
|
191
|
+
labelTextColor: [
|
192
|
+
{ ...title, property: 'color' },
|
193
|
+
{ ...description, property: 'color' },
|
194
|
+
],
|
195
|
+
icon: { ...icon, property: 'content' },
|
196
|
+
iconSize: { ...icon, property: 'width' },
|
197
|
+
requiredIndicator: { ...requiredIndicator, property: 'content' },
|
198
|
+
},
|
199
|
+
}),
|
200
|
+
draggableMixin,
|
201
|
+
componentNameValidationMixin
|
202
|
+
)(RawUploadFile);
|
@@ -0,0 +1,11 @@
|
|
1
|
+
export const getFileBase64 = (fileObj) => {
|
2
|
+
return new Promise((resolve) => {
|
3
|
+
const reader = new FileReader();
|
4
|
+
reader.onload = (e) => resolve(e.target.result);
|
5
|
+
reader.readAsDataURL(fileObj);
|
6
|
+
});
|
7
|
+
};
|
8
|
+
|
9
|
+
export const getFilename = (fileObj) => {
|
10
|
+
return fileObj.name.replace(/^.*\\/, '');
|
11
|
+
};
|
package/src/constants.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
1
|
export const DESCOPE_PREFIX = 'descope';
|
2
|
-
export const CSS_SELECTOR_SPECIFIER_MULTIPLY = 3
|
3
|
-
export const BASE_THEME_SECTION = 'host'
|
4
|
-
export const PORTAL_THEME_PREFIX = '@'
|
2
|
+
export const CSS_SELECTOR_SPECIFIER_MULTIPLY = 3;
|
3
|
+
export const BASE_THEME_SECTION = 'host';
|
4
|
+
export const PORTAL_THEME_PREFIX = '@';
|
@@ -1,101 +1,95 @@
|
|
1
1
|
import { kebabCaseJoin } from '.';
|
2
2
|
import { DESCOPE_PREFIX } from '../constants';
|
3
3
|
|
4
|
-
export const observeAttributes = (
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
) =>
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
(!includeAttrs.length || includeAttrs.includes(attr.name))
|
14
|
-
)
|
15
|
-
.map((attr) => attr.name)
|
4
|
+
export const observeAttributes = (ele, callback, { excludeAttrs = [], includeAttrs = [] }) => {
|
5
|
+
// sync all attrs on init
|
6
|
+
const filteredAttrs = Array.from(ele.attributes)
|
7
|
+
.filter(
|
8
|
+
(attr) =>
|
9
|
+
!excludeAttrs.includes(attr.name) &&
|
10
|
+
(!includeAttrs.length || includeAttrs.includes(attr.name))
|
11
|
+
)
|
12
|
+
.map((attr) => attr.name);
|
16
13
|
|
17
|
-
|
14
|
+
callback(filteredAttrs);
|
18
15
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
16
|
+
const observer = new MutationObserver((mutationsList) => {
|
17
|
+
mutationsList.forEach((mutation) => {
|
18
|
+
if (
|
19
|
+
mutation.type === 'attributes' &&
|
20
|
+
!excludeAttrs.includes(mutation.attributeName) &&
|
21
|
+
(!includeAttrs.length || includeAttrs.includes(mutation.attributeName))
|
22
|
+
) {
|
23
|
+
callback([mutation.attributeName]);
|
24
|
+
}
|
25
|
+
});
|
26
|
+
});
|
30
27
|
|
31
|
-
|
28
|
+
observer.observe(ele, { attributes: true });
|
32
29
|
};
|
33
30
|
|
34
31
|
// calling the callback with this object: { addedNodes, removedNodes }
|
35
|
-
export const observeChildren = (
|
36
|
-
|
37
|
-
callback,
|
38
|
-
) => {
|
39
|
-
callback({ addedNodes: Array.from(ele.children), removedNodes: [] });
|
32
|
+
export const observeChildren = (ele, callback) => {
|
33
|
+
callback({ addedNodes: Array.from(ele.children), removedNodes: [] });
|
40
34
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
35
|
+
const observer = new MutationObserver((mutationsList) => {
|
36
|
+
mutationsList.forEach((mutation) => {
|
37
|
+
if (mutation.type === 'childList') {
|
38
|
+
callback(mutation);
|
39
|
+
}
|
40
|
+
});
|
41
|
+
});
|
48
42
|
|
49
|
-
|
43
|
+
observer.observe(ele, { childList: true });
|
50
44
|
};
|
51
45
|
|
52
46
|
const createSyncAttrsCb =
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
47
|
+
(srcEle, targetEle, mapAttrs = {}) =>
|
48
|
+
(attrNames) => {
|
49
|
+
attrNames.forEach((attrName) => {
|
50
|
+
const targetAttrName = mapAttrs[attrName] || attrName;
|
51
|
+
const srcAttrVal = srcEle.getAttribute(attrName);
|
52
|
+
if (srcAttrVal !== null) {
|
53
|
+
if (targetEle.getAttribute(targetAttrName) !== srcAttrVal) {
|
54
|
+
targetEle.setAttribute(targetAttrName, srcAttrVal);
|
55
|
+
}
|
56
|
+
} else {
|
57
|
+
targetEle.removeAttribute(targetAttrName);
|
58
|
+
}
|
59
|
+
});
|
60
|
+
};
|
67
61
|
|
68
62
|
export const syncAttrs = (ele1, ele2, options) => {
|
69
|
-
|
70
|
-
|
63
|
+
observeAttributes(ele1, createSyncAttrsCb(ele1, ele2), options);
|
64
|
+
observeAttributes(ele2, createSyncAttrsCb(ele2, ele1), options);
|
71
65
|
};
|
72
66
|
|
73
67
|
export const getComponentName = (name) => kebabCaseJoin(DESCOPE_PREFIX, name);
|
74
68
|
|
75
|
-
export const getCssVarName = (...args) =>
|
76
|
-
`--${kebabCaseJoin(...args)}`;
|
69
|
+
export const getCssVarName = (...args) => `--${kebabCaseJoin(...args)}`;
|
77
70
|
|
78
71
|
export const forwardAttrs = (source, dest, options = {}) => {
|
79
|
-
|
80
|
-
source,
|
81
|
-
createSyncAttrsCb(source, dest, options.mapAttrs),
|
82
|
-
options
|
83
|
-
);
|
72
|
+
observeAttributes(source, createSyncAttrsCb(source, dest, options.mapAttrs), options);
|
84
73
|
};
|
85
74
|
|
86
75
|
export const forwardProps = (src, target, props = []) => {
|
87
|
-
|
76
|
+
if (!props.length) return;
|
88
77
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
78
|
+
const config = props.reduce(
|
79
|
+
(acc, prop) =>
|
80
|
+
Object.assign(acc, {
|
81
|
+
[prop]: {
|
82
|
+
get() {
|
83
|
+
return src[prop];
|
84
|
+
},
|
85
|
+
set(v) {
|
86
|
+
// eslint-disable-next-line no-param-reassign
|
87
|
+
src[prop] = v;
|
88
|
+
},
|
89
|
+
},
|
90
|
+
}),
|
91
|
+
{}
|
92
|
+
);
|
99
93
|
|
100
|
-
|
101
|
-
}
|
94
|
+
Object.defineProperties(target, config);
|
95
|
+
};
|
package/src/helpers/index.js
CHANGED
@@ -1,26 +1,27 @@
|
|
1
|
-
|
2
1
|
export const kebabCase = (str) =>
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
2
|
+
str
|
3
|
+
.replace(/([a-z])([A-Z])/g, '$1-$2')
|
4
|
+
.replace(/[\s_.]+/g, '-')
|
5
|
+
.toLowerCase();
|
7
6
|
|
8
7
|
export const kebabCaseJoin = (...args) => kebabCase(args.filter((arg) => !!arg).join('-'));
|
9
8
|
|
10
|
-
export const compose =
|
11
|
-
|
12
|
-
|
9
|
+
export const compose =
|
10
|
+
(...fns) =>
|
11
|
+
(val) =>
|
12
|
+
fns.reduceRight((res, fn) => fn(res), val);
|
13
13
|
|
14
|
-
export const upperFirst = (str) => str.charAt(0).toUpperCase() + str.slice(1)
|
14
|
+
export const upperFirst = (str) => str.charAt(0).toUpperCase() + str.slice(1);
|
15
15
|
|
16
16
|
export const isFunction = (maybeFunc) => typeof maybeFunc === 'function';
|
17
17
|
|
18
18
|
export const isUrl = (maybeUrl) => {
|
19
|
-
|
20
|
-
|
19
|
+
try {
|
20
|
+
// eslint-disable-next-line no-new
|
21
|
+
new URL(maybeUrl);
|
21
22
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
}
|
23
|
+
return true;
|
24
|
+
} catch (e) {
|
25
|
+
return false;
|
26
|
+
}
|
27
|
+
};
|