@pageboard/html 0.14.22 → 0.14.24

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/elements/form.js CHANGED
@@ -192,6 +192,6 @@ exports.api_form = {
192
192
  scripts: [ // for asynchronous submits and automatic triggers
193
193
  '../ui/form.js'
194
194
  ],
195
- polyfills: ['fetch']
195
+ polyfills: ['fetch', 'FormDataSubmitter']
196
196
  };
197
197
 
@@ -56,7 +56,7 @@ exports.breadcrumb = {
56
56
  group: "block",
57
57
  html: `<nav class="ui breadcrumb">
58
58
  <div class="divider"></div>
59
- <a href="[$links.up|nth:-1|at:a::1|repeat:link]" class="section">[link.title]</a>
59
+ <a href="[$links.up|nth:-1|at:a::1|repeat:link|.url]" class="section">[link.title]</a>
60
60
  <div class="divider"></div>
61
61
  <div class="active section">[$page.content.title|fail:div::1]</div>
62
62
  </nav>`,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pageboard/html",
3
- "version": "0.14.22",
3
+ "version": "0.14.24",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "repository": {
@@ -4,7 +4,7 @@ class HTMLElementFieldsetList extends Page.Element {
4
4
  #prefix;
5
5
  #model;
6
6
 
7
- fill(values) {
7
+ fill(values = {}) {
8
8
  if (this.isContentEditable || this.prefix == null) return;
9
9
  const vars = [];
10
10
  for (const [key, val] of Object.entries(values)) {
@@ -25,6 +25,12 @@ class HTMLElementFieldsetList extends Page.Element {
25
25
  this.#resize();
26
26
  return vars;
27
27
  }
28
+ patch(state) {
29
+ // initialize
30
+ if (this.ownView.children.length == 0) {
31
+ this.#resize();
32
+ }
33
+ }
28
34
 
29
35
  reset() {
30
36
  this.#list = this.#defaultList?.slice();
@@ -142,7 +148,7 @@ class HTMLElementFieldsetList extends Page.Element {
142
148
  );
143
149
  const min = Number(this.dataset.min) || 0;
144
150
  const max = Number(this.dataset.max) || Infinity;
145
- let list = this.#list;
151
+ let list = this.#list ??= [];
146
152
  const placeholder = list.length == 0 && min == 0;
147
153
  if (list.length == 0) {
148
154
  list = [{...this.#model, $i: min == 0 ? -1 : 0}];
@@ -164,28 +170,28 @@ class HTMLElementFieldsetList extends Page.Element {
164
170
  }
165
171
  });
166
172
 
167
- const view = this.ownView;
168
- view.textContent = '';
169
- view.appendChild(tpl);
170
-
171
173
  if (placeholder) {
172
- for (const node of view.querySelectorAll(`[name^="${this.#prefixStr}"]`)) {
174
+ for (const node of tpl.querySelectorAll(`[name^="${this.#prefixStr}"]`)) {
173
175
  node.disabled = true;
174
176
  }
175
177
  }
176
178
 
177
- view.querySelectorAll(this.#selector('up')).forEach((node, i) => {
179
+ tpl.querySelectorAll(this.#selector('up')).forEach((node, i) => {
178
180
  node.disabled = i == 0;
179
181
  });
180
- view.querySelectorAll(this.#selector('down')).forEach((node, i, arr) => {
182
+ tpl.querySelectorAll(this.#selector('down')).forEach((node, i, arr) => {
181
183
  node.disabled = i == arr.length - 1;
182
184
  });
183
- view.querySelectorAll(this.#selector('del')).forEach((node) => {
184
- node.disabled = this.#list.length <= min;
185
+ tpl.querySelectorAll(this.#selector('del')).forEach((node) => {
186
+ node.disabled = list.length <= min;
185
187
  });
186
- view.querySelectorAll(this.#selector('add')).forEach((node) => {
187
- node.disabled = this.#list.length >= max;
188
+ tpl.querySelectorAll(this.#selector('add')).forEach((node) => {
189
+ node.disabled = list.length >= max;
188
190
  });
191
+
192
+ const view = this.ownView;
193
+ view.textContent = '';
194
+ view.appendChild(tpl);
189
195
  }
190
196
 
191
197
  #parts(key) {
package/ui/fieldset.js CHANGED
@@ -13,8 +13,23 @@ class HTMLElementFieldSet extends Page.create(HTMLFieldSetElement) {
13
13
 
14
14
  fill(query) {
15
15
  if (this.isContentEditable || !this.options?.name || !this.form) return;
16
- if (!query) query = this.form.read(true);
17
- const val = query[this.options.name];
16
+ const { name } = this.options;
17
+ if (!query) {
18
+ query = {};
19
+ for (const node of this.form.querySelectorAll(
20
+ `[name="${name}"]`
21
+ )) {
22
+ if (node.type == "checkbox") {
23
+ throw new Error("Unsupported checkbox in fiedset condition: " + this.options.name);
24
+ }
25
+ if (node.type == "radio") {
26
+ if (node.checked) query[name] = node.value;
27
+ } else {
28
+ query[name] = node.value;
29
+ }
30
+ }
31
+ }
32
+ const val = query[name];
18
33
  const disabled = this.disabled = this.hidden = !this.#compare(val);
19
34
  for (const node of this.querySelectorAll('[name]')) {
20
35
  node.disabled = disabled;
@@ -22,13 +37,12 @@ class HTMLElementFieldSet extends Page.create(HTMLFieldSetElement) {
22
37
  }
23
38
 
24
39
  patch(state) {
25
- // before/after form#fill
26
- this.fill(null);
27
- state.finish(() => this.fill(null));
40
+ // initialize
41
+ this.fill();
28
42
  }
29
43
  handleAllChange(e, state) {
30
44
  if (this.form?.contains(e.target)) {
31
- this.fill(null);
45
+ this.fill();
32
46
  }
33
47
  }
34
48
  }
package/ui/form.js CHANGED
@@ -112,8 +112,8 @@ class HTMLElementForm extends Page.create(HTMLFormElement) {
112
112
  state.dispatch(this, 'submit');
113
113
  });
114
114
  }
115
- read(withDefaults = false) {
116
- const fd = new FormData(this);
115
+ read(withDefaults = false, submitter) {
116
+ const fd = new FormData(this, submitter);
117
117
  const query = {};
118
118
  fd.forEach((val, key) => {
119
119
  if (val == "") val = null;
@@ -182,12 +182,6 @@ class HTMLElementForm extends Page.create(HTMLFormElement) {
182
182
  }
183
183
  }
184
184
  }
185
- // FIXME use e.submitter polyfill when available
186
- // https://github.com/Financial-Times/polyfill-library/issues/1111
187
- const btn = document.activeElement;
188
- if (btn && btn.type == "submit" && btn.name && btn.value) {
189
- query[btn.name] = btn.value;
190
- }
191
185
  return query;
192
186
  }
193
187
  fill(query) {
@@ -295,7 +289,7 @@ class HTMLElementForm extends Page.create(HTMLFormElement) {
295
289
  getMethod(e, state) {
296
290
  const redirect = this.getAttribute('action');
297
291
  const loc = Page.parse(redirect);
298
- Object.assign(loc.query, this.read(false));
292
+ Object.assign(loc.query, this.read(false, e.submitter));
299
293
  if (loc.samePathname(state)) {
300
294
  loc.query = { ...state.query, ...loc.query };
301
295
  }