@dile/crud 2.2.1 → 2.2.3

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.
@@ -153,6 +153,26 @@ describe('dile-ajax-select-crud-overlay', () => {
153
153
  });
154
154
  });
155
155
 
156
+ describe('Icons (inherited from dile-select-ajax-overlay)', () => {
157
+ it('propagates iconProperty and icon to data-icon on the generated options/select', async () => {
158
+ mockAxios([
159
+ { id: 1, name: 'Spain' },
160
+ { id: 2, name: 'France', iconName: 'material.star' },
161
+ ]);
162
+ const el = await renderCrudSelect(`
163
+ <dile-ajax-select-crud-overlay endpoint="/api/countries" idProperty="id" displayProperty="name" iconProperty="iconName" icon="lucide.globe" delay="10"></dile-ajax-select-crud-overlay>
164
+ `);
165
+
166
+ await typeKeyword(el, 'sp');
167
+
168
+ const options = el.select.options;
169
+ // Spain has no iconName of its own, so it falls back to the select-level default.
170
+ expect(options[0].icon).toBe('lucide.globe');
171
+ // France declares its own icon via iconProperty, which takes precedence.
172
+ expect(options[1].icon).toBe('material.star');
173
+ });
174
+ });
175
+
156
176
  describe('Form Association', () => {
157
177
  it('is form-associated, same as dile-select-ajax-overlay', async () => {
158
178
  mockAxios([]);
@@ -48,6 +48,15 @@ describe.each(VARIANTS)('$tag (select: $selectTag)', ({ tag, selectTag }) => {
48
48
  expect(theselect.tagName.toLowerCase()).toBe(selectTag);
49
49
  });
50
50
 
51
+ it('passes iconProperty and icon through to the internal select', async () => {
52
+ mockAxios({ get: vi.fn(() => Promise.resolve({ status: 200, data: [] })) });
53
+ const el = await renderManyRelation('iconProperty="iconName" icon="lucide.globe"');
54
+
55
+ const theselect = select(el);
56
+ expect(theselect.getAttribute('iconproperty')).toBe('iconName');
57
+ expect(theselect.getAttribute('icon')).toBe('lucide.globe');
58
+ });
59
+
51
60
  it('loads the related items list from endpointList on connect', async () => {
52
61
  const get = vi.fn(() =>
53
62
  Promise.resolve({ status: 200, data: { data: [{ id: 1, name: 'Strategy' }] } })
@@ -99,3 +108,47 @@ describe.each(VARIANTS)('$tag (select: $selectTag)', ({ tag, selectTag }) => {
99
108
  expect(del).toHaveBeenCalledWith('/api/board-games/1/tags/9', {}, undefined);
100
109
  });
101
110
  });
111
+
112
+ describe('dile-many-relation-overlay icons (only the overlay select supports them)', () => {
113
+ afterEach(() => {
114
+ document.body.innerHTML = '';
115
+ delete window.axiosInstance;
116
+ });
117
+
118
+ function wait(ms) {
119
+ return new Promise((resolve) => setTimeout(resolve, ms));
120
+ }
121
+
122
+ it('reaches the internal dile-select-overlay popup as data-icon on the generated options', async () => {
123
+ const get = vi.fn(() =>
124
+ Promise.resolve({ status: 200, data: [{ id: 1, name: 'Strategy', iconName: 'material.star' }] })
125
+ );
126
+ window.axiosInstance = { get };
127
+
128
+ document.body.innerHTML = `
129
+ <dile-many-relation-overlay
130
+ endpointGet="/api/tags"
131
+ endpointList="/api/board-games/1/tags"
132
+ endpointAdd="/api/board-games/1/tags"
133
+ endpointRemove="/api/board-games/1/tags"
134
+ idProperty="id"
135
+ displayProperty="name"
136
+ iconProperty="iconName"
137
+ icon="lucide.globe"
138
+ ></dile-many-relation-overlay>
139
+ `;
140
+ const el = document.body.querySelector('dile-many-relation-overlay');
141
+ await el.updateComplete;
142
+
143
+ const theselect = el.shadowRoot.getElementById('theselect');
144
+ const input = theselect.shadowRoot.getElementById('search');
145
+ input.value = 'str';
146
+ input.dispatchEvent(new Event('input', { bubbles: true }));
147
+ await wait(theselect.delay + 50);
148
+ await theselect.updateComplete;
149
+
150
+ const options = theselect.select.options;
151
+ // Only result has its own iconName, taking precedence over the select-level default.
152
+ expect(options[0].icon).toBe('material.star');
153
+ });
154
+ });
@@ -110,6 +110,14 @@ export class DileManyRelation extends DileI18nMixin(LitElement) {
110
110
  maxResults: { type: Number },
111
111
  pageParamName: { type: String },
112
112
  getSelectResultList: { type: Object },
113
+ /** Property in each result item holding a dile-iconlib "family.name" icon string, shown
114
+ * next to that option. Only has an effect when the internal select is
115
+ * dile-ajax-select-crud-overlay (i.e. on dile-many-relation-overlay) — the native-select-based
116
+ * dile-ajax-select-crud can't show icons. */
117
+ iconProperty: { type: String },
118
+ /** dile-iconlib "family.name" icon string used as the default icon for every option that
119
+ * doesn't have its own via iconProperty. Same dile-many-relation-overlay-only caveat as iconProperty. */
120
+ icon: { type: String },
113
121
 
114
122
  // Related list customisation
115
123
  itemTemplate: { type: Object },
@@ -202,6 +210,8 @@ export class DileManyRelation extends DileI18nMixin(LitElement) {
202
210
  maxResults="${this.maxResults}"
203
211
  pageParamName="${this.pageParamName}"
204
212
  .getSelectResultList="${this.getSelectResultList}"
213
+ iconProperty="${this.iconProperty}"
214
+ icon="${this.icon}"
205
215
  language="${this.language}"
206
216
  @element-changed="${this._onSelectChanged}"
207
217
  ></${selectTag}>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dile/crud",
3
- "version": "2.2.1",
3
+ "version": "2.2.3",
4
4
  "description": "Components to create a generic crud system based on Web Components and Lit",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -25,12 +25,12 @@
25
25
  },
26
26
  "homepage": "https://dile-components.com/",
27
27
  "dependencies": {
28
- "@dile/ui": "^3.5.1",
28
+ "@dile/ui": "^3.5.3",
29
29
  "axios": "^1.19.0",
30
30
  "lit": "^2.7.0 || ^3.0.0"
31
31
  },
32
32
  "publishConfig": {
33
33
  "access": "public"
34
34
  },
35
- "gitHead": "7bcf203fb23acc24867e9f3df4f3ca2367eabd97"
35
+ "gitHead": "e9fe84bbbcc552ccf6045190ee0f034dfdb06412"
36
36
  }