@descope-ui/common 0.0.17 → 0.1.0

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 CHANGED
@@ -2,6 +2,15 @@
2
2
 
3
3
  This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
4
4
 
5
+ ## [0.1.0](https://github.com/descope/web-components-ui/compare/@descope-ui/common-0.0.18...@descope-ui/common-0.1.0) (2025-09-02)
6
+
7
+
8
+ ### Features
9
+
10
+ * Trusted Devices ([#697](https://github.com/descope/web-components-ui/issues/697)) ([fb2f0eb](https://github.com/descope/web-components-ui/commit/fb2f0eb6773ed624354ed9f0b97d713bb8b10fce))
11
+
12
+ ## [0.0.18](https://github.com/descope/web-components-ui/compare/@descope-ui/common-0.0.17...@descope-ui/common-0.0.18) (2025-07-21)
13
+
5
14
  ## [0.0.17](https://github.com/descope/web-components-ui/compare/@descope-ui/common-0.0.16...@descope-ui/common-0.0.17) (2025-07-15)
6
15
 
7
16
  ## [0.0.16](https://github.com/descope/web-components-ui/compare/@descope-ui/common-0.0.15...@descope-ui/common-0.0.16) (2025-06-30)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@descope-ui/common",
3
- "version": "0.0.17",
3
+ "version": "0.1.0",
4
4
  "dependencies": {
5
5
  "element-internals-polyfill": "^1.3.9",
6
6
  "color": "^4.2.3",
@@ -1,13 +1,17 @@
1
1
  import { kebabCaseJoin } from '../utils';
2
2
  import { DESCOPE_PREFIX } from '../constants';
3
3
 
4
- export const observeAttributes = (ele, callback, { excludeAttrs = [], includeAttrs = [] }) => {
4
+ export const observeAttributes = (
5
+ ele,
6
+ callback,
7
+ { excludeAttrs = [], includeAttrs = [] },
8
+ ) => {
5
9
  // sync all attrs on init
6
10
  const filteredAttrs = Array.from(ele.attributes)
7
11
  .filter(
8
12
  (attr) =>
9
13
  !excludeAttrs.includes(attr.name) &&
10
- (!includeAttrs.length || includeAttrs.includes(attr.name))
14
+ (!includeAttrs.length || includeAttrs.includes(attr.name)),
11
15
  )
12
16
  .map((attr) => attr.name);
13
17
 
@@ -40,24 +44,28 @@ export const observeChildren = (ele, callback) => {
40
44
  });
41
45
  });
42
46
 
43
- observer.observe(ele, { childList: true, characterData: true, subtree: true });
47
+ observer.observe(ele, {
48
+ childList: true,
49
+ characterData: true,
50
+ subtree: true,
51
+ });
44
52
  };
45
53
 
46
54
  const createSyncAttrsCb =
47
55
  (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);
56
+ (attrNames) => {
57
+ attrNames.forEach((attrName) => {
58
+ const targetAttrName = mapAttrs[attrName] || attrName;
59
+ const srcAttrVal = srcEle.getAttribute(attrName);
60
+ if (srcAttrVal !== null) {
61
+ if (targetEle.getAttribute(targetAttrName) !== srcAttrVal) {
62
+ targetEle.setAttribute(targetAttrName, srcAttrVal);
58
63
  }
59
- });
60
- };
64
+ } else {
65
+ targetEle.removeAttribute(targetAttrName);
66
+ }
67
+ });
68
+ };
61
69
 
62
70
  export const syncAttrs = (ele1, ele2, options) => {
63
71
  observeAttributes(ele1, createSyncAttrsCb(ele1, ele2), options);
@@ -69,7 +77,11 @@ export const getComponentName = (name) => kebabCaseJoin(DESCOPE_PREFIX, name);
69
77
  export const getCssVarName = (...args) => `--${kebabCaseJoin(...args)}`;
70
78
 
71
79
  export const forwardAttrs = (source, dest, options = {}) => {
72
- observeAttributes(source, createSyncAttrsCb(source, dest, options.mapAttrs), options);
80
+ observeAttributes(
81
+ source,
82
+ createSyncAttrsCb(source, dest, options.mapAttrs),
83
+ options,
84
+ );
73
85
  };
74
86
 
75
87
  export const forwardProps = (src, target, props = []) => {
@@ -88,14 +100,13 @@ export const forwardProps = (src, target, props = []) => {
88
100
  },
89
101
  },
90
102
  }),
91
- {}
103
+ {},
92
104
  );
93
105
 
94
106
  Object.defineProperties(target, config);
95
107
  };
96
108
 
97
109
  export const injectStyle = (cssString, ref, { prepend = false } = {}) => {
98
-
99
110
  let style;
100
111
  try {
101
112
  style = new CSSStyleSheet();
@@ -109,14 +120,14 @@ export const injectStyle = (cssString, ref, { prepend = false } = {}) => {
109
120
  style.replaceSync(cssString);
110
121
  }
111
122
  if (_ref) {
112
- const adoptedStyleSheets = [...(_ref.adoptedStyleSheets || [])]
123
+ const adoptedStyleSheets = [...(_ref.adoptedStyleSheets || [])];
113
124
  adoptedStyleSheets[prepend ? 'unshift' : 'push'](style);
114
125
 
115
126
  _ref.adoptedStyleSheets = adoptedStyleSheets;
116
127
  }
117
128
 
118
129
  return style;
119
- }
130
+ };
120
131
 
121
132
  // we should mimic the CSSStyleSheet API for the fns we are using
122
133
  class CSSStyleSheetMock {
@@ -127,7 +138,7 @@ class CSSStyleSheetMock {
127
138
  this.ref = ref?.shadowRoot || ref;
128
139
 
129
140
  if (!this.ref) {
130
- return
141
+ return;
131
142
  }
132
143
 
133
144
  if (prepend) {
@@ -146,4 +157,13 @@ class CSSStyleSheetMock {
146
157
  }
147
158
  }
148
159
 
149
- const generateStyleTagFallback = (cssString, ref, { prepend = false } = {}) => new CSSStyleSheetMock(cssString, ref, { prepend });
160
+ const generateStyleTagFallback = (cssString, ref, { prepend = false } = {}) =>
161
+ new CSSStyleSheetMock(cssString, ref, { prepend });
162
+
163
+ export const limitAbbreviation = (str, limit = 2) =>
164
+ str
165
+ .trim()
166
+ .split(' ')
167
+ .splice(0, limit)
168
+ .map((s) => s[0]?.toUpperCase())
169
+ .join('');
@@ -32,6 +32,7 @@ export const createDynamicDataMixin =
32
32
  slotName,
33
33
  rerenderAttrsList = [],
34
34
  targetSelector,
35
+ sortFn = (data) => data,
35
36
  }) =>
36
37
  (superclass) =>
37
38
  class DynamicDataMixinClass extends superclass {
@@ -62,7 +63,8 @@ export const createDynamicDataMixin =
62
63
 
63
64
  #renderItems() {
64
65
  this.#removeOldItems();
65
- this.data.forEach((item, index) => {
66
+ const items = sortFn ? this.data.sort(sortFn) : this.data;
67
+ items.forEach((item, index) => {
66
68
  const content = getTemplateContent(itemRenderer(item, index, this));
67
69
  if (!this.#targetEle) return;
68
70
  this.#targetEle.appendChild(content?.cloneNode(true));
@@ -14,3 +14,4 @@ export { externalInputMixin } from './externalInputMixin';
14
14
  export { componentsContextMixin } from './componentsContextMixin';
15
15
  export { connectorMixin } from './connectorMixin';
16
16
  export { createDynamicDataMixin } from './createDynamicDataMixin';
17
+ export { activeableMixin } from './activeableMixin';