@descope-ui/common 0.0.14 → 0.0.15

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,8 @@
2
2
 
3
3
  This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
4
4
 
5
+ ## [0.0.15](https://github.com/descope/web-components-ui/compare/@descope-ui/common-0.0.14...@descope-ui/common-0.0.15) (2025-06-29)
6
+
5
7
  ## [0.0.14](https://github.com/descope/web-components-ui/compare/@descope-ui/common-0.0.13...@descope-ui/common-0.0.14) (2025-06-26)
6
8
 
7
9
  ## [0.0.13](https://github.com/descope/web-components-ui/compare/@descope-ui/common-0.0.12...@descope-ui/common-0.0.13) (2025-06-09)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@descope-ui/common",
3
- "version": "0.0.14",
3
+ "version": "0.0.15",
4
4
  "dependencies": {
5
5
  "element-internals-polyfill": "^1.3.9",
6
6
  "color": "^4.2.3",
@@ -1,7 +1,8 @@
1
- import { observeAttributes } from '../helpers/componentHelpers';
1
+ import { observeAttributes } from '../../componentsHelpers';
2
2
 
3
3
  const defaultValidateSchema = () => true;
4
- const defaultItemRenderer = (item) => `<pre>${JSON.stringify(item, null, 4)}</pre>`;
4
+ const defaultItemRenderer = (item) =>
5
+ `<pre>${JSON.stringify(item, null, 4)}</pre>`;
5
6
 
6
7
  const createTemplate = (templateString) => {
7
8
  const template = document.createElement('template');
@@ -30,11 +31,15 @@ export const createDynamicDataMixin =
30
31
  validateSchema = defaultValidateSchema,
31
32
  slotName,
32
33
  rerenderAttrsList = [],
34
+ targetSelector,
35
+ sortFn
33
36
  }) =>
34
37
  (superclass) =>
35
38
  class DynamicDataMixinClass extends superclass {
36
39
  #data = [];
37
40
 
41
+ #targetEle;
42
+
38
43
  // eslint-disable-next-line class-methods-use-this
39
44
  #validateSchema(data) {
40
45
  if (!validateSchema) return true;
@@ -50,20 +55,24 @@ export const createDynamicDataMixin =
50
55
 
51
56
  #removeOldItems() {
52
57
  const selector = slotName ? `*[slot="${slotName}"]` : ':not([slot])';
53
- this.baseElement.querySelectorAll(selector).forEach((item) => item.remove());
58
+ if (!this.#targetEle) return;
59
+ this.#targetEle
60
+ .querySelectorAll(selector)
61
+ .forEach((item) => item.remove());
54
62
  }
55
63
 
56
64
  #renderItems() {
57
65
  this.#removeOldItems();
58
66
  this.data.forEach((item, index) => {
59
67
  const content = getTemplateContent(itemRenderer(item, index, this));
60
- this.baseElement.appendChild(content?.cloneNode(true));
68
+ if (!this.#targetEle) return;
69
+ this.#targetEle.appendChild(content?.cloneNode(true));
61
70
  });
62
71
  }
63
72
 
64
73
  set data(value) {
65
74
  if (this.#validateSchema(value)) {
66
- this.#data = value;
75
+ this.#data = sortFn ? value.sort(sortFn) : value;
67
76
  this.#renderItems();
68
77
  }
69
78
  }
@@ -75,13 +84,17 @@ export const createDynamicDataMixin =
75
84
  init() {
76
85
  super.init?.();
77
86
 
87
+ this.#targetEle = targetSelector
88
+ ? this.shadowRoot.querySelector(targetSelector)
89
+ : this.baseElement;
90
+
78
91
  observeAttributes(
79
92
  this,
80
93
  (attrs) => {
81
94
  if (attrs.includes('data')) this.#handleDataAttr();
82
95
  else this.#renderItems();
83
96
  },
84
- { includeAttrs: [...rerenderAttrsList, 'data'] }
97
+ { includeAttrs: [...rerenderAttrsList, 'data'] },
85
98
  );
86
99
  }
87
100
 
@@ -13,3 +13,4 @@ export { inputEventsDispatchingMixin } from './inputEventsDispatchingMixin';
13
13
  export { externalInputMixin } from './externalInputMixin';
14
14
  export { componentsContextMixin } from './componentsContextMixin';
15
15
  export { connectorMixin } from './connectorMixin';
16
+ export { createDynamicDataMixin } from './createDynamicDataMixin';