@descope-ui/common 3.7.0 → 3.7.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@descope-ui/common",
3
- "version": "3.7.0",
3
+ "version": "3.7.2",
4
4
  "files": [
5
5
  "src"
6
6
  ],
@@ -30,6 +30,8 @@ export const observeAttributes = (
30
30
  });
31
31
 
32
32
  observer.observe(ele, { attributes: true });
33
+
34
+ return { disconnect: () => observer.disconnect() };
33
35
  };
34
36
 
35
37
  // calling the callback with this object: { addedNodes, removedNodes }
@@ -79,13 +81,12 @@ export const getComponentName = (name) => kebabCaseJoin(DESCOPE_PREFIX, name);
79
81
 
80
82
  export const getCssVarName = (...args) => `--${kebabCaseJoin(...args)}`;
81
83
 
82
- export const forwardAttrs = (source, dest, options = {}) => {
84
+ export const forwardAttrs = (source, dest, options = {}) =>
83
85
  observeAttributes(
84
86
  source,
85
87
  createSyncAttrsCb(source, dest, options.mapAttrs),
86
88
  options,
87
89
  );
88
- };
89
90
 
90
91
  export const forwardProps = (src, target, props = []) => {
91
92
  if (!props.length) return;
@@ -98,7 +99,6 @@ export const forwardProps = (src, target, props = []) => {
98
99
  return src[prop];
99
100
  },
100
101
  set(v) {
101
- // eslint-disable-next-line no-param-reassign
102
102
  src[prop] = v;
103
103
  },
104
104
  },
@@ -113,8 +113,9 @@ export const injectStyle = (cssString, ref, { prepend = false } = {}) => {
113
113
  let style;
114
114
 
115
115
  try {
116
+ // eslint-disable-next-line no-undef
116
117
  style = new CSSStyleSheet();
117
- } catch (e) {
118
+ } catch {
118
119
  // fallback for browsers that don't support CSSStyleSheet
119
120
  return generateStyleTagFallback(cssString, ref, { prepend });
120
121
  }
@@ -16,3 +16,4 @@ export { connectorMixin } from './connectorMixin';
16
16
  export { createDynamicDataMixin } from './createDynamicDataMixin';
17
17
  export { activeableMixin } from './activeableMixin';
18
18
  export { inputOverrideValidConstraintsMixin } from './inputOverrideValidConstraintsMixin';
19
+ export { stretchMixin } from './stretchMixin';
@@ -0,0 +1,48 @@
1
+ // stretchMixin — manages the `[stretch]` attribute as a pure layout signal.
2
+ // Consumers own the visual implementation (`:host([stretch])` CSS in their
3
+ // own init styles, theme rules, etc.).
4
+ //
5
+ // triggers — for leaf components that own a "full size" attribute.
6
+ // Each entry maps an attribute/value pair; when the attribute matches the
7
+ // value, `[stretch]` is toggled on the host.
8
+ // Example: stretchMixin({ triggers: [{ attr: 'full-width', value: 'true' }] })
9
+ // Use on components like descope-button that expose a full-width prop.
10
+ //
11
+ // Propagating `[stretch]` from slotted children (e.g. for anchored components)
12
+ // is the consumer's responsibility. descope-anchored implements this correctly
13
+ // via per-anchor MutationObservers on assignedElements({ flatten: true }),
14
+ // which also handles React props set after init.
15
+
16
+ export const stretchMixin =
17
+ ({ triggers = [] } = {}) =>
18
+ (superclass) =>
19
+ class StretchMixinClass extends superclass {
20
+ static get observedAttributes() {
21
+ return [
22
+ ...(superclass.observedAttributes || []),
23
+ ...triggers.map(({ attr }) => attr),
24
+ ];
25
+ }
26
+
27
+ get #shouldStretch() {
28
+ return triggers.some(
29
+ ({ attr, value }) => this.getAttribute(attr) === value,
30
+ );
31
+ }
32
+
33
+ #syncStretch = () => {
34
+ this.toggleAttribute('stretch', this.#shouldStretch);
35
+ };
36
+
37
+ attributeChangedCallback(name, oldVal, newVal) {
38
+ super.attributeChangedCallback?.(name, oldVal, newVal);
39
+ if (oldVal !== newVal) {
40
+ this.#syncStretch();
41
+ }
42
+ }
43
+
44
+ init() {
45
+ super.init?.();
46
+ this.#syncStretch();
47
+ }
48
+ };