@descope-ui/common 0.0.14 → 0.0.16

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,10 @@
2
2
 
3
3
  This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
4
4
 
5
+ ## [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)
6
+
7
+ ## [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)
8
+
5
9
  ## [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
10
 
7
11
  ## [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.16",
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,14 @@ export const createDynamicDataMixin =
30
31
  validateSchema = defaultValidateSchema,
31
32
  slotName,
32
33
  rerenderAttrsList = [],
34
+ targetSelector,
33
35
  }) =>
34
36
  (superclass) =>
35
37
  class DynamicDataMixinClass extends superclass {
36
38
  #data = [];
37
39
 
40
+ #targetEle;
41
+
38
42
  // eslint-disable-next-line class-methods-use-this
39
43
  #validateSchema(data) {
40
44
  if (!validateSchema) return true;
@@ -50,14 +54,18 @@ export const createDynamicDataMixin =
50
54
 
51
55
  #removeOldItems() {
52
56
  const selector = slotName ? `*[slot="${slotName}"]` : ':not([slot])';
53
- this.baseElement.querySelectorAll(selector).forEach((item) => item.remove());
57
+ if (!this.#targetEle) return;
58
+ this.#targetEle
59
+ .querySelectorAll(selector)
60
+ .forEach((item) => item.remove());
54
61
  }
55
62
 
56
63
  #renderItems() {
57
64
  this.#removeOldItems();
58
65
  this.data.forEach((item, index) => {
59
66
  const content = getTemplateContent(itemRenderer(item, index, this));
60
- this.baseElement.appendChild(content?.cloneNode(true));
67
+ if (!this.#targetEle) return;
68
+ this.#targetEle.appendChild(content?.cloneNode(true));
61
69
  });
62
70
  }
63
71
 
@@ -75,13 +83,17 @@ export const createDynamicDataMixin =
75
83
  init() {
76
84
  super.init?.();
77
85
 
86
+ this.#targetEle = targetSelector
87
+ ? this.shadowRoot.querySelector(targetSelector)
88
+ : this.baseElement;
89
+
78
90
  observeAttributes(
79
91
  this,
80
92
  (attrs) => {
81
93
  if (attrs.includes('data')) this.#handleDataAttr();
82
94
  else this.#renderItems();
83
95
  },
84
- { includeAttrs: [...rerenderAttrsList, 'data'] }
96
+ { includeAttrs: [...rerenderAttrsList, 'data'] },
85
97
  );
86
98
  }
87
99
 
@@ -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';