@descope-ui/common 0.0.5 → 0.0.6
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/CHANGELOG.md +2 -0
- package/package.json +1 -1
- package/src/baseClasses/baseClasses/createCssVarImageClass.js +7 -5
- package/src/componentsHelpers/index.js +16 -0
- package/src/componentsMixins/mixins/createProxy.js +3 -2
- package/src/componentsMixins/mixins/createStyleMixin/index.js +9 -23
- package/src/sbHelpers.js +6 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
|
|
4
4
|
|
|
5
|
+
## [0.0.6](https://github.com/descope/web-components-ui/compare/@descope-ui/common-0.0.5...@descope-ui/common-0.0.6) (2025-03-03)
|
|
6
|
+
|
|
5
7
|
## [0.0.5](https://github.com/descope/web-components-ui/compare/@descope-ui/common-0.0.4...@descope-ui/common-0.0.5) (2025-02-26)
|
|
6
8
|
|
|
7
9
|
## [0.0.4](https://github.com/descope/web-components-ui/compare/@descope-ui/common-0.0.3...@descope-ui/common-0.0.4) (2025-02-17)
|
package/package.json
CHANGED
|
@@ -3,6 +3,7 @@ import { componentNameValidationMixin } from '../../componentsMixins/mixins/comp
|
|
|
3
3
|
import { createStyleMixin } from '../../componentsMixins/mixins/createStyleMixin';
|
|
4
4
|
import { draggableMixin } from '../../componentsMixins/mixins/draggableMixin';
|
|
5
5
|
import { createBaseClass } from './createBaseClass';
|
|
6
|
+
import { injectStyle } from '../../componentsHelpers';
|
|
6
7
|
|
|
7
8
|
export const createCssVarImageClass = ({ componentName, varName, fallbackVarName }) => {
|
|
8
9
|
let style;
|
|
@@ -15,8 +16,11 @@ export const createCssVarImageClass = ({ componentName, varName, fallbackVarName
|
|
|
15
16
|
constructor() {
|
|
16
17
|
super();
|
|
17
18
|
this.attachShadow({ mode: 'open' }).innerHTML = `
|
|
18
|
-
<
|
|
19
|
-
|
|
19
|
+
<div></div>
|
|
20
|
+
`;
|
|
21
|
+
|
|
22
|
+
injectStyle(`
|
|
23
|
+
:host {
|
|
20
24
|
display: inline-flex;
|
|
21
25
|
}
|
|
22
26
|
:host([draggable="true"]) > div {
|
|
@@ -30,9 +34,7 @@ export const createCssVarImageClass = ({ componentName, varName, fallbackVarName
|
|
|
30
34
|
margin: auto;
|
|
31
35
|
${getContent()}
|
|
32
36
|
}
|
|
33
|
-
|
|
34
|
-
<div></div>
|
|
35
|
-
`;
|
|
37
|
+
`, this)
|
|
36
38
|
}
|
|
37
39
|
}
|
|
38
40
|
|
|
@@ -93,3 +93,19 @@ export const forwardProps = (src, target, props = []) => {
|
|
|
93
93
|
|
|
94
94
|
Object.defineProperties(target, config);
|
|
95
95
|
};
|
|
96
|
+
|
|
97
|
+
export const injectStyle = (cssString, ref, {prepend = false} = {}) => {
|
|
98
|
+
const style = new CSSStyleSheet();
|
|
99
|
+
const _ref = ref?.shadowRoot || ref;
|
|
100
|
+
if (cssString) {
|
|
101
|
+
style.replaceSync(cssString);
|
|
102
|
+
}
|
|
103
|
+
if (_ref) {
|
|
104
|
+
const adoptedStyleSheets = [...(_ref.adoptedStyleSheets || [])]
|
|
105
|
+
adoptedStyleSheets[prepend ? 'unshift' : 'push'](style);
|
|
106
|
+
|
|
107
|
+
_ref.adoptedStyleSheets = adoptedStyleSheets;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return style;
|
|
111
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createBaseClass } from '../../baseClasses';
|
|
2
2
|
import { isFunction } from '../../utils';
|
|
3
|
-
import { forwardProps, syncAttrs } from '../../componentsHelpers';
|
|
3
|
+
import { forwardProps, injectStyle, syncAttrs } from '../../componentsHelpers';
|
|
4
4
|
import { createDispatchEvent } from '../../componentsMixins/helpers/mixinsHelpers';
|
|
5
5
|
|
|
6
6
|
export const createProxy = ({
|
|
@@ -20,7 +20,6 @@ export const createProxy = ({
|
|
|
20
20
|
|
|
21
21
|
constructor() {
|
|
22
22
|
super().attachShadow({ mode: 'open', delegatesFocus }).innerHTML = `
|
|
23
|
-
<style id="create-proxy">${(isFunction(style) ? style() : style) || ''}</style>
|
|
24
23
|
<${wrappedEleName}>
|
|
25
24
|
${slots
|
|
26
25
|
.map(
|
|
@@ -31,6 +30,8 @@ export const createProxy = ({
|
|
|
31
30
|
.join('')}
|
|
32
31
|
</${wrappedEleName}>
|
|
33
32
|
`;
|
|
33
|
+
|
|
34
|
+
injectStyle((isFunction(style) ? style() : style) || '', this);
|
|
34
35
|
}
|
|
35
36
|
|
|
36
37
|
init() {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BASE_THEME_SECTION, CSS_SELECTOR_SPECIFIER_MULTIPLY } from '../../../constants';
|
|
2
2
|
import { kebabCaseJoin } from '../../../utils';
|
|
3
|
-
import { getCssVarName, observeAttributes } from '../../../componentsHelpers';
|
|
3
|
+
import { getCssVarName, injectStyle, observeAttributes } from '../../../componentsHelpers';
|
|
4
4
|
import { componentsThemeManager } from '../../../themeHelpers';
|
|
5
5
|
import { createStyle, createCssVarsList, createClassSelectorSpecifier } from './helpers';
|
|
6
6
|
|
|
@@ -65,13 +65,11 @@ export const createStyleMixin =
|
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
#onComponentThemeChange() {
|
|
68
|
-
this.#themeStyleEle.
|
|
68
|
+
this.#themeStyleEle.replaceSync(this.#componentTheme[this.#themeSection]);
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
#createComponentTheme() {
|
|
72
|
-
this.#themeStyleEle =
|
|
73
|
-
this.#themeStyleEle.id = `style-mixin-theme__${componentName}`;
|
|
74
|
-
this.#rootElement.prepend(this.#themeStyleEle);
|
|
72
|
+
this.#themeStyleEle = injectStyle('', this.#rootElement, { prepend: true });
|
|
75
73
|
this.#disconnectThemeManager = componentsThemeManager.onCurrentThemeChange(
|
|
76
74
|
this.#onComponentThemeChange.bind(this)
|
|
77
75
|
);
|
|
@@ -80,21 +78,18 @@ export const createStyleMixin =
|
|
|
80
78
|
|
|
81
79
|
#createOverridesStyle() {
|
|
82
80
|
if (this.#styleAttributes.length) {
|
|
83
|
-
this.#overrideStyleEle = document.createElement('style');
|
|
84
|
-
this.#overrideStyleEle.id = `style-mixin-overrides__${componentName}`;
|
|
85
|
-
|
|
86
81
|
const classSpecifier = createClassSelectorSpecifier(
|
|
87
82
|
componentName,
|
|
88
83
|
CSS_SELECTOR_SPECIFIER_MULTIPLY
|
|
89
84
|
);
|
|
90
85
|
|
|
91
|
-
this.#overrideStyleEle
|
|
92
|
-
this.#rootElement.append(this.#overrideStyleEle);
|
|
86
|
+
this.#overrideStyleEle = injectStyle(`:host(${classSpecifier}) {}`, this.#rootElement);
|
|
93
87
|
}
|
|
94
88
|
}
|
|
95
89
|
|
|
96
90
|
#setAttrOverride(attrName, value) {
|
|
97
|
-
const style = this.#overrideStyleEle?.
|
|
91
|
+
const style = this.#overrideStyleEle?.cssRules[0].style;
|
|
92
|
+
|
|
98
93
|
if (!style) return;
|
|
99
94
|
|
|
100
95
|
const varName = getCssVarName(
|
|
@@ -110,31 +105,22 @@ export const createStyleMixin =
|
|
|
110
105
|
}
|
|
111
106
|
|
|
112
107
|
#updateOverridesStyle(attrs = []) {
|
|
113
|
-
let shouldUpdate = false;
|
|
114
|
-
|
|
115
108
|
attrs.forEach((attr) => {
|
|
116
109
|
if (this.#styleAttributes.includes(attr)) {
|
|
117
110
|
this.#setAttrOverride(attr, this.getAttribute(attr));
|
|
118
|
-
shouldUpdate = true;
|
|
119
111
|
}
|
|
120
112
|
});
|
|
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
113
|
}
|
|
127
114
|
|
|
128
115
|
#createMappingStyle() {
|
|
129
116
|
if (Object.keys(mappings).length) {
|
|
130
|
-
const
|
|
131
|
-
themeStyle.id = `style-mixin-mappings__${componentName}`;
|
|
132
|
-
themeStyle.innerHTML = createStyle(
|
|
117
|
+
const style = createStyle(
|
|
133
118
|
kebabCaseJoin(componentName, this.#componentNameSuffix),
|
|
134
119
|
this.#baseSelector,
|
|
135
120
|
mappings
|
|
136
121
|
);
|
|
137
|
-
|
|
122
|
+
|
|
123
|
+
injectStyle(style, this.#rootElement, { prepend: true });
|
|
138
124
|
}
|
|
139
125
|
}
|
|
140
126
|
|
package/src/sbHelpers.js
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
export const withForm = (children) => {
|
|
2
2
|
return `
|
|
3
|
+
<style nonce="${window.DESCOPE_NONCE}">
|
|
4
|
+
.form-actions {
|
|
5
|
+
margin-top: 6em
|
|
6
|
+
}
|
|
7
|
+
</style>
|
|
3
8
|
<form onsubmit="event.preventDefault()">
|
|
4
9
|
<div>${children}</div>
|
|
5
|
-
<div
|
|
10
|
+
<div class="form-actions">
|
|
6
11
|
<button type="submit" data-testid="submit-button">Submit</button>
|
|
7
12
|
</div>
|
|
8
13
|
</form>
|