@descope/web-components-ui 1.0.427 → 1.0.429
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 +8 -16
- 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,95 +0,0 @@
|
|
1
|
-
import { kebabCaseJoin } from '../utils';
|
2
|
-
import { DESCOPE_PREFIX } from '../constants';
|
3
|
-
|
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);
|
13
|
-
|
14
|
-
callback(filteredAttrs);
|
15
|
-
|
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
|
-
});
|
27
|
-
|
28
|
-
observer.observe(ele, { attributes: true });
|
29
|
-
};
|
30
|
-
|
31
|
-
// calling the callback with this object: { addedNodes, removedNodes }
|
32
|
-
export const observeChildren = (ele, callback) => {
|
33
|
-
callback({ addedNodes: Array.from(ele.children), removedNodes: [] });
|
34
|
-
|
35
|
-
const observer = new MutationObserver((mutationsList) => {
|
36
|
-
mutationsList.forEach((mutation) => {
|
37
|
-
if (mutation.type === 'childList' || mutation.type === 'characterData') {
|
38
|
-
callback(mutation);
|
39
|
-
}
|
40
|
-
});
|
41
|
-
});
|
42
|
-
|
43
|
-
observer.observe(ele, { childList: true, characterData: true, subtree: true });
|
44
|
-
};
|
45
|
-
|
46
|
-
const createSyncAttrsCb =
|
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
|
-
};
|
61
|
-
|
62
|
-
export const syncAttrs = (ele1, ele2, options) => {
|
63
|
-
observeAttributes(ele1, createSyncAttrsCb(ele1, ele2), options);
|
64
|
-
observeAttributes(ele2, createSyncAttrsCb(ele2, ele1), options);
|
65
|
-
};
|
66
|
-
|
67
|
-
export const getComponentName = (name) => kebabCaseJoin(DESCOPE_PREFIX, name);
|
68
|
-
|
69
|
-
export const getCssVarName = (...args) => `--${kebabCaseJoin(...args)}`;
|
70
|
-
|
71
|
-
export const forwardAttrs = (source, dest, options = {}) => {
|
72
|
-
observeAttributes(source, createSyncAttrsCb(source, dest, options.mapAttrs), options);
|
73
|
-
};
|
74
|
-
|
75
|
-
export const forwardProps = (src, target, props = []) => {
|
76
|
-
if (!props.length) return;
|
77
|
-
|
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
|
-
);
|
93
|
-
|
94
|
-
Object.defineProperties(target, config);
|
95
|
-
};
|
@@ -1,10 +0,0 @@
|
|
1
|
-
// create a dispatch event function that also calls to the onevent function in case it's set
|
2
|
-
// usage example:
|
3
|
-
// #dispatchSomething = createDispatchEvent.bind(this, 'something' { ...options })
|
4
|
-
// this will dispatch a new event when called, but also call to "onsomething"
|
5
|
-
export function createDispatchEvent(eventName, options = {}) {
|
6
|
-
const event = new Event(eventName, options);
|
7
|
-
|
8
|
-
this[`on${eventName}`]?.(event); // in case we got an event callback as property
|
9
|
-
this.dispatchEvent(event);
|
10
|
-
}
|
@@ -1 +0,0 @@
|
|
1
|
-
export * from './mixins'
|
@@ -1,14 +0,0 @@
|
|
1
|
-
export const activeableMixin = (superclass) =>
|
2
|
-
class ActiveableMixinClass extends superclass {
|
3
|
-
init() {
|
4
|
-
super.init?.();
|
5
|
-
|
6
|
-
this.baseElement.addEventListener('mousedown', (e) => {
|
7
|
-
e.preventDefault();
|
8
|
-
this.setAttribute('active', 'true');
|
9
|
-
window.addEventListener('mouseup', () => this.removeAttribute('active'), {
|
10
|
-
once: true,
|
11
|
-
});
|
12
|
-
});
|
13
|
-
}
|
14
|
-
};
|
@@ -1,22 +0,0 @@
|
|
1
|
-
import { createDispatchEvent } from '../../componentsMixins/helpers/mixinsHelpers';
|
2
|
-
|
3
|
-
export const changeMixin = (superclass) =>
|
4
|
-
class ChangeMixinClass extends superclass {
|
5
|
-
#dispatchChange = createDispatchEvent.bind(this, 'change');
|
6
|
-
|
7
|
-
init() {
|
8
|
-
super.init?.();
|
9
|
-
this.prevValue = this.value;
|
10
|
-
|
11
|
-
this.addEventListener('change', (e) => {
|
12
|
-
e.stopPropagation();
|
13
|
-
});
|
14
|
-
|
15
|
-
this.addEventListener('blur', () => {
|
16
|
-
if (this.value !== this.prevValue) {
|
17
|
-
this.#dispatchChange();
|
18
|
-
this.prevValue = this.value;
|
19
|
-
}
|
20
|
-
});
|
21
|
-
}
|
22
|
-
};
|
@@ -1,23 +0,0 @@
|
|
1
|
-
export const componentNameValidationMixin = (superclass) =>
|
2
|
-
class ComponentNameValidationMixinClass extends superclass {
|
3
|
-
#checkComponentName() {
|
4
|
-
const currentComponentName = this.localName;
|
5
|
-
|
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
|
-
}
|
11
|
-
|
12
|
-
if (currentComponentName !== superclass.componentName) {
|
13
|
-
throw Error(
|
14
|
-
`component name mismatch, expected "${superclass.componentName}", current "${currentComponentName}"`
|
15
|
-
);
|
16
|
-
}
|
17
|
-
}
|
18
|
-
|
19
|
-
init() {
|
20
|
-
super.init?.();
|
21
|
-
this.#checkComponentName();
|
22
|
-
}
|
23
|
-
};
|
@@ -1,12 +0,0 @@
|
|
1
|
-
export const componentsContextMixin = (superclass) =>
|
2
|
-
class ComponentsContextMixinClass extends superclass {
|
3
|
-
updateComponentsContext(componentsContext) {
|
4
|
-
this.dispatchEvent(
|
5
|
-
new CustomEvent('components-context', {
|
6
|
-
bubbles: true,
|
7
|
-
composed: true,
|
8
|
-
detail: componentsContext,
|
9
|
-
})
|
10
|
-
);
|
11
|
-
}
|
12
|
-
};
|
@@ -1,100 +0,0 @@
|
|
1
|
-
import { observeAttributes } from '../helpers/componentHelpers';
|
2
|
-
|
3
|
-
const defaultValidateSchema = () => true;
|
4
|
-
const defaultItemRenderer = (item) => `<pre>${JSON.stringify(item, null, 4)}</pre>`;
|
5
|
-
|
6
|
-
const createTemplate = (templateString) => {
|
7
|
-
const template = document.createElement('template');
|
8
|
-
template.innerHTML = templateString;
|
9
|
-
|
10
|
-
return template;
|
11
|
-
};
|
12
|
-
|
13
|
-
const getTemplateContent = (templateOrString) => {
|
14
|
-
if (typeof templateOrString === 'string') {
|
15
|
-
return createTemplate(templateOrString).content;
|
16
|
-
}
|
17
|
-
|
18
|
-
if (templateOrString instanceof HTMLTemplateElement) {
|
19
|
-
return templateOrString.content;
|
20
|
-
}
|
21
|
-
|
22
|
-
// eslint-disable-next-line no-console
|
23
|
-
console.error('Invalid template', templateOrString);
|
24
|
-
return null;
|
25
|
-
};
|
26
|
-
|
27
|
-
export const createDynamicDataMixin =
|
28
|
-
({
|
29
|
-
itemRenderer = defaultItemRenderer,
|
30
|
-
validateSchema = defaultValidateSchema,
|
31
|
-
slotName,
|
32
|
-
rerenderAttrsList = [],
|
33
|
-
}) =>
|
34
|
-
(superclass) =>
|
35
|
-
class DynamicDataMixinClass extends superclass {
|
36
|
-
#data = [];
|
37
|
-
|
38
|
-
// eslint-disable-next-line class-methods-use-this
|
39
|
-
#validateSchema(data) {
|
40
|
-
if (!validateSchema) return true;
|
41
|
-
|
42
|
-
const validation = validateSchema(data);
|
43
|
-
if (validation === true) return true;
|
44
|
-
|
45
|
-
// eslint-disable-next-line no-console
|
46
|
-
console.error('Data schema validation failed', validation || '');
|
47
|
-
|
48
|
-
return false;
|
49
|
-
}
|
50
|
-
|
51
|
-
#removeOldItems() {
|
52
|
-
const selector = slotName ? `*[slot="${slotName}"]` : ':not([slot])';
|
53
|
-
this.baseElement.querySelectorAll(selector).forEach((item) => item.remove());
|
54
|
-
}
|
55
|
-
|
56
|
-
#renderItems() {
|
57
|
-
this.#removeOldItems();
|
58
|
-
this.data.forEach((item, index) => {
|
59
|
-
const content = getTemplateContent(itemRenderer(item, index, this));
|
60
|
-
this.baseElement.appendChild(content?.cloneNode(true));
|
61
|
-
});
|
62
|
-
}
|
63
|
-
|
64
|
-
set data(value) {
|
65
|
-
if (this.#validateSchema(value)) {
|
66
|
-
this.#data = value;
|
67
|
-
this.#renderItems();
|
68
|
-
}
|
69
|
-
}
|
70
|
-
|
71
|
-
get data() {
|
72
|
-
return this.#data;
|
73
|
-
}
|
74
|
-
|
75
|
-
init() {
|
76
|
-
super.init?.();
|
77
|
-
|
78
|
-
observeAttributes(
|
79
|
-
this,
|
80
|
-
(attrs) => {
|
81
|
-
if (attrs.includes('data')) this.#handleDataAttr();
|
82
|
-
else this.#renderItems();
|
83
|
-
},
|
84
|
-
{ includeAttrs: [...rerenderAttrsList, 'data'] }
|
85
|
-
);
|
86
|
-
}
|
87
|
-
|
88
|
-
#handleDataAttr() {
|
89
|
-
const dataAttr = this.getAttribute('data');
|
90
|
-
|
91
|
-
if (!dataAttr) return;
|
92
|
-
|
93
|
-
try {
|
94
|
-
this.data = JSON.parse(dataAttr);
|
95
|
-
} catch (e) {
|
96
|
-
// eslint-disable-next-line no-console
|
97
|
-
console.warn('Invalid JSON data', dataAttr);
|
98
|
-
}
|
99
|
-
}
|
100
|
-
};
|
@@ -1,58 +0,0 @@
|
|
1
|
-
import { createBaseClass } from '../../baseClasses';
|
2
|
-
import { isFunction } from '../../utils';
|
3
|
-
import { forwardProps, syncAttrs } from '../../componentsHelpers';
|
4
|
-
import { createDispatchEvent } from '../../componentsMixins/helpers/mixinsHelpers';
|
5
|
-
|
6
|
-
export const createProxy = ({
|
7
|
-
componentName,
|
8
|
-
wrappedEleName,
|
9
|
-
slots = [],
|
10
|
-
style,
|
11
|
-
excludeAttrsSync = [],
|
12
|
-
includeAttrsSync = [],
|
13
|
-
includeForwardProps = [],
|
14
|
-
delegatesFocus = true,
|
15
|
-
}) => {
|
16
|
-
class ProxyClass extends createBaseClass({ componentName, baseSelector: wrappedEleName }) {
|
17
|
-
#dispatchBlur = createDispatchEvent.bind(this, 'blur');
|
18
|
-
|
19
|
-
#dispatchFocus = createDispatchEvent.bind(this, 'focus');
|
20
|
-
|
21
|
-
constructor() {
|
22
|
-
super().attachShadow({ mode: 'open', delegatesFocus }).innerHTML = `
|
23
|
-
<style id="create-proxy">${(isFunction(style) ? style() : style) || ''}</style>
|
24
|
-
<${wrappedEleName}>
|
25
|
-
${slots
|
26
|
-
.map(
|
27
|
-
(
|
28
|
-
slot // when slot is an empty string, we will create the default slot (without a name)
|
29
|
-
) => `<slot ${slot ? `name="${slot}" slot="${slot}"` : ''}></slot>`
|
30
|
-
)
|
31
|
-
.join('')}
|
32
|
-
</${wrappedEleName}>
|
33
|
-
`;
|
34
|
-
}
|
35
|
-
|
36
|
-
init() {
|
37
|
-
super.init?.();
|
38
|
-
|
39
|
-
this.baseElement.addEventListener('blur', (_) => {
|
40
|
-
this.#dispatchBlur();
|
41
|
-
});
|
42
|
-
|
43
|
-
this.baseElement.addEventListener('focus', (_) => {
|
44
|
-
this.#dispatchFocus();
|
45
|
-
});
|
46
|
-
|
47
|
-
// this is needed for components that uses props, such as combo box
|
48
|
-
forwardProps(this.baseElement, this, includeForwardProps);
|
49
|
-
|
50
|
-
syncAttrs(this.baseElement, this, {
|
51
|
-
excludeAttrs: excludeAttrsSync,
|
52
|
-
includeAttrs: includeAttrsSync,
|
53
|
-
});
|
54
|
-
}
|
55
|
-
}
|
56
|
-
|
57
|
-
return ProxyClass;
|
58
|
-
};
|
@@ -1,106 +0,0 @@
|
|
1
|
-
import { camelCaseJoin, isFunction, kebabCase, kebabCaseJoin } from '../../../utils';
|
2
|
-
import { getCssVarName } from '../../../componentsHelpers';
|
3
|
-
|
4
|
-
const createCssVar = (varName, fallback) => `var(${varName}${fallback ? `, ${fallback}` : ''})`;
|
5
|
-
|
6
|
-
const createCssSelector = (baseSelector = '', relativeSelectorOrSelectorFn = '') =>
|
7
|
-
isFunction(relativeSelectorOrSelectorFn)
|
8
|
-
? relativeSelectorOrSelectorFn(baseSelector)
|
9
|
-
: `${baseSelector}${
|
10
|
-
/^[A-Za-z]/.test(relativeSelectorOrSelectorFn)
|
11
|
-
? ` ${relativeSelectorOrSelectorFn}`
|
12
|
-
: relativeSelectorOrSelectorFn
|
13
|
-
}`;
|
14
|
-
|
15
|
-
class StyleBuilder {
|
16
|
-
constructor() {
|
17
|
-
this.styleMap = new Map();
|
18
|
-
}
|
19
|
-
|
20
|
-
add(selector, property, value) {
|
21
|
-
if (!this.styleMap.has(selector)) {
|
22
|
-
this.styleMap.set(selector, []);
|
23
|
-
}
|
24
|
-
|
25
|
-
this.styleMap.set(selector, [...this.styleMap.get(selector), { property, value }]);
|
26
|
-
}
|
27
|
-
|
28
|
-
toString() {
|
29
|
-
return Array.from(this.styleMap.entries()).reduce((acc, [selector, propValArr]) => {
|
30
|
-
const properties = propValArr
|
31
|
-
.map(({ property, value }) => `${property}: ${value}`)
|
32
|
-
.join(';\n');
|
33
|
-
|
34
|
-
return `${acc}${selector} { \n${properties} \n}\n\n`;
|
35
|
-
}, '');
|
36
|
-
}
|
37
|
-
}
|
38
|
-
|
39
|
-
const normalizeConfig = (attr, config) => {
|
40
|
-
const defaultMapping = { selector: '', property: kebabCase(attr) };
|
41
|
-
|
42
|
-
if (!config || !Object.keys(config).length) return [defaultMapping];
|
43
|
-
|
44
|
-
if (Array.isArray(config)) return config.map((entry) => ({ ...defaultMapping, ...entry }));
|
45
|
-
|
46
|
-
return [{ ...defaultMapping, ...config }];
|
47
|
-
};
|
48
|
-
|
49
|
-
const getFallbackVarName = (origVarName, suffix = 'fallback') => kebabCaseJoin(origVarName, suffix);
|
50
|
-
|
51
|
-
export const createStyle = (componentName, baseSelector, mappings) => {
|
52
|
-
const style = new StyleBuilder();
|
53
|
-
const createFallbackVar = (fallback, origVarName) => {
|
54
|
-
if (!fallback) return '';
|
55
|
-
if (typeof fallback === 'string') return fallback;
|
56
|
-
|
57
|
-
const fallbackVarName = getFallbackVarName(origVarName, fallback?.suffix);
|
58
|
-
return createCssVar(fallbackVarName, createFallbackVar(fallback.fallback, fallbackVarName));
|
59
|
-
};
|
60
|
-
|
61
|
-
Object.keys(mappings).forEach((attr) => {
|
62
|
-
const attrConfig = normalizeConfig(attr, mappings[attr]);
|
63
|
-
|
64
|
-
const cssVarName = getCssVarName(componentName, attr);
|
65
|
-
|
66
|
-
attrConfig.forEach(
|
67
|
-
({ selector: relativeSelectorOrSelectorFn, property, important, fallback }) => {
|
68
|
-
const fallbackValue = createFallbackVar(fallback, cssVarName);
|
69
|
-
style.add(
|
70
|
-
createCssSelector(baseSelector, relativeSelectorOrSelectorFn),
|
71
|
-
isFunction(property) ? property() : property,
|
72
|
-
createCssVar(cssVarName, fallbackValue) + (important ? '!important' : '')
|
73
|
-
);
|
74
|
-
}
|
75
|
-
);
|
76
|
-
});
|
77
|
-
|
78
|
-
return style.toString();
|
79
|
-
};
|
80
|
-
|
81
|
-
const getFallbackVarsNames = (attr, origVarName, { fallback }) => {
|
82
|
-
if (!fallback) return {};
|
83
|
-
|
84
|
-
const fallbackVarName = getFallbackVarName(origVarName, fallback.suffix);
|
85
|
-
const fallbackAttrName = camelCaseJoin(attr, fallback.suffix || 'fallback');
|
86
|
-
return {
|
87
|
-
[fallbackAttrName]: fallbackVarName,
|
88
|
-
...getFallbackVarsNames(fallbackAttrName, fallbackVarName, fallback),
|
89
|
-
};
|
90
|
-
};
|
91
|
-
|
92
|
-
export const createCssVarsList = (componentName, mappings) =>
|
93
|
-
Object.keys(mappings).reduce((acc, attr) => {
|
94
|
-
const varName = getCssVarName(componentName, attr);
|
95
|
-
|
96
|
-
return Object.assign(
|
97
|
-
acc,
|
98
|
-
{ [attr]: varName },
|
99
|
-
getFallbackVarsNames(attr, varName, mappings[attr])
|
100
|
-
);
|
101
|
-
}, {});
|
102
|
-
|
103
|
-
// on some cases we need a selector to be more specific than another
|
104
|
-
// for this we have this fn that generate a class selector multiple times
|
105
|
-
export const createClassSelectorSpecifier = (className, numOfRepeats) =>
|
106
|
-
Array(numOfRepeats).fill(`.${className}`).join('');
|
@@ -1,167 +0,0 @@
|
|
1
|
-
import { BASE_THEME_SECTION, CSS_SELECTOR_SPECIFIER_MULTIPLY } from '../../../constants';
|
2
|
-
import { kebabCaseJoin } from '../../../utils';
|
3
|
-
import { getCssVarName, observeAttributes } from '../../../componentsHelpers';
|
4
|
-
import { componentsThemeManager } from '../../../themeHelpers';
|
5
|
-
import { createStyle, createCssVarsList, createClassSelectorSpecifier } from './helpers';
|
6
|
-
|
7
|
-
const STYLE_OVERRIDE_ATTR_PREFIX = 'st';
|
8
|
-
|
9
|
-
export const createStyleMixin =
|
10
|
-
({ mappings = {}, componentNameOverride = '' }) =>
|
11
|
-
(superclass) => {
|
12
|
-
const componentName = componentNameOverride || superclass.componentName;
|
13
|
-
|
14
|
-
return class CustomStyleMixinClass extends superclass {
|
15
|
-
static get cssVarList() {
|
16
|
-
return {
|
17
|
-
...superclass.cssVarList,
|
18
|
-
...createCssVarsList(componentName, {
|
19
|
-
...mappings,
|
20
|
-
}),
|
21
|
-
};
|
22
|
-
}
|
23
|
-
|
24
|
-
#overrideStyleEle;
|
25
|
-
|
26
|
-
#themeStyleEle;
|
27
|
-
|
28
|
-
#disconnectThemeManager;
|
29
|
-
|
30
|
-
#componentNameSuffix;
|
31
|
-
|
32
|
-
#themeSection;
|
33
|
-
|
34
|
-
#rootElement;
|
35
|
-
|
36
|
-
#baseSelector;
|
37
|
-
|
38
|
-
#styleAttributes;
|
39
|
-
|
40
|
-
#getRootElement;
|
41
|
-
|
42
|
-
// we are using this mixin also for portalMixin
|
43
|
-
// so we should be able to inject styles to other DOM elements
|
44
|
-
// this is why we need to support these overrides
|
45
|
-
constructor({
|
46
|
-
getRootElement,
|
47
|
-
componentNameSuffix = '',
|
48
|
-
themeSection = BASE_THEME_SECTION,
|
49
|
-
baseSelector,
|
50
|
-
} = {}) {
|
51
|
-
super();
|
52
|
-
this.#componentNameSuffix = componentNameSuffix;
|
53
|
-
this.#themeSection = themeSection;
|
54
|
-
this.#baseSelector = baseSelector ?? this.baseSelector;
|
55
|
-
this.#getRootElement = getRootElement;
|
56
|
-
|
57
|
-
this.#styleAttributes = Object.keys(CustomStyleMixinClass.cssVarList).map((key) =>
|
58
|
-
kebabCaseJoin(STYLE_OVERRIDE_ATTR_PREFIX, componentNameSuffix, key)
|
59
|
-
);
|
60
|
-
}
|
61
|
-
|
62
|
-
// eslint-disable-next-line class-methods-use-this
|
63
|
-
get #componentTheme() {
|
64
|
-
return componentsThemeManager.currentTheme?.[componentName] || '';
|
65
|
-
}
|
66
|
-
|
67
|
-
#onComponentThemeChange() {
|
68
|
-
this.#themeStyleEle.innerHTML = this.#componentTheme[this.#themeSection];
|
69
|
-
}
|
70
|
-
|
71
|
-
#createComponentTheme() {
|
72
|
-
this.#themeStyleEle = document.createElement('style');
|
73
|
-
this.#themeStyleEle.id = `style-mixin-theme__${componentName}`;
|
74
|
-
this.#rootElement.prepend(this.#themeStyleEle);
|
75
|
-
this.#disconnectThemeManager = componentsThemeManager.onCurrentThemeChange(
|
76
|
-
this.#onComponentThemeChange.bind(this)
|
77
|
-
);
|
78
|
-
this.#onComponentThemeChange();
|
79
|
-
}
|
80
|
-
|
81
|
-
#createOverridesStyle() {
|
82
|
-
if (this.#styleAttributes.length) {
|
83
|
-
this.#overrideStyleEle = document.createElement('style');
|
84
|
-
this.#overrideStyleEle.id = `style-mixin-overrides__${componentName}`;
|
85
|
-
|
86
|
-
const classSpecifier = createClassSelectorSpecifier(
|
87
|
-
componentName,
|
88
|
-
CSS_SELECTOR_SPECIFIER_MULTIPLY
|
89
|
-
);
|
90
|
-
|
91
|
-
this.#overrideStyleEle.innerText = `:host(${classSpecifier}) {}`;
|
92
|
-
this.#rootElement.append(this.#overrideStyleEle);
|
93
|
-
}
|
94
|
-
}
|
95
|
-
|
96
|
-
#setAttrOverride(attrName, value) {
|
97
|
-
const style = this.#overrideStyleEle?.sheet?.cssRules[0].style;
|
98
|
-
if (!style) return;
|
99
|
-
|
100
|
-
const varName = getCssVarName(
|
101
|
-
componentName,
|
102
|
-
attrName.replace(new RegExp(`^${STYLE_OVERRIDE_ATTR_PREFIX}-`), '')
|
103
|
-
);
|
104
|
-
|
105
|
-
if (value) style?.setProperty(varName, value);
|
106
|
-
else {
|
107
|
-
style?.removeProperty(varName);
|
108
|
-
this.removeAttribute(attrName);
|
109
|
-
}
|
110
|
-
}
|
111
|
-
|
112
|
-
#updateOverridesStyle(attrs = []) {
|
113
|
-
let shouldUpdate = false;
|
114
|
-
|
115
|
-
attrs.forEach((attr) => {
|
116
|
-
if (this.#styleAttributes.includes(attr)) {
|
117
|
-
this.#setAttrOverride(attr, this.getAttribute(attr));
|
118
|
-
shouldUpdate = true;
|
119
|
-
}
|
120
|
-
});
|
121
|
-
|
122
|
-
if (shouldUpdate) {
|
123
|
-
// we are rewriting the style back to the style tag
|
124
|
-
this.#overrideStyleEle.innerHTML = this.#overrideStyleEle?.sheet?.cssRules[0].cssText;
|
125
|
-
}
|
126
|
-
}
|
127
|
-
|
128
|
-
#createMappingStyle() {
|
129
|
-
if (Object.keys(mappings).length) {
|
130
|
-
const themeStyle = document.createElement('style');
|
131
|
-
themeStyle.id = `style-mixin-mappings__${componentName}`;
|
132
|
-
themeStyle.innerHTML = createStyle(
|
133
|
-
kebabCaseJoin(componentName, this.#componentNameSuffix),
|
134
|
-
this.#baseSelector,
|
135
|
-
mappings
|
136
|
-
);
|
137
|
-
this.#rootElement.prepend(themeStyle);
|
138
|
-
}
|
139
|
-
}
|
140
|
-
|
141
|
-
#addClassName(className) {
|
142
|
-
(this.#rootElement.classList || this.#rootElement.host.classList).add(className);
|
143
|
-
}
|
144
|
-
|
145
|
-
async init() {
|
146
|
-
super.init?.();
|
147
|
-
if (this.shadowRoot.isConnected) {
|
148
|
-
this.#rootElement = (await this.#getRootElement?.(this)) || this.shadowRoot;
|
149
|
-
|
150
|
-
this.#addClassName(componentName);
|
151
|
-
|
152
|
-
this.#createMappingStyle();
|
153
|
-
this.#createComponentTheme();
|
154
|
-
this.#createOverridesStyle();
|
155
|
-
|
156
|
-
// this is instead attributeChangedCallback because we cannot use static methods in this case
|
157
|
-
observeAttributes(this, this.#updateOverridesStyle.bind(this), {});
|
158
|
-
}
|
159
|
-
}
|
160
|
-
|
161
|
-
disconnectedCallback() {
|
162
|
-
super.disconnectedCallback?.();
|
163
|
-
|
164
|
-
this.#disconnectThemeManager?.();
|
165
|
-
}
|
166
|
-
};
|
167
|
-
};
|
@@ -1,62 +0,0 @@
|
|
1
|
-
export const draggableMixin = (superclass) =>
|
2
|
-
class DraggableMixinClass extends superclass {
|
3
|
-
#styleEle = null;
|
4
|
-
|
5
|
-
static get observedAttributes() {
|
6
|
-
const superAttrs = superclass.observedAttributes || [];
|
7
|
-
return [...superAttrs, 'draggable'];
|
8
|
-
}
|
9
|
-
|
10
|
-
constructor() {
|
11
|
-
super();
|
12
|
-
|
13
|
-
this.#styleEle = document.createElement('style');
|
14
|
-
this.#styleEle.innerText = `* { cursor: inherit!important }`;
|
15
|
-
}
|
16
|
-
|
17
|
-
#handleDraggableStyle(isDraggable) {
|
18
|
-
if (isDraggable) {
|
19
|
-
this.shadowRoot.appendChild(this.#styleEle);
|
20
|
-
} else {
|
21
|
-
this.#styleEle.remove();
|
22
|
-
}
|
23
|
-
}
|
24
|
-
|
25
|
-
get isDraggable() {
|
26
|
-
return this.hasAttribute('draggable') && this.getAttribute('draggable') !== 'false';
|
27
|
-
}
|
28
|
-
|
29
|
-
init() {
|
30
|
-
// because we are delegating the focus from the outer component,
|
31
|
-
// the D&D is not working well in the page editor
|
32
|
-
// in order to solve it we are making the inner component focusable on mouse down
|
33
|
-
// and removing it on complete
|
34
|
-
this.addEventListener('mousedown', (e) => {
|
35
|
-
if (this.isDraggable) {
|
36
|
-
const prevTabIndex = this.baseElement.getAttribute('tabindex');
|
37
|
-
this.baseElement.setAttribute('tabindex', '-1');
|
38
|
-
|
39
|
-
const onComplete = () => {
|
40
|
-
prevTabIndex
|
41
|
-
? this.baseElement.setAttribute('tabindex', prevTabIndex)
|
42
|
-
: this.baseElement.removeAttribute('tabindex');
|
43
|
-
|
44
|
-
e.target.removeEventListener('mouseup', onComplete);
|
45
|
-
e.target.removeEventListener('dragend', onComplete);
|
46
|
-
};
|
47
|
-
|
48
|
-
e.target.addEventListener('mouseup', onComplete, { once: true });
|
49
|
-
e.target.addEventListener('dragend', onComplete, { once: true });
|
50
|
-
}
|
51
|
-
});
|
52
|
-
|
53
|
-
super.init?.();
|
54
|
-
}
|
55
|
-
|
56
|
-
attributeChangedCallback(attrName, oldValue, newValue) {
|
57
|
-
super.attributeChangedCallback?.(attrName, oldValue, newValue);
|
58
|
-
if (attrName === 'draggable') {
|
59
|
-
this.#handleDraggableStyle(newValue === 'true');
|
60
|
-
}
|
61
|
-
}
|
62
|
-
};
|