@relax.js/core 1.0.5 → 1.0.6

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.
@@ -249,10 +249,11 @@ setFormData(form, { country: 2 }, {
249
249
  });
250
250
  ```
251
251
 
252
- The `data-source` attribute has two parts:
252
+ The `data-source` attribute has three parts:
253
253
 
254
254
  - **Source name** (required): the property on `context` to read from — `countries` above.
255
255
  - **Value and text properties** (optional): inside parentheses, separated by a comma — `(id, name)` means `item.id` is the option value and `item.name` is the option text. Without parentheses, the defaults `value` and `text` are used.
256
+ - **Group property** (optional): a third name inside the parentheses declares the property that assigns each item to an `<optgroup>` — see below.
256
257
 
257
258
  #### `data-source` as a method
258
259
 
@@ -271,6 +272,41 @@ setFormData(form, { country: 'se' }, {
271
272
  });
272
273
  ```
273
274
 
275
+ #### Grouping options into `<optgroup>`
276
+
277
+ Add a third name inside the parentheses to group items:
278
+
279
+ ```html
280
+ <select name="country" data-source="countries(id, name, region)"></select>
281
+ ```
282
+
283
+ ```typescript
284
+ setFormData(form, { country: 2 }, {
285
+ countries: [
286
+ { id: 1, name: 'Sweden', region: 'Europe' },
287
+ { id: 2, name: 'United States', region: 'Americas' },
288
+ { id: 3, name: 'Germany', region: 'Europe' }
289
+ ]
290
+ });
291
+ ```
292
+
293
+ Produces:
294
+
295
+ ```html
296
+ <select name="country">
297
+ <optgroup label="Europe">
298
+ <option value="1">Sweden</option>
299
+ <option value="3">Germany</option>
300
+ </optgroup>
301
+ <optgroup label="Americas">
302
+ <option value="2" selected>United States</option>
303
+ </optgroup>
304
+ </select>
305
+ ```
306
+
307
+ - Group order follows the order each group is first encountered in the items array.
308
+ - Items whose group property is missing, `null`, `undefined`, or an empty string are placed at the top level of the select (ungrouped).
309
+
274
310
  #### Placeholder options are preserved
275
311
 
276
312
  Options whose `value` is empty (for example a leading "Select one…") are kept when `setFormData` repopulates the list:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@relax.js/core",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "description": "Ship faster with less code. Web Component library with routing, forms, DI, templating, and i18n. No virtual DOM, no build magic, no surprise re-renders.",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",