@descope/web-components-ui 1.0.40 → 1.0.42
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/cjs/index.cjs.js +35 -18
- package/dist/cjs/index.cjs.js.map +1 -1
- package/dist/index.esm.js +416 -343
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/descope-button/index.js +3 -3
- package/src/components/descope-checkbox/index.js +2 -2
- package/src/components/descope-combo/index.js +12 -12
- package/src/components/descope-container/Container.js +57 -51
- package/src/components/descope-container/index.js +1 -1
- package/src/components/descope-date-picker/index.js +13 -7
- package/src/components/descope-email-field/index.js +2 -2
- package/src/components/descope-number-field/index.js +2 -2
- package/src/components/descope-password-field/index.js +2 -2
- package/src/components/descope-switch-toggle/index.js +2 -2
- package/src/components/descope-text-area/index.js +2 -2
- package/src/components/descope-text-field/index.js +3 -3
- package/src/componentsHelpers/componentNameValidationMixin.js +21 -17
- package/src/componentsHelpers/createProxy/helpers.js +31 -27
- package/src/componentsHelpers/createStyleMixin/helpers.js +65 -47
- package/src/componentsHelpers/createStyleMixin/index.js +76 -55
- package/src/componentsHelpers/draggableMixin.js +25 -26
- package/src/constants.js +1 -1
- package/src/dev/index.js +4 -3
- package/src/helpers.js +8 -6
- package/src/index.cjs.js +1 -1
- package/src/index.js +13 -13
- package/src/index.umd.js +11 -5
- package/src/theme/components/button.js +37 -37
- package/src/theme/components/container.js +10 -12
- package/src/theme/components/textArea.js +3 -3
- package/src/theme/components/textField.js +1 -1
- package/src/theme/globals.js +44 -36
- package/src/theme/index.js +2 -2
- package/src/themeHelpers/index.js +45 -30
- package/src/themeHelpers/processColors.js +10 -7
@@ -1,57 +1,63 @@
|
|
1
|
-
import {
|
1
|
+
import {
|
2
|
+
getComponentName,
|
3
|
+
createStyleMixin,
|
4
|
+
draggableMixin,
|
5
|
+
compose,
|
6
|
+
componentNameValidationMixin
|
7
|
+
} from '../../componentsHelpers';
|
2
8
|
|
3
|
-
export const componentName = getComponentName(
|
9
|
+
export const componentName = getComponentName('container');
|
4
10
|
|
5
11
|
class RawContainer extends HTMLElement {
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
12
|
+
static get componentName() {
|
13
|
+
return componentName;
|
14
|
+
}
|
15
|
+
constructor() {
|
16
|
+
super();
|
17
|
+
const template = document.createElement('template');
|
18
|
+
template.innerHTML = `<slot></slot>`;
|
19
|
+
|
20
|
+
this.attachShadow({ mode: 'open' });
|
21
|
+
this.shadowRoot.appendChild(template.content.cloneNode(true));
|
22
|
+
|
23
|
+
this.baseSelector = ':host > slot';
|
24
|
+
}
|
19
25
|
}
|
20
26
|
|
21
27
|
const Container = compose(
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
)(RawContainer)
|
56
|
-
|
57
|
-
export default Container
|
28
|
+
createStyleMixin({
|
29
|
+
// todo: do we want to change the mapping structure to this? ['aa', 'aaa', {'color': [{ selector: '::part(label)' }]}],
|
30
|
+
mappings: {
|
31
|
+
height: {},
|
32
|
+
width: {},
|
33
|
+
|
34
|
+
verticalPadding: [
|
35
|
+
{ property: 'padding-top' },
|
36
|
+
{ property: 'padding-bottom' }
|
37
|
+
],
|
38
|
+
horizontalPadding: [
|
39
|
+
{ property: 'padding-left' },
|
40
|
+
{ property: 'padding-right' }
|
41
|
+
],
|
42
|
+
|
43
|
+
display: {},
|
44
|
+
flexDirection: {},
|
45
|
+
justifyContent: {},
|
46
|
+
alignItems: {},
|
47
|
+
gap: {},
|
48
|
+
|
49
|
+
backgroundColor: {},
|
50
|
+
borderRadius: {},
|
51
|
+
|
52
|
+
borderColor: {},
|
53
|
+
borderStyle: {},
|
54
|
+
borderWidth: {},
|
55
|
+
|
56
|
+
boxShadow: {}
|
57
|
+
}
|
58
|
+
}),
|
59
|
+
draggableMixin,
|
60
|
+
componentNameValidationMixin
|
61
|
+
)(RawContainer);
|
62
|
+
|
63
|
+
export default Container;
|
@@ -1,7 +1,13 @@
|
|
1
|
-
import
|
2
|
-
import {
|
1
|
+
import '@vaadin/date-picker';
|
2
|
+
import {
|
3
|
+
getComponentName,
|
4
|
+
draggableMixin,
|
5
|
+
createProxy,
|
6
|
+
compose,
|
7
|
+
componentNameValidationMixin
|
8
|
+
} from '../../componentsHelpers';
|
3
9
|
|
4
|
-
const componentName = getComponentName(
|
10
|
+
const componentName = getComponentName('date-picker');
|
5
11
|
|
6
12
|
const DatePicker = compose(
|
7
13
|
draggableMixin,
|
@@ -9,12 +15,12 @@ const DatePicker = compose(
|
|
9
15
|
)(
|
10
16
|
createProxy({
|
11
17
|
componentName,
|
12
|
-
slots: [
|
13
|
-
wrappedEleName:
|
14
|
-
style:
|
18
|
+
slots: ['prefix', 'suffix'],
|
19
|
+
wrappedEleName: 'vaadin-date-picker',
|
20
|
+
style: ``
|
15
21
|
})
|
16
22
|
);
|
17
23
|
|
18
24
|
customElements.define(componentName, DatePicker);
|
19
25
|
|
20
|
-
export { DatePicker }
|
26
|
+
export { DatePicker };
|
@@ -1,6 +1,6 @@
|
|
1
|
-
import
|
2
|
-
import TextField, { componentName } from
|
1
|
+
import '@vaadin/text-field';
|
2
|
+
import TextField, { componentName } from './TextField';
|
3
3
|
|
4
4
|
customElements.define(componentName, TextField);
|
5
5
|
|
6
|
-
export { TextField }
|
6
|
+
export { TextField };
|
@@ -1,21 +1,25 @@
|
|
1
1
|
export const componentNameValidationMixin = (superclass) =>
|
2
|
-
|
3
|
-
|
4
|
-
|
2
|
+
class DraggableMixinClass extends superclass {
|
3
|
+
#checkComponentName() {
|
4
|
+
const currentComponentName = this.shadowRoot.host.tagName.toLowerCase();
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
if (!superclass.componentName) {
|
7
|
+
throw Error(
|
8
|
+
`component name is not defined on super class, make sure you have a static get for "componentName"`
|
9
|
+
);
|
10
|
+
}
|
9
11
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
12
|
+
if (currentComponentName !== superclass.componentName) {
|
13
|
+
throw Error(
|
14
|
+
`component name mismatch, expected "${superclass.componentName}", current "${currentComponentName}"`
|
15
|
+
);
|
16
|
+
}
|
17
|
+
}
|
14
18
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
19
|
+
connectedCallback() {
|
20
|
+
super.connectedCallback?.();
|
21
|
+
if (this.shadowRoot.isConnected) {
|
22
|
+
this.#checkComponentName();
|
23
|
+
}
|
24
|
+
}
|
25
|
+
};
|
@@ -1,33 +1,37 @@
|
|
1
|
-
|
2
1
|
const observeAttributes = (ele, callback, excludeAttrs) => {
|
3
|
-
|
4
|
-
|
2
|
+
// sync all attrs on init
|
3
|
+
callback(...Array.from(ele.attributes).map((attr) => attr.name));
|
5
4
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
5
|
+
const observer = new MutationObserver((mutationsList) => {
|
6
|
+
for (const mutation of mutationsList) {
|
7
|
+
if (
|
8
|
+
mutation.type === 'attributes' &&
|
9
|
+
!excludeAttrs.includes(mutation.attributeName)
|
10
|
+
) {
|
11
|
+
callback(mutation.attributeName);
|
12
|
+
}
|
13
|
+
}
|
14
|
+
});
|
13
15
|
|
14
|
-
|
15
|
-
}
|
16
|
+
observer.observe(ele, { attributes: true });
|
17
|
+
};
|
16
18
|
|
17
|
-
const createSyncAttrsCb =
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
}
|
19
|
+
const createSyncAttrsCb =
|
20
|
+
(srcEle, targetEle) =>
|
21
|
+
(...attrNames) => {
|
22
|
+
attrNames.forEach((attrName) => {
|
23
|
+
const srcAttrVal = srcEle.getAttribute(attrName);
|
24
|
+
if (srcAttrVal !== null) {
|
25
|
+
if (targetEle.getAttribute(attrName) !== srcAttrVal) {
|
26
|
+
targetEle.setAttribute(attrName, srcAttrVal);
|
27
|
+
}
|
28
|
+
} else {
|
29
|
+
targetEle.removeAttribute(attrName);
|
30
|
+
}
|
31
|
+
});
|
32
|
+
};
|
29
33
|
|
30
34
|
export const syncAttrs = (ele1, ele2, excludeAttrs) => {
|
31
|
-
|
32
|
-
|
33
|
-
}
|
35
|
+
observeAttributes(ele1, createSyncAttrsCb(ele1, ele2), excludeAttrs);
|
36
|
+
observeAttributes(ele2, createSyncAttrsCb(ele2, ele1), excludeAttrs);
|
37
|
+
};
|
@@ -1,68 +1,86 @@
|
|
1
|
-
import { getCssVarName, kebabCase } from
|
1
|
+
import { getCssVarName, kebabCase } from '../../helpers';
|
2
2
|
|
3
|
-
const createCssVarFallback = (first, ...rest) =>
|
3
|
+
const createCssVarFallback = (first, ...rest) =>
|
4
|
+
`var(${first}${rest.length ? ` , ${createCssVarFallback(...rest)}` : ''})`;
|
4
5
|
|
5
|
-
const createCssSelector = (
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
const createCssSelector = (
|
7
|
+
baseSelector = '',
|
8
|
+
relativeSelectorOrSelectorFn = ''
|
9
|
+
) =>
|
10
|
+
typeof relativeSelectorOrSelectorFn === 'function'
|
11
|
+
? relativeSelectorOrSelectorFn(baseSelector)
|
12
|
+
: `${baseSelector}${relativeSelectorOrSelectorFn}`;
|
9
13
|
|
10
14
|
class StyleBuilder {
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
15
|
+
constructor() {
|
16
|
+
this.styleMap = new Map();
|
17
|
+
}
|
18
|
+
|
19
|
+
add(selector, property, value) {
|
20
|
+
if (!this.styleMap.has(selector)) {
|
21
|
+
this.styleMap.set(selector, []);
|
22
|
+
}
|
23
|
+
|
24
|
+
this.styleMap.set(selector, [
|
25
|
+
...this.styleMap.get(selector),
|
26
|
+
{ property, value }
|
27
|
+
]);
|
28
|
+
}
|
29
|
+
|
30
|
+
toString() {
|
31
|
+
return Array.from(this.styleMap.entries()).reduce(
|
32
|
+
(style, [selector, propValArr]) =>
|
33
|
+
(style += `${selector} { \n${propValArr
|
34
|
+
.map(({ property, value }) => `${property}: ${value}`)
|
35
|
+
.join(';\n')} \n}\n\n`),
|
36
|
+
''
|
37
|
+
);
|
38
|
+
}
|
28
39
|
}
|
29
40
|
|
30
41
|
const normalizeConfig = (attr, config) => {
|
31
|
-
|
42
|
+
const defaultMapping = { selector: '', property: kebabCase(attr) };
|
32
43
|
|
33
|
-
|
44
|
+
if (!config || !Object.keys(config).length) return [defaultMapping];
|
34
45
|
|
35
|
-
|
46
|
+
if (Array.isArray(config))
|
47
|
+
return config.map((entry) => Object.assign({}, defaultMapping, entry));
|
36
48
|
|
37
|
-
|
38
|
-
}
|
49
|
+
return [Object.assign({}, defaultMapping, config)];
|
50
|
+
};
|
39
51
|
|
40
52
|
export const createStyle = (componentName, baseSelector, mappings) => {
|
41
|
-
|
53
|
+
const style = new StyleBuilder();
|
42
54
|
|
43
|
-
|
44
|
-
|
55
|
+
Object.keys(mappings).forEach((attr) => {
|
56
|
+
const attrConfig = normalizeConfig(attr, mappings[attr]);
|
45
57
|
|
46
|
-
|
58
|
+
const cssVarName = getCssVarName(componentName, attr);
|
47
59
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
60
|
+
attrConfig.forEach(
|
61
|
+
({ selector: relativeSelectorOrSelectorFn, property }) => {
|
62
|
+
style.add(
|
63
|
+
createCssSelector(baseSelector, relativeSelectorOrSelectorFn),
|
64
|
+
property,
|
65
|
+
createCssVarFallback(cssVarName)
|
66
|
+
);
|
67
|
+
}
|
68
|
+
);
|
69
|
+
});
|
56
70
|
|
57
|
-
|
58
|
-
}
|
71
|
+
return style.toString();
|
72
|
+
};
|
59
73
|
|
60
74
|
export const createCssVarsList = (componentName, mappings) =>
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
75
|
+
Object.keys(mappings).reduce(
|
76
|
+
(acc, attr) =>
|
77
|
+
Object.assign(acc, { [attr]: getCssVarName(componentName, attr) }),
|
78
|
+
{}
|
79
|
+
);
|
65
80
|
|
66
81
|
// match the host selector with the inner element selector
|
67
82
|
// e.g. when we want to set the same size for the host & the inner element this can be useful
|
68
|
-
export const matchHostStyle = (mappingObj) => [
|
83
|
+
export const matchHostStyle = (mappingObj) => [
|
84
|
+
mappingObj,
|
85
|
+
{ ...mappingObj, selector: () => `:host${mappingObj.selector || ''}` }
|
86
|
+
];
|
@@ -1,58 +1,79 @@
|
|
1
1
|
import { getCssVarName, kebabCaseJoin } from '../../helpers';
|
2
2
|
import { createStyle, createCssVarsList } from './helpers';
|
3
3
|
|
4
|
-
export const createStyleMixin =
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
4
|
+
export const createStyleMixin =
|
5
|
+
({ mappings = {} }) =>
|
6
|
+
(superclass) => {
|
7
|
+
const styleAttributes = Object.keys(mappings).map((key) =>
|
8
|
+
kebabCaseJoin('st', key)
|
9
|
+
);
|
10
|
+
return class CustomStyleMixinClass extends superclass {
|
11
|
+
static get observedAttributes() {
|
12
|
+
const superAttrs = superclass.observedAttributes || [];
|
13
|
+
return [...superAttrs, ...styleAttributes];
|
14
|
+
}
|
15
|
+
|
16
|
+
static get cssVarList() {
|
17
|
+
return createCssVarsList(superclass.componentName, mappings);
|
18
|
+
}
|
19
|
+
|
20
|
+
#styleEle = null;
|
21
|
+
|
22
|
+
constructor() {
|
23
|
+
super();
|
24
|
+
|
25
|
+
this.#createComponentStyle();
|
26
|
+
this.#createAttrOverrideStyle();
|
27
|
+
}
|
28
|
+
|
29
|
+
#createAttrOverrideStyle() {
|
30
|
+
this.#styleEle = document.createElement('style');
|
31
|
+
this.#styleEle.id = 'style-mixin-overrides';
|
32
|
+
|
33
|
+
this.#styleEle.innerText = '* {}';
|
34
|
+
this.shadowRoot.prepend(this.#styleEle);
|
35
|
+
}
|
36
|
+
|
37
|
+
#updateAttrOverrideStyle(attrName, value) {
|
38
|
+
const style = this.#styleEle.sheet.cssRules[0].style;
|
39
|
+
const varName = getCssVarName(
|
40
|
+
superclass.componentName,
|
41
|
+
attrName.replace(/^st-/, '')
|
42
|
+
);
|
43
|
+
|
44
|
+
if (value) style.setProperty(varName, value);
|
45
|
+
else style.removeProperty(varName);
|
46
|
+
}
|
47
|
+
|
48
|
+
#createComponentStyle() {
|
49
|
+
const themeStyle = document.createElement('style');
|
50
|
+
themeStyle.id = 'style-mixin-component';
|
51
|
+
themeStyle.innerHTML = createStyle(
|
52
|
+
superclass.componentName,
|
53
|
+
this.baseSelector,
|
54
|
+
mappings
|
55
|
+
);
|
56
|
+
this.shadowRoot.prepend(themeStyle);
|
57
|
+
}
|
58
|
+
|
59
|
+
attributeChangedCallback(attrName, oldValue, newValue) {
|
60
|
+
super.attributeChangedCallback?.(attrName, oldValue, newValue);
|
61
|
+
|
62
|
+
if (styleAttributes.includes(attrName)) {
|
63
|
+
this.#updateAttrOverrideStyle(attrName, newValue);
|
64
|
+
}
|
65
|
+
}
|
66
|
+
|
67
|
+
// we need to see if this is needed
|
68
|
+
// connectedCallback() {
|
69
|
+
// super.connectedCallback?.();
|
70
|
+
// if (this.shadowRoot.isConnected) {
|
71
|
+
// Array.from(this.attributes).forEach(attr => {
|
72
|
+
// if (styleAttributes.includes(attr.nodeName)) {
|
73
|
+
// this.#updateAttrOverrideStyle(attr.nodeName, attr.value)
|
74
|
+
// }
|
75
|
+
// });
|
76
|
+
// }
|
77
|
+
// }
|
78
|
+
};
|
79
|
+
};
|
@@ -1,32 +1,31 @@
|
|
1
1
|
export const draggableMixin = (superclass) =>
|
2
|
-
|
2
|
+
class DraggableMixinClass extends superclass {
|
3
|
+
#styleEle = null;
|
3
4
|
|
4
|
-
|
5
|
+
static get observedAttributes() {
|
6
|
+
const superAttrs = superclass.observedAttributes || [];
|
7
|
+
return [...superAttrs, 'draggable'];
|
8
|
+
}
|
5
9
|
|
6
|
-
|
7
|
-
|
8
|
-
return [...superAttrs, 'draggable']
|
9
|
-
}
|
10
|
+
constructor() {
|
11
|
+
super();
|
10
12
|
|
11
|
-
|
12
|
-
|
13
|
+
this.#styleEle = document.createElement('style');
|
14
|
+
this.#styleEle.innerText = `${this.baseSelector} { cursor: inherit }`;
|
15
|
+
}
|
13
16
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
+
#handleDraggableStyle(isDraggable) {
|
18
|
+
if (isDraggable) {
|
19
|
+
this.shadowRoot.appendChild(this.#styleEle);
|
20
|
+
} else {
|
21
|
+
this.#styleEle.remove();
|
22
|
+
}
|
23
|
+
}
|
17
24
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
attributeChangedCallback(attrName, oldValue, newValue) {
|
27
|
-
super.attributeChangedCallback?.(attrName, oldValue, newValue);
|
28
|
-
if (attrName === 'draggable') {
|
29
|
-
this.#handleDraggableStyle(newValue === 'true')
|
30
|
-
}
|
31
|
-
}
|
32
|
-
}
|
25
|
+
attributeChangedCallback(attrName, oldValue, newValue) {
|
26
|
+
super.attributeChangedCallback?.(attrName, oldValue, newValue);
|
27
|
+
if (attrName === 'draggable') {
|
28
|
+
this.#handleDraggableStyle(newValue === 'true');
|
29
|
+
}
|
30
|
+
}
|
31
|
+
};
|
package/src/constants.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export const DESCOPE_PREFIX = 'descope'
|
1
|
+
export const DESCOPE_PREFIX = 'descope';
|