mnfst 0.5.148 → 0.5.149
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/lib/manifest.combobox.js +47 -12
- package/lib/manifest.integrity.json +1 -1
- package/package.json +1 -1
package/lib/manifest.combobox.js
CHANGED
|
@@ -101,6 +101,35 @@ function initializeComboboxPlugin() {
|
|
|
101
101
|
if (el.__mnfstCombobox) return;
|
|
102
102
|
el.__mnfstCombobox = true;
|
|
103
103
|
|
|
104
|
+
// ----- Prerender hydration -----
|
|
105
|
+
// A prerendered page bakes in the wrapper this plugin generated. On load we
|
|
106
|
+
// adopt that wrapper and re-derive the selection from the baked chips, rather
|
|
107
|
+
// than nesting a second .combobox inside it (which shrinks the field and
|
|
108
|
+
// truncates the chips). A fresh SPA run has no such wrapper and skips this.
|
|
109
|
+
const adopt = el.parentElement && el.parentElement.classList.contains('combobox') ? el.parentElement : null;
|
|
110
|
+
let recoveredName = null, seedSelected = null;
|
|
111
|
+
if (adopt) {
|
|
112
|
+
seedSelected = Array.from(adopt.querySelectorAll(':scope > .combobox-chip')).map(c => ({
|
|
113
|
+
value: c.dataset.value,
|
|
114
|
+
label: (c.querySelector('span') || c).textContent.trim()
|
|
115
|
+
}));
|
|
116
|
+
const hiddens = Array.from(adopt.querySelectorAll('input[data-cb]'));
|
|
117
|
+
if (hiddens.length) {
|
|
118
|
+
recoveredName = hiddens[0].getAttribute('name');
|
|
119
|
+
if (!seedSelected.length) seedSelected = hiddens.map(h => ({ value: h.value, label: h.value }));
|
|
120
|
+
}
|
|
121
|
+
adopt.querySelectorAll('.combobox-chip, input[data-cb], [role=status]').forEach(n => n.remove());
|
|
122
|
+
const bakedMenuId = el.getAttribute('aria-controls');
|
|
123
|
+
// Remove a generated (datalist/select) menu; authored <menu> sources are the
|
|
124
|
+
// source itself and must be kept for readOptions.
|
|
125
|
+
if (bakedMenuId && bakedMenuId.indexOf('combobox-menu-') === 0) {
|
|
126
|
+
const m = document.getElementById(bakedMenuId);
|
|
127
|
+
if (m) m.remove();
|
|
128
|
+
}
|
|
129
|
+
['aria-controls', 'aria-expanded', 'aria-activedescendant', 'aria-haspopup', 'role', 'aria-autocomplete'].forEach(a => el.removeAttribute(a));
|
|
130
|
+
adopt.style.removeProperty('anchor-name');
|
|
131
|
+
}
|
|
132
|
+
|
|
104
133
|
// ----- Config: bare id string, or a { } object -----
|
|
105
134
|
let cfg = {};
|
|
106
135
|
const expr = expression.trim();
|
|
@@ -123,7 +152,7 @@ function initializeComboboxPlugin() {
|
|
|
123
152
|
const separators = cfg.separators != null
|
|
124
153
|
? String(cfg.separators).split('').filter(c => c.trim() || c === ' ')
|
|
125
154
|
: (multiple ? [','] : []);
|
|
126
|
-
const name = el.getAttribute('name');
|
|
155
|
+
const name = el.getAttribute('name') || recoveredName;
|
|
127
156
|
const placeholder = el.getAttribute('placeholder') || (editorNone ? el.textContent.trim() : '');
|
|
128
157
|
|
|
129
158
|
// ----- Source / options -----
|
|
@@ -134,14 +163,19 @@ function initializeComboboxPlugin() {
|
|
|
134
163
|
if (editorNone && !hasMenu) return; // a button trigger needs a list
|
|
135
164
|
|
|
136
165
|
// ----- Shell -----
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
166
|
+
let wrap;
|
|
167
|
+
if (adopt) {
|
|
168
|
+
wrap = adopt; // reuse the baked field (its author max-width is preserved)
|
|
169
|
+
} else {
|
|
170
|
+
wrap = document.createElement('div');
|
|
171
|
+
wrap.className = 'combobox';
|
|
172
|
+
el.parentNode.insertBefore(wrap, el);
|
|
173
|
+
wrap.appendChild(el);
|
|
174
|
+
// The wrapper IS the field, so move the author's sizing (inline style) onto
|
|
175
|
+
// it. Otherwise the editor/button is constrained inside a full-width field.
|
|
176
|
+
const authorStyle = el.getAttribute('style');
|
|
177
|
+
if (authorStyle) { wrap.setAttribute('style', authorStyle); el.removeAttribute('style'); }
|
|
178
|
+
}
|
|
145
179
|
el.setAttribute('autocomplete', 'off');
|
|
146
180
|
if (!editorNone) el.removeAttribute('placeholder');
|
|
147
181
|
if (name) el.removeAttribute('name'); // hidden inputs carry the value(s)
|
|
@@ -153,7 +187,7 @@ function initializeComboboxPlugin() {
|
|
|
153
187
|
const announce = (m) => { live.textContent = ''; live.textContent = m; };
|
|
154
188
|
|
|
155
189
|
// ----- Selection model -----
|
|
156
|
-
let selected = [];
|
|
190
|
+
let selected = adopt && seedSelected ? seedSelected : [];
|
|
157
191
|
const isSelected = (v) => selected.some(s => String(s.value).toLowerCase() === String(v).toLowerCase());
|
|
158
192
|
const atCap = () => multiple && selected.length >= max;
|
|
159
193
|
|
|
@@ -530,8 +564,9 @@ function initializeComboboxPlugin() {
|
|
|
530
564
|
});
|
|
531
565
|
}
|
|
532
566
|
|
|
533
|
-
// ----- Seed initial chips from value="a, b" (input triggers only
|
|
534
|
-
|
|
567
|
+
// ----- Seed initial chips from value="a, b" (fresh input triggers only;
|
|
568
|
+
// an adopted wrapper already provided its selection above) -----
|
|
569
|
+
if (!adopt && !editorNone && chips && el.value) {
|
|
535
570
|
const seeds = el.value.split(/[,\n;]+/).map(s => s.trim()).filter(Boolean);
|
|
536
571
|
el.value = '';
|
|
537
572
|
seeds.forEach(s => commitText(s));
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
"manifest.code.js": "sha384-nP6DncLx/UuJtloyVKMCOXwIBAq32DshTb/Lc0vVRBWX7kSbxiBnY5aEyqqvK8Kg",
|
|
7
7
|
"manifest.color.js": "sha384-6Rv3LxyTcZNjrhtayQfqRdCx0uSZ4BiEbgEI98I62eTvp8Aw7LBIoNJ0Je1oktwL",
|
|
8
8
|
"manifest.colorpicker.js": "sha384-Wqz0ZIbeIi7KarqqqSLsQk+7E/fMaKhb32hrq5/eWzX1yjqMrpPZKH8y+jZ3mfg+",
|
|
9
|
-
"manifest.combobox.js": "sha384-
|
|
9
|
+
"manifest.combobox.js": "sha384-5OTdLvqNKNPCEqbfUi15oHAK5BMYSZts/01bW2EN2RBU2JTDh+tG9tG085Jrf4xo",
|
|
10
10
|
"manifest.components.js": "sha384-mzPFoM0vqL9dnTVLMN3OrmO+KCgSqGknM1fd7bM1xzYeCco5OaZi56IMR5RS5oad",
|
|
11
11
|
"manifest.data.js": "sha384-bCYTYyAYNVkg5pSwGcoe07Dgf5B7JDN7GtOIQdS+BtrBStQwvjZtskiQ38Bncvrf",
|
|
12
12
|
"manifest.datepicker.js": "sha384-NEb/H4vuR3CFtRcodHsm3jJjrcYW2JMpDlQKlgwTrzpMMTcDkFKYXzAYJD0gZ7Ov",
|