@yuneta/gobj-ui 7.23.57 → 7.23.59

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.
@@ -6361,13 +6361,7 @@ var attrs_table$16 = [
6361
6361
  (0, _yuneta_gobj_js.SDATA)(_yuneta_gobj_js.data_type_t.DTP_BOOLEAN, "with_checkbox", 0, false, "Show a first column with checkbox to select rows"),
6362
6362
  (0, _yuneta_gobj_js.SDATA)(_yuneta_gobj_js.data_type_t.DTP_BOOLEAN, "with_rownum", 0, false, "Print first column with row number"),
6363
6363
  (0, _yuneta_gobj_js.SDATA)(_yuneta_gobj_js.data_type_t.DTP_BOOLEAN, "with_delete_row_btn", 0, false, "Print last column with delete row button"),
6364
- (0, _yuneta_gobj_js.SDATA)(_yuneta_gobj_js.data_type_t.DTP_JSON, "toolbar", 0, [
6365
- "save",
6366
- "undo",
6367
- "clear",
6368
- "copy",
6369
- "paste"
6370
- ], "Toolbar buttons to show, in order: save, undo, clear, copy, paste. [] hides the toolbar"),
6364
+ (0, _yuneta_gobj_js.SDATA)(_yuneta_gobj_js.data_type_t.DTP_JSON, "toolbar", 0, DEFAULT_TOOLBAR.slice(), "Toolbar buttons to show. The order inside each group is the order given here; which side each group takes is form_toolbar_plan.js. [] hides the toolbar"),
6371
6365
  (0, _yuneta_gobj_js.SDATA)(_yuneta_gobj_js.data_type_t.DTP_JSON, "tabulator_settings", 0, {
6372
6366
  layout: "fitDataFill",
6373
6367
  validationMode: "highlight",
@@ -6546,7 +6540,7 @@ function toolbar_button$1(gobj, name) {
6546
6540
  case "clear": return [
6547
6541
  "button",
6548
6542
  {
6549
- class: "button p-1",
6543
+ class: "button p-1 button-clear",
6550
6544
  title: "clear",
6551
6545
  "aria-label": "clear"
6552
6546
  },
@@ -6570,7 +6564,7 @@ function toolbar_button$1(gobj, name) {
6570
6564
  case "copy": return [
6571
6565
  "button",
6572
6566
  {
6573
- class: "button p-1",
6567
+ class: "button p-1 button-copy",
6574
6568
  title: "copy",
6575
6569
  "aria-label": "copy"
6576
6570
  },
@@ -6594,7 +6588,7 @@ function toolbar_button$1(gobj, name) {
6594
6588
  case "paste": return [
6595
6589
  "button",
6596
6590
  {
6597
- class: "button p-1",
6591
+ class: "button p-1 button-paste",
6598
6592
  title: "paste",
6599
6593
  "aria-label": "paste"
6600
6594
  },
@@ -7064,7 +7058,7 @@ function create_form_field(gobj, $form, prefix, field_desc, { tag, inputType, na
7064
7058
  "div",
7065
7059
  {
7066
7060
  class: "xcontrol control",
7067
- style: "max-width:100px;"
7061
+ style: "max-width:220px;"
7068
7062
  },
7069
7063
  []
7070
7064
  ]]
@@ -7322,6 +7316,7 @@ function create_form_field(gobj, $form, prefix, field_desc, { tag, inputType, na
7322
7316
  ]);
7323
7317
  $control.appendChild($extend);
7324
7318
  if (inputType !== "color" && inputType !== "datetime-local" && (!readonly || is_pkey)) attach_clear($control, $extend);
7319
+ if (inputType === "color") attach_color_value($control, $extend);
7325
7320
  break;
7326
7321
  }
7327
7322
  case "textarea": {
@@ -7520,6 +7515,37 @@ function create_form_field(gobj, $form, prefix, field_desc, { tag, inputType, na
7520
7515
  return $element;
7521
7516
  }
7522
7517
  /******************************************************************
7518
+ * A colour swatch beside its own value.
7519
+ *
7520
+ * The swatch says WHICH colour and nothing else -- and the value is
7521
+ * the half a person needs: to read it, to write it down, to paste it
7522
+ * into the next record. Read-only it was unreachable altogether;
7523
+ * editable it was a colour you could only pick, never copy.
7524
+ *
7525
+ * A `<span>`, not a second input: the record is collected from the
7526
+ * controls marked `yui-form-data-input`, and one field with two of
7527
+ * them is a field read twice. It carries `user-select: all`, so one
7528
+ * click takes the whole value and not the half a double-click would
7529
+ * stop at (`#e0a800` is three words to a browser).
7530
+ ******************************************************************/
7531
+ function attach_color_value($control, $input) {
7532
+ let $value = (0, _yuneta_gobj_js.createElement2)([
7533
+ "span",
7534
+ { class: "yui-color-value is-family-monospace is-size-7" },
7535
+ ""
7536
+ ]);
7537
+ function refresh() {
7538
+ let v = $input.value || "";
7539
+ $value.textContent = v;
7540
+ $value.title = v;
7541
+ }
7542
+ refresh();
7543
+ $input.addEventListener("input", refresh);
7544
+ $input.addEventListener("change", refresh);
7545
+ $input.yui_color_value = $value;
7546
+ $control.appendChild($value);
7547
+ }
7548
+ /******************************************************************
7523
7549
  * `readonly` is an attribute of a TEXT control and of nothing else.
7524
7550
  *
7525
7551
  * A `<select>` ignores it. So does a checkbox, and so does a radio:
@@ -8099,6 +8125,10 @@ function set_form_values(gobj, template, $form, record) {
8099
8125
  break;
8100
8126
  case "color":
8101
8127
  $input.value = convertColor(value);
8128
+ if ($input.yui_color_value) {
8129
+ $input.yui_color_value.textContent = $input.value;
8130
+ $input.yui_color_value.title = $input.value;
8131
+ }
8102
8132
  break;
8103
8133
  default: $input.value = value;
8104
8134
  }
@@ -6356,13 +6356,7 @@ var attrs_table$16 = [
6356
6356
  SDATA(data_type_t.DTP_BOOLEAN, "with_checkbox", 0, false, "Show a first column with checkbox to select rows"),
6357
6357
  SDATA(data_type_t.DTP_BOOLEAN, "with_rownum", 0, false, "Print first column with row number"),
6358
6358
  SDATA(data_type_t.DTP_BOOLEAN, "with_delete_row_btn", 0, false, "Print last column with delete row button"),
6359
- SDATA(data_type_t.DTP_JSON, "toolbar", 0, [
6360
- "save",
6361
- "undo",
6362
- "clear",
6363
- "copy",
6364
- "paste"
6365
- ], "Toolbar buttons to show, in order: save, undo, clear, copy, paste. [] hides the toolbar"),
6359
+ SDATA(data_type_t.DTP_JSON, "toolbar", 0, DEFAULT_TOOLBAR.slice(), "Toolbar buttons to show. The order inside each group is the order given here; which side each group takes is form_toolbar_plan.js. [] hides the toolbar"),
6366
6360
  SDATA(data_type_t.DTP_JSON, "tabulator_settings", 0, {
6367
6361
  layout: "fitDataFill",
6368
6362
  validationMode: "highlight",
@@ -6541,7 +6535,7 @@ function toolbar_button$1(gobj, name) {
6541
6535
  case "clear": return [
6542
6536
  "button",
6543
6537
  {
6544
- class: "button p-1",
6538
+ class: "button p-1 button-clear",
6545
6539
  title: "clear",
6546
6540
  "aria-label": "clear"
6547
6541
  },
@@ -6565,7 +6559,7 @@ function toolbar_button$1(gobj, name) {
6565
6559
  case "copy": return [
6566
6560
  "button",
6567
6561
  {
6568
- class: "button p-1",
6562
+ class: "button p-1 button-copy",
6569
6563
  title: "copy",
6570
6564
  "aria-label": "copy"
6571
6565
  },
@@ -6589,7 +6583,7 @@ function toolbar_button$1(gobj, name) {
6589
6583
  case "paste": return [
6590
6584
  "button",
6591
6585
  {
6592
- class: "button p-1",
6586
+ class: "button p-1 button-paste",
6593
6587
  title: "paste",
6594
6588
  "aria-label": "paste"
6595
6589
  },
@@ -7059,7 +7053,7 @@ function create_form_field(gobj, $form, prefix, field_desc, { tag, inputType, na
7059
7053
  "div",
7060
7054
  {
7061
7055
  class: "xcontrol control",
7062
- style: "max-width:100px;"
7056
+ style: "max-width:220px;"
7063
7057
  },
7064
7058
  []
7065
7059
  ]]
@@ -7317,6 +7311,7 @@ function create_form_field(gobj, $form, prefix, field_desc, { tag, inputType, na
7317
7311
  ]);
7318
7312
  $control.appendChild($extend);
7319
7313
  if (inputType !== "color" && inputType !== "datetime-local" && (!readonly || is_pkey)) attach_clear($control, $extend);
7314
+ if (inputType === "color") attach_color_value($control, $extend);
7320
7315
  break;
7321
7316
  }
7322
7317
  case "textarea": {
@@ -7515,6 +7510,37 @@ function create_form_field(gobj, $form, prefix, field_desc, { tag, inputType, na
7515
7510
  return $element;
7516
7511
  }
7517
7512
  /******************************************************************
7513
+ * A colour swatch beside its own value.
7514
+ *
7515
+ * The swatch says WHICH colour and nothing else -- and the value is
7516
+ * the half a person needs: to read it, to write it down, to paste it
7517
+ * into the next record. Read-only it was unreachable altogether;
7518
+ * editable it was a colour you could only pick, never copy.
7519
+ *
7520
+ * A `<span>`, not a second input: the record is collected from the
7521
+ * controls marked `yui-form-data-input`, and one field with two of
7522
+ * them is a field read twice. It carries `user-select: all`, so one
7523
+ * click takes the whole value and not the half a double-click would
7524
+ * stop at (`#e0a800` is three words to a browser).
7525
+ ******************************************************************/
7526
+ function attach_color_value($control, $input) {
7527
+ let $value = createElement2([
7528
+ "span",
7529
+ { class: "yui-color-value is-family-monospace is-size-7" },
7530
+ ""
7531
+ ]);
7532
+ function refresh() {
7533
+ let v = $input.value || "";
7534
+ $value.textContent = v;
7535
+ $value.title = v;
7536
+ }
7537
+ refresh();
7538
+ $input.addEventListener("input", refresh);
7539
+ $input.addEventListener("change", refresh);
7540
+ $input.yui_color_value = $value;
7541
+ $control.appendChild($value);
7542
+ }
7543
+ /******************************************************************
7518
7544
  * `readonly` is an attribute of a TEXT control and of nothing else.
7519
7545
  *
7520
7546
  * A `<select>` ignores it. So does a checkbox, and so does a radio:
@@ -8094,6 +8120,10 @@ function set_form_values(gobj, template, $form, record) {
8094
8120
  break;
8095
8121
  case "color":
8096
8122
  $input.value = convertColor(value);
8123
+ if ($input.yui_color_value) {
8124
+ $input.yui_color_value.textContent = $input.value;
8125
+ $input.yui_color_value.title = $input.value;
8126
+ }
8097
8127
  break;
8098
8128
  default: $input.value = value;
8099
8129
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yuneta/gobj-ui",
3
- "version": "7.23.57",
3
+ "version": "7.23.59",
4
4
  "type": "module",
5
5
  "main": "dist/gobj-ui.cjs.js",
6
6
  "module": "dist/gobj-ui.es.js",
@@ -79,3 +79,18 @@
79
79
  .C_YUI_FORM .yui-jse-readonly {
80
80
  background-color: var(--bulma-background, #f5f5f5);
81
81
  }
82
+
83
+ /* The value of a colour, beside its swatch: what the swatch cannot say.
84
+ * `user-select: all` so one click takes the whole `#e0a800` -- to a
85
+ * browser that is three words, and a double-click stops at one of them. */
86
+ .C_YUI_FORM .yui-color-value {
87
+ margin-left: 0.5rem;
88
+ vertical-align: middle;
89
+ color: var(--bulma-text-weak, #7a7a7a);
90
+ user-select: all;
91
+ -webkit-user-select: all;
92
+ cursor: text;
93
+ }
94
+ .C_YUI_FORM input[type="color"] {
95
+ vertical-align: middle;
96
+ }
package/src/c_yui_form.js CHANGED
@@ -57,7 +57,7 @@ import { createJSONEditor } from 'vanilla-jsoneditor';
57
57
  import "vanilla-jsoneditor/themes/jse-theme-dark.css";
58
58
  import "./c_yui_form.css";
59
59
  import {attach_clear, refresh_clear} from "./yui_inputs.js";
60
- import {plan_toolbar} from "./form_toolbar_plan.js";
60
+ import {plan_toolbar, DEFAULT_TOOLBAR} from "./form_toolbar_plan.js";
61
61
  /* Read at field-build time only — deliberately NOT watched: the hosting
62
62
  * dialog rebuilds the form on every open, and re-rendering a form under
63
63
  * the user mid-edit would throw away what they typed. */
@@ -117,7 +117,12 @@ SDATA(data_type_t.DTP_BOOLEAN, "with_delete_row_btn", 0, false, "Print last co
117
117
  * Unknown names are ignored, with a warning: a typo must not silently
118
118
  * drop the save button.
119
119
  */
120
- SDATA(data_type_t.DTP_JSON, "toolbar", 0, ["save", "undo", "clear", "copy", "paste"], "Toolbar buttons to show, in order: save, undo, clear, copy, paste. [] hides the toolbar"),
120
+ /* The default is the LIST, not a copy of it: written out here it was a
121
+ * second copy of `DEFAULT_TOOLBAR` that `plan_toolbar` never got to
122
+ * see -- the attr always has a value, so the module that decides the
123
+ * plan could change its default and nothing moved. Sliced because an
124
+ * attr default is handed out and must not be the shared array. */
125
+ SDATA(data_type_t.DTP_JSON, "toolbar", 0, DEFAULT_TOOLBAR.slice(), "Toolbar buttons to show. The order inside each group is the order given here; which side each group takes is form_toolbar_plan.js. [] hides the toolbar"),
121
126
  /*
122
127
  * Defaults for tabulator
123
128
  */
@@ -354,7 +359,7 @@ function toolbar_button(gobj, name)
354
359
  }
355
360
  }];
356
361
  case "clear":
357
- return ['button', {class: 'button p-1', title: 'clear', 'aria-label': 'clear'}, [
362
+ return ['button', {class: 'button p-1 button-clear', title: 'clear', 'aria-label': 'clear'}, [
358
363
  ['span', {class: 'icon m-0'}, '<i class="yi-broom-wide"></i>'],
359
364
  ['span', {class: 'is-hidden-mobile pl-1 pr-1', i18n: 'clear'}, 'clear']
360
365
  ], {
@@ -364,7 +369,7 @@ function toolbar_button(gobj, name)
364
369
  }
365
370
  }];
366
371
  case "copy":
367
- return ['button', {class: 'button p-1', title: 'copy', 'aria-label': 'copy'}, [
372
+ return ['button', {class: 'button p-1 button-copy', title: 'copy', 'aria-label': 'copy'}, [
368
373
  ['span', {class: 'icon m-0'}, '<i class="yi-copy"></i>'],
369
374
  ['span', {class: 'is-hidden-mobile pl-1 pr-1', i18n: 'copy'}, 'copy']
370
375
  ], {click: function(evt) {
@@ -373,7 +378,7 @@ function toolbar_button(gobj, name)
373
378
  }
374
379
  }];
375
380
  case "paste":
376
- return ['button', {class: 'button p-1', title: 'paste', 'aria-label': 'paste'}, [
381
+ return ['button', {class: 'button p-1 button-paste', title: 'paste', 'aria-label': 'paste'}, [
377
382
  ['span', {class: 'icon m-0'}, '<i class="yi-paste"></i>'],
378
383
  ['span', {class: 'is-hidden-mobile pl-1 pr-1', i18n: 'paste'}, 'paste']
379
384
  ], {click: async function(evt) {
@@ -1024,7 +1029,9 @@ function create_form_field(
1024
1029
 
1025
1030
  ['div', {class: 'field-body'}, [
1026
1031
  ['div', {class: 'field'}, [
1027
- ['div', {class: 'xcontrol control', style: 'max-width:100px;'}, []]
1032
+ /* Room for the swatch AND its value
1033
+ * beside it (attach_color_value). */
1034
+ ['div', {class: 'xcontrol control', style: 'max-width:220px;'}, []]
1028
1035
  ]]
1029
1036
  ]]
1030
1037
  ]]
@@ -1201,6 +1208,9 @@ function create_form_field(
1201
1208
  (!readonly || is_pkey)) {
1202
1209
  attach_clear($control, $extend);
1203
1210
  }
1211
+ if(inputType === 'color') {
1212
+ attach_color_value($control, $extend);
1213
+ }
1204
1214
  break;
1205
1215
  }
1206
1216
 
@@ -1456,6 +1466,43 @@ function create_form_field(
1456
1466
  return $element;
1457
1467
  }
1458
1468
 
1469
+ /******************************************************************
1470
+ * A colour swatch beside its own value.
1471
+ *
1472
+ * The swatch says WHICH colour and nothing else -- and the value is
1473
+ * the half a person needs: to read it, to write it down, to paste it
1474
+ * into the next record. Read-only it was unreachable altogether;
1475
+ * editable it was a colour you could only pick, never copy.
1476
+ *
1477
+ * A `<span>`, not a second input: the record is collected from the
1478
+ * controls marked `yui-form-data-input`, and one field with two of
1479
+ * them is a field read twice. It carries `user-select: all`, so one
1480
+ * click takes the whole value and not the half a double-click would
1481
+ * stop at (`#e0a800` is three words to a browser).
1482
+ ******************************************************************/
1483
+ function attach_color_value($control, $input)
1484
+ {
1485
+ let $value = createElement2(
1486
+ ['span', {class: 'yui-color-value is-family-monospace is-size-7'}, '']
1487
+ );
1488
+
1489
+ function refresh() {
1490
+ let v = $input.value || "";
1491
+ $value.textContent = v;
1492
+ $value.title = v;
1493
+ }
1494
+
1495
+ refresh();
1496
+ $input.addEventListener('input', refresh);
1497
+ /* The swatch's value is also written from outside (loading a record
1498
+ * into the form), and that fires nothing. `set_field_value()` ends
1499
+ * in a synthetic `change`, which is why this listens to both. */
1500
+ $input.addEventListener('change', refresh);
1501
+ $input.yui_color_value = $value;
1502
+
1503
+ $control.appendChild($value);
1504
+ }
1505
+
1459
1506
  /******************************************************************
1460
1507
  * `readonly` is an attribute of a TEXT control and of nothing else.
1461
1508
  *
@@ -2398,6 +2445,12 @@ function set_form_values(gobj, template, $form, record)
2398
2445
  break;
2399
2446
  case "color":
2400
2447
  $input.value = convertColor(value);
2448
+ /* Writing `.value` fires nothing, so the readout
2449
+ * beside the swatch has to be told. */
2450
+ if($input.yui_color_value) {
2451
+ $input.yui_color_value.textContent = $input.value;
2452
+ $input.yui_color_value.title = $input.value;
2453
+ }
2401
2454
  break;
2402
2455
  default:
2403
2456
  $input.value = value;