@skirbi/sugar 0.0.22 → 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 CHANGED
@@ -1,5 +1,9 @@
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
+
3
7
  0.0.22 2026-05-28 03:45:56Z
4
8
 
5
9
  * Fix htmlelementsugar-select for using native options
@@ -98,40 +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
- const searchEl = frag.querySelector('[skirbi-search]');
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
- }
119
- else if (hasEndpoint) {
120
- this._setupRemote(select, searchEl, cfg);
121
- }
122
- else {
123
- const authoredOptions = Array.from(this.children)
124
- .filter((node) => node.matches?.('option,optgroup'));
125
-
126
- for (const option of authoredOptions) {
127
- select.appendChild(option);
128
- }
129
- }
130
-
131
-
132
-
133
- // Apply initial value after options exist.
134
- if (cfg.value != null && cfg.value !== '') select.value = String(cfg.value);
102
+ this.setupSelectControl(frag);
135
103
 
136
104
  this.replaceChildren(frag);
137
105
  }
@@ -164,6 +132,47 @@ export class HTMLElementSugarSelect extends HTMLElementSugarInput {
164
132
  }
165
133
  }
166
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
+
167
176
  // TODO: getByPath(x, json) might want to return a console.warn when it
168
177
  // returns undefined. This would help developers spot mistakes? Yes/no/maybe?
169
178
 
@@ -232,7 +241,7 @@ export class HTMLElementSugarSelect extends HTMLElementSugarInput {
232
241
  const json = await res.json();
233
242
  const items = this._itemsFromJson(json, cfg);
234
243
  const opts = items.map((it) => this._mapItemToOption(it, cfg));
235
- this._setOptions(select, opts);
244
+ this._setOptions(select, opts, cfg);
236
245
 
237
246
  // search-min: hide the search UI for small results.
238
247
  if (searchEl && cfg['search-min'] > 0) {
package/lib/index.mjs CHANGED
@@ -2,7 +2,7 @@
2
2
  //
3
3
  // SPDX-License-Identifier: MIT
4
4
 
5
- const VERSION = "0.0.22";
5
+ const VERSION = "0.0.23";
6
6
 
7
7
  export { HTMLElementSugar } from './htmlelement.mjs';
8
8
  export { HTMLElementSugarInput } from './htmlelement-input.mjs';
package/package.json CHANGED
@@ -52,5 +52,5 @@
52
52
  },
53
53
  "sideEffects": false,
54
54
  "type": "module",
55
- "version": "0.0.22"
55
+ "version": "0.0.23"
56
56
  }