@skirbi/sugar 0.0.21 → 0.0.23
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/Changes +8 -0
- package/lib/htmlelement-select.mjs +43 -23
- package/lib/index.mjs +1 -1
- package/package.json +1 -1
package/Changes
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
Revision history for @skirbi/sugar
|
|
2
2
|
|
|
3
|
+
0.0.23 2026-05-28 03:53:52Z
|
|
4
|
+
|
|
5
|
+
* Make htmlelementsugar-select easier to override/extend
|
|
6
|
+
|
|
7
|
+
0.0.22 2026-05-28 03:45:56Z
|
|
8
|
+
|
|
9
|
+
* Fix htmlelementsugar-select for using native options
|
|
10
|
+
|
|
3
11
|
0.0.21 2026-05-10 02:05:46Z
|
|
4
12
|
|
|
5
13
|
* Add `$()` and `$$()` selector helpers to HTMLElementSugar.
|
|
@@ -98,29 +98,8 @@ export class HTMLElementSugarSelect extends HTMLElementSugarInput {
|
|
|
98
98
|
this._rendered = true;
|
|
99
99
|
|
|
100
100
|
const frag = this.renderFromTemplate();
|
|
101
|
-
const cfg = this.getConfig();
|
|
102
101
|
|
|
103
|
-
|
|
104
|
-
const select = this.enhanceControl(frag);
|
|
105
|
-
|
|
106
|
-
const hasEndpoint = !!cfg.endpoint;
|
|
107
|
-
const rawOptions = cfg.options || cfg['data-options'] || '';
|
|
108
|
-
const hasStatic = !!rawOptions;
|
|
109
|
-
|
|
110
|
-
// Only show a search box if asked and there's something to search.
|
|
111
|
-
if (!(cfg.searchable && (hasEndpoint || hasStatic))) {
|
|
112
|
-
searchEl?.remove();
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
if (hasStatic) {
|
|
116
|
-
this._setOptionsFromOptions(select, rawOptions, cfg);
|
|
117
|
-
if (searchEl) this._setupLocalSearch(select, searchEl);
|
|
118
|
-
} else if (hasEndpoint) {
|
|
119
|
-
this._setupRemote(select, searchEl, cfg);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
// Apply initial value after options exist.
|
|
123
|
-
if (cfg.value != null && cfg.value !== '') select.value = String(cfg.value);
|
|
102
|
+
this.setupSelectControl(frag);
|
|
124
103
|
|
|
125
104
|
this.replaceChildren(frag);
|
|
126
105
|
}
|
|
@@ -153,6 +132,47 @@ export class HTMLElementSugarSelect extends HTMLElementSugarInput {
|
|
|
153
132
|
}
|
|
154
133
|
}
|
|
155
134
|
|
|
135
|
+
setupSelectControl(frag, cfg = this.getConfig()) {
|
|
136
|
+
const searchEl = frag.querySelector('[skirbi-search]');
|
|
137
|
+
const select = this.enhanceControl(frag);
|
|
138
|
+
|
|
139
|
+
const hasEndpoint = !!cfg.endpoint;
|
|
140
|
+
const rawOptions = cfg.options || cfg['data-options'] || '';
|
|
141
|
+
const hasStatic = !!rawOptions;
|
|
142
|
+
|
|
143
|
+
const authoredOptions = Array.from(this.children)
|
|
144
|
+
.filter((node) => node.matches?.('option,optgroup'));
|
|
145
|
+
|
|
146
|
+
const hasAuthored = authoredOptions.length > 0;
|
|
147
|
+
|
|
148
|
+
if (!(cfg.searchable && (hasEndpoint || hasStatic || hasAuthored))) {
|
|
149
|
+
searchEl?.remove();
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
if (hasStatic) {
|
|
153
|
+
this._setOptionsFromOptions(select, rawOptions, cfg);
|
|
154
|
+
if (searchEl) this._setupLocalSearch(select, searchEl);
|
|
155
|
+
}
|
|
156
|
+
else if (hasEndpoint) {
|
|
157
|
+
this._setupRemote(select, searchEl, cfg);
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
if (cfg.placeholder) this._addPlaceholder(select, cfg.placeholder);
|
|
161
|
+
|
|
162
|
+
for (const option of authoredOptions) {
|
|
163
|
+
select.appendChild(option);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
if (searchEl) this._setupLocalSearch(select, searchEl);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
if (cfg.value != null && cfg.value !== '') {
|
|
170
|
+
select.value = String(cfg.value);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
return select;
|
|
174
|
+
}
|
|
175
|
+
|
|
156
176
|
// TODO: getByPath(x, json) might want to return a console.warn when it
|
|
157
177
|
// returns undefined. This would help developers spot mistakes? Yes/no/maybe?
|
|
158
178
|
|
|
@@ -221,7 +241,7 @@ export class HTMLElementSugarSelect extends HTMLElementSugarInput {
|
|
|
221
241
|
const json = await res.json();
|
|
222
242
|
const items = this._itemsFromJson(json, cfg);
|
|
223
243
|
const opts = items.map((it) => this._mapItemToOption(it, cfg));
|
|
224
|
-
this._setOptions(select, opts);
|
|
244
|
+
this._setOptions(select, opts, cfg);
|
|
225
245
|
|
|
226
246
|
// search-min: hide the search UI for small results.
|
|
227
247
|
if (searchEl && cfg['search-min'] > 0) {
|
package/lib/index.mjs
CHANGED
package/package.json
CHANGED