@yuneta/gobj-ui 5.7.0 → 5.7.2

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.
@@ -5809,7 +5809,8 @@ function plan_toolbar(wanted) {
5809
5809
  return {
5810
5810
  left,
5811
5811
  right,
5812
- unknown
5812
+ unknown,
5813
+ single_group: left.length === 0 !== (right.length === 0)
5813
5814
  };
5814
5815
  }
5815
5816
  //#endregion
@@ -6013,14 +6014,20 @@ function isEventSet(table, event) {
6013
6014
  function set_changed_stated(gobj, changed) {
6014
6015
  let $container = (0, _yuneta_gobj_js.gobj_read_attr)(gobj, "$container");
6015
6016
  let $form = $container.querySelector("form");
6017
+ const enable = ($btn, on, color) => {
6018
+ if (!$btn) return;
6019
+ if (on) $btn.removeAttribute("disabled");
6020
+ else $btn.setAttribute("disabled", true);
6021
+ const $i = $btn.querySelector("span i");
6022
+ if ($i) $i.style.color = color;
6023
+ };
6024
+ const OFF_COLOR = "hsl(var(--bulma-button-h), var(--bulma-button-s), var(--bulma-button-color-l))";
6016
6025
  let $button_save = $container.querySelector(".button-save");
6017
6026
  let $button_undo = $container.querySelector(".button-undo");
6018
6027
  if (changed) {
6019
6028
  (0, _yuneta_gobj_js.gobj_write_bool_attr)(gobj, "changes", true);
6020
- $button_save.removeAttribute("disabled");
6021
- $button_undo.removeAttribute("disabled");
6022
- $button_save.querySelector("span i").style.color = "MediumSeaGreen";
6023
- $button_undo.querySelector("span i").style.color = "Magenta";
6029
+ enable($button_save, true, "MediumSeaGreen");
6030
+ enable($button_undo, true, "Magenta");
6024
6031
  $form.querySelectorAll(".yui-tabulator-table").forEach(($table) => {
6025
6032
  if (isEventSet($table.tabulator, "dataChanged")) $table.tabulator.off("dataChanged");
6026
6033
  $table.querySelectorAll(".yui-tabulator-table-nested").forEach(($table_nested) => {
@@ -6029,10 +6036,8 @@ function set_changed_stated(gobj, changed) {
6029
6036
  });
6030
6037
  } else {
6031
6038
  (0, _yuneta_gobj_js.gobj_write_bool_attr)(gobj, "changes", false);
6032
- $button_save.setAttribute("disabled", true);
6033
- $button_undo.setAttribute("disabled", true);
6034
- $button_save.querySelector("span i").style.color = "hsl(var(--bulma-button-h), var(--bulma-button-s), var(--bulma-button-color-l))";
6035
- $button_undo.querySelector("span i").style.color = "hsl(var(--bulma-button-h), var(--bulma-button-s), var(--bulma-button-color-l))";
6039
+ enable($button_save, false, OFF_COLOR);
6040
+ enable($button_undo, false, OFF_COLOR);
6036
6041
  setTimeout(function() {
6037
6042
  $form.querySelectorAll(".yui-tabulator-table").forEach(($table) => {
6038
6043
  if (isEventSet($table.tabulator, "dataChanged")) $table.tabulator.off("dataChanged");
@@ -6206,27 +6211,31 @@ function build_toolbar(gobj) {
6206
6211
  },
6207
6212
  ""
6208
6213
  ];
6214
+ const justify = plan.single_group ? "is-justify-content-center" : "is-justify-content-space-between";
6215
+ let groups = [];
6216
+ if (plan.left.length) groups.push([
6217
+ "div",
6218
+ {
6219
+ class: "p-1 is-flex is-flex-direction-row is-align-items-center",
6220
+ style: "column-gap:6px;"
6221
+ },
6222
+ plan.left.map((n) => toolbar_button(gobj, n))
6223
+ ]);
6224
+ if (plan.right.length) groups.push([
6225
+ "div",
6226
+ {
6227
+ class: "p-1 is-flex is-flex-direction-row is-align-items-center",
6228
+ style: "column-gap:6px;"
6229
+ },
6230
+ plan.right.map((n) => toolbar_button(gobj, n))
6231
+ ]);
6209
6232
  return [
6210
6233
  "div",
6211
6234
  {
6212
- class: "yui-toolbar-form is-flex-shrink-0 is-flex is-flex-direction-row is-justify-content-space-between is-align-items-center",
6235
+ class: `yui-toolbar-form is-flex-shrink-0 is-flex is-flex-direction-row ${justify} is-align-items-center`,
6213
6236
  style: "width:100%; flex-wrap:wrap; row-gap:6px;"
6214
6237
  },
6215
- [[
6216
- "div",
6217
- {
6218
- class: "p-1 is-flex is-flex-direction-row is-align-items-center",
6219
- style: "column-gap:6px;"
6220
- },
6221
- plan.left.map((n) => toolbar_button(gobj, n))
6222
- ], [
6223
- "div",
6224
- {
6225
- class: "p-1 is-flex is-flex-direction-row is-align-items-center",
6226
- style: "column-gap:6px;"
6227
- },
6228
- plan.right.map((n) => toolbar_button(gobj, n))
6229
- ]]
6238
+ groups
6230
6239
  ];
6231
6240
  }
6232
6241
  /************************************************************
@@ -5804,7 +5804,8 @@ function plan_toolbar(wanted) {
5804
5804
  return {
5805
5805
  left,
5806
5806
  right,
5807
- unknown
5807
+ unknown,
5808
+ single_group: left.length === 0 !== (right.length === 0)
5808
5809
  };
5809
5810
  }
5810
5811
  //#endregion
@@ -6008,14 +6009,20 @@ function isEventSet(table, event) {
6008
6009
  function set_changed_stated(gobj, changed) {
6009
6010
  let $container = gobj_read_attr(gobj, "$container");
6010
6011
  let $form = $container.querySelector("form");
6012
+ const enable = ($btn, on, color) => {
6013
+ if (!$btn) return;
6014
+ if (on) $btn.removeAttribute("disabled");
6015
+ else $btn.setAttribute("disabled", true);
6016
+ const $i = $btn.querySelector("span i");
6017
+ if ($i) $i.style.color = color;
6018
+ };
6019
+ const OFF_COLOR = "hsl(var(--bulma-button-h), var(--bulma-button-s), var(--bulma-button-color-l))";
6011
6020
  let $button_save = $container.querySelector(".button-save");
6012
6021
  let $button_undo = $container.querySelector(".button-undo");
6013
6022
  if (changed) {
6014
6023
  gobj_write_bool_attr(gobj, "changes", true);
6015
- $button_save.removeAttribute("disabled");
6016
- $button_undo.removeAttribute("disabled");
6017
- $button_save.querySelector("span i").style.color = "MediumSeaGreen";
6018
- $button_undo.querySelector("span i").style.color = "Magenta";
6024
+ enable($button_save, true, "MediumSeaGreen");
6025
+ enable($button_undo, true, "Magenta");
6019
6026
  $form.querySelectorAll(".yui-tabulator-table").forEach(($table) => {
6020
6027
  if (isEventSet($table.tabulator, "dataChanged")) $table.tabulator.off("dataChanged");
6021
6028
  $table.querySelectorAll(".yui-tabulator-table-nested").forEach(($table_nested) => {
@@ -6024,10 +6031,8 @@ function set_changed_stated(gobj, changed) {
6024
6031
  });
6025
6032
  } else {
6026
6033
  gobj_write_bool_attr(gobj, "changes", false);
6027
- $button_save.setAttribute("disabled", true);
6028
- $button_undo.setAttribute("disabled", true);
6029
- $button_save.querySelector("span i").style.color = "hsl(var(--bulma-button-h), var(--bulma-button-s), var(--bulma-button-color-l))";
6030
- $button_undo.querySelector("span i").style.color = "hsl(var(--bulma-button-h), var(--bulma-button-s), var(--bulma-button-color-l))";
6034
+ enable($button_save, false, OFF_COLOR);
6035
+ enable($button_undo, false, OFF_COLOR);
6031
6036
  setTimeout(function() {
6032
6037
  $form.querySelectorAll(".yui-tabulator-table").forEach(($table) => {
6033
6038
  if (isEventSet($table.tabulator, "dataChanged")) $table.tabulator.off("dataChanged");
@@ -6201,27 +6206,31 @@ function build_toolbar(gobj) {
6201
6206
  },
6202
6207
  ""
6203
6208
  ];
6209
+ const justify = plan.single_group ? "is-justify-content-center" : "is-justify-content-space-between";
6210
+ let groups = [];
6211
+ if (plan.left.length) groups.push([
6212
+ "div",
6213
+ {
6214
+ class: "p-1 is-flex is-flex-direction-row is-align-items-center",
6215
+ style: "column-gap:6px;"
6216
+ },
6217
+ plan.left.map((n) => toolbar_button(gobj, n))
6218
+ ]);
6219
+ if (plan.right.length) groups.push([
6220
+ "div",
6221
+ {
6222
+ class: "p-1 is-flex is-flex-direction-row is-align-items-center",
6223
+ style: "column-gap:6px;"
6224
+ },
6225
+ plan.right.map((n) => toolbar_button(gobj, n))
6226
+ ]);
6204
6227
  return [
6205
6228
  "div",
6206
6229
  {
6207
- class: "yui-toolbar-form is-flex-shrink-0 is-flex is-flex-direction-row is-justify-content-space-between is-align-items-center",
6230
+ class: `yui-toolbar-form is-flex-shrink-0 is-flex is-flex-direction-row ${justify} is-align-items-center`,
6208
6231
  style: "width:100%; flex-wrap:wrap; row-gap:6px;"
6209
6232
  },
6210
- [[
6211
- "div",
6212
- {
6213
- class: "p-1 is-flex is-flex-direction-row is-align-items-center",
6214
- style: "column-gap:6px;"
6215
- },
6216
- plan.left.map((n) => toolbar_button(gobj, n))
6217
- ], [
6218
- "div",
6219
- {
6220
- class: "p-1 is-flex is-flex-direction-row is-align-items-center",
6221
- style: "column-gap:6px;"
6222
- },
6223
- plan.right.map((n) => toolbar_button(gobj, n))
6224
- ]]
6233
+ groups
6225
6234
  ];
6226
6235
  }
6227
6236
  /************************************************************
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yuneta/gobj-ui",
3
- "version": "5.7.0",
3
+ "version": "5.7.2",
4
4
  "type": "module",
5
5
  "main": "dist/gobj-ui.cjs.js",
6
6
  "module": "dist/gobj-ui.es.js",
package/src/c_yui_form.js CHANGED
@@ -219,6 +219,29 @@ function set_changed_stated(gobj, changed)
219
219
  let $container = gobj_read_attr(gobj, "$container");
220
220
  let $form = $container.querySelector('form');
221
221
 
222
+ /*
223
+ * Los dos pueden NO estar: desde que la botonera es configurable
224
+ * (`toolbar`), un dialogo de una sola accion pide ["save"] y aqui no
225
+ * hay undo que habilitar. Antes se daban por presentes y quitar uno
226
+ * reventaba con "can't access property setAttribute, a is null" al
227
+ * primer cambio en el formulario.
228
+ */
229
+ const enable = ($btn, on, color) => {
230
+ if(!$btn) {
231
+ return;
232
+ }
233
+ if(on) {
234
+ $btn.removeAttribute("disabled");
235
+ } else {
236
+ $btn.setAttribute("disabled", true);
237
+ }
238
+ const $i = $btn.querySelector('span i');
239
+ if($i) {
240
+ $i.style.color = color;
241
+ }
242
+ };
243
+ const OFF_COLOR = "hsl(var(--bulma-button-h), var(--bulma-button-s), var(--bulma-button-color-l))";
244
+
222
245
  let $button_save = $container.querySelector('.button-save');
223
246
  let $button_undo = $container.querySelector('.button-undo');
224
247
 
@@ -228,11 +251,8 @@ function set_changed_stated(gobj, changed)
228
251
  */
229
252
  gobj_write_bool_attr(gobj, "changes", true);
230
253
 
231
- $button_save.removeAttribute("disabled");
232
- $button_undo.removeAttribute("disabled");
233
-
234
- $button_save.querySelector('span i').style.color = "MediumSeaGreen";
235
- $button_undo.querySelector('span i').style.color = "Magenta";
254
+ enable($button_save, true, "MediumSeaGreen");
255
+ enable($button_undo, true, "Magenta");
236
256
 
237
257
  $form.querySelectorAll('.yui-tabulator-table').forEach($table => {
238
258
  if(isEventSet($table.tabulator, "dataChanged")) {
@@ -252,11 +272,8 @@ function set_changed_stated(gobj, changed)
252
272
  */
253
273
  gobj_write_bool_attr(gobj, "changes", false);
254
274
 
255
- $button_save.setAttribute("disabled", true);
256
- $button_undo.setAttribute("disabled", true);
257
-
258
- $button_save.querySelector('span i').style.color = "hsl(var(--bulma-button-h), var(--bulma-button-s), var(--bulma-button-color-l))";
259
- $button_undo.querySelector('span i').style.color = "hsl(var(--bulma-button-h), var(--bulma-button-s), var(--bulma-button-color-l))";
275
+ enable($button_save, false, OFF_COLOR);
276
+ enable($button_undo, false, OFF_COLOR);
260
277
 
261
278
  // TODO improve
262
279
  setTimeout(function() {
@@ -374,12 +391,21 @@ function build_toolbar(gobj)
374
391
  return ['span', {class: 'yui-toolbar-form-empty', style: 'display:none;'}, ''];
375
392
  }
376
393
 
377
- return ['div', {class: 'yui-toolbar-form is-flex-shrink-0 is-flex is-flex-direction-row is-justify-content-space-between is-align-items-center', style: 'width:100%; flex-wrap:wrap; row-gap:6px;'}, [
378
- ['div', {class: 'p-1 is-flex is-flex-direction-row is-align-items-center', style:'column-gap:6px;'},
379
- plan.left.map((n) => toolbar_button(gobj, n))],
380
- ['div', {class: 'p-1 is-flex is-flex-direction-row is-align-items-center', style:'column-gap:6px;'},
381
- plan.right.map((n) => toolbar_button(gobj, n))]
382
- ]];
394
+ const justify = plan.single_group
395
+ ? 'is-justify-content-center'
396
+ : 'is-justify-content-space-between';
397
+
398
+ let groups = [];
399
+ if(plan.left.length) {
400
+ groups.push(['div', {class: 'p-1 is-flex is-flex-direction-row is-align-items-center', style:'column-gap:6px;'},
401
+ plan.left.map((n) => toolbar_button(gobj, n))]);
402
+ }
403
+ if(plan.right.length) {
404
+ groups.push(['div', {class: 'p-1 is-flex is-flex-direction-row is-align-items-center', style:'column-gap:6px;'},
405
+ plan.right.map((n) => toolbar_button(gobj, n))]);
406
+ }
407
+
408
+ return ['div', {class: `yui-toolbar-form is-flex-shrink-0 is-flex is-flex-direction-row ${justify} is-align-items-center`, style: 'width:100%; flex-wrap:wrap; row-gap:6px;'}, groups];
383
409
  }
384
410
 
385
411
  /************************************************************
@@ -52,7 +52,14 @@ function plan_toolbar(wanted)
52
52
  }
53
53
  }
54
54
 
55
- return {left, right, unknown};
55
+ /* Con un solo grupo, repartir con `space-between` deja el boton
56
+ * pegado a un borde y el hueco entero al otro lado: un dialogo de
57
+ * una accion se ve mejor centrado. Lo decide aqui y no el CSS de
58
+ * quien llama, porque la clase que lo reparte es un helper de Bulma
59
+ * y esos llevan `!important`: una regla de app no puede ganarles. */
60
+ const single_group = (left.length === 0) !== (right.length === 0);
61
+
62
+ return {left, right, unknown, single_group};
56
63
  }
57
64
 
58
65
 
@@ -46,6 +46,17 @@ describe("plan_toolbar", () => {
46
46
  expect(p.unknown).toEqual(["sav"]);
47
47
  });
48
48
 
49
+ it("one group centres; two groups keep the split", () => {
50
+ /* La clase que reparte es un helper de Bulma, con !important:
51
+ * si no se decide aqui, ninguna regla de app puede centrarlo. */
52
+ expect(plan_toolbar(["save"]).single_group).toBe(true);
53
+ expect(plan_toolbar(["save", "undo", "clear"]).single_group).toBe(true);
54
+ expect(plan_toolbar(["copy", "paste"]).single_group).toBe(true);
55
+ expect(plan_toolbar(undefined).single_group).toBe(false);
56
+ expect(plan_toolbar(["save", "copy"]).single_group).toBe(false);
57
+ expect(plan_toolbar([]).single_group).toBe(false);
58
+ });
59
+
49
60
  it("drops one whole side without disturbing the other", () => {
50
61
  const p = plan_toolbar(["save", "undo", "clear"]);
51
62
  expect(p.left).toEqual(["save", "undo", "clear"]);