@yuneta/gobj-ui 7.26.52 → 7.26.54

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yuneta/gobj-ui",
3
- "version": "7.26.52",
3
+ "version": "7.26.54",
4
4
  "type": "module",
5
5
  "main": "dist/gobj-ui.cjs.js",
6
6
  "module": "dist/gobj-ui.es.js",
@@ -30,6 +30,7 @@
30
30
  "prebuild": "npm run check-markup",
31
31
  "pretest": "npm run check-markup",
32
32
  "qa-history": "node scripts/qa-history.mjs",
33
+ "qa-cell-editor": "node scripts/qa-cell-editor.mjs",
33
34
  "deploy-round": "node scripts/deploy-round.mjs",
34
35
  "prepublishOnly": "npm run build"
35
36
  },
package/src/c_yui_form.js CHANGED
@@ -100,7 +100,8 @@ import {
100
100
  time_value_to_text
101
101
  } from "./form_time_value.js";
102
102
  import {form_time_cell_editor} from "./form_time_cell_editor.js";
103
- import {safe_locale} from "./yui_time.js";
103
+ import {yui_tabulator_keep_edit_on_redraw} from "./yui_tabulator_edit.js";
104
+ import {safe_locale} from "./yui_date_text.js";
104
105
  import {parse_json_field, json_editor_value} from "./form_json_field.js";
105
106
  import {
106
107
  json_editor_menu_items,
@@ -2485,6 +2486,7 @@ function create_tabulator(gobj, $extend, name, template, rows)
2485
2486
  $extend,
2486
2487
  tabulator_settings
2487
2488
  );
2489
+ yui_tabulator_keep_edit_on_redraw(tabulator);
2488
2490
  /* What the READER does to a table -- edits a cell, adds or deletes a
2489
2491
  * row -- reaches the form only through `dataChanged`. Wired here, on
2490
2492
  * every table, nested ones included (a row's formatter builds them
package/src/c_yui_json.js CHANGED
@@ -112,7 +112,7 @@ import {yui_shell_of} from "./c_yui_shell.js";
112
112
  import {attach_clear} from "./yui_inputs.js";
113
113
 
114
114
  import i18next, {t} from "i18next";
115
- import {safe_locale} from "./yui_time.js";
115
+ import {safe_locale} from "./yui_date_text.js";
116
116
 
117
117
  import "./c_yui_json.css";
118
118
  import {text_node} from "./yui_text.js";
@@ -79,6 +79,7 @@ import {yui_tabulator_lang, yui_tabulator_relocalize,
79
79
  yui_tabulator_name_filters,
80
80
  yui_tabulator_name_row_selects,
81
81
  yui_tabulator_name_editor} from "./yui_tabulator_i18n.js";
82
+ import {yui_tabulator_keep_edit_on_redraw} from "./yui_tabulator_edit.js";
82
83
 
83
84
  import {
84
85
  yui_selection_column,
@@ -99,7 +100,7 @@ import {
99
100
  import {row_matches} from "./yui_row_search.js";
100
101
 
101
102
  import i18next, {t} from "i18next";
102
- import {safe_locale} from "./yui_time.js";
103
+ import {safe_locale} from "./yui_date_text.js";
103
104
 
104
105
  import {yui_toolbar_icon} from "./yui_toolbar.js";
105
106
 
@@ -1782,6 +1783,7 @@ function create_tabulator(gobj)
1782
1783
  * what it said before for an app that does not define the key). */
1783
1784
  placeholder: t("no data available", {defaultValue: "No data available"})
1784
1785
  }));
1786
+ yui_tabulator_keep_edit_on_redraw(tabulator);
1785
1787
 
1786
1788
  /* "highlight" still paints the whole-row hover wash (and a pointer
1787
1789
  * cursor), which reads as a selection. This table selects only via the
@@ -35,7 +35,7 @@
35
35
  * Copyright (c) 2026, ArtGins.
36
36
  * All Rights Reserved.
37
37
  ****************************************************************************/
38
- import {fmt_date_time} from "./yui_time.js";
38
+ import {fmt_date_time} from "./yui_date_text.js";
39
39
 
40
40
  /************************************************************
41
41
  * A Date -> the value of a `datetime-local` input, in local time,
@@ -16,7 +16,7 @@
16
16
  * All Rights Reserved.
17
17
  ***********************************************************************/
18
18
  import {json2flat, flat_diff} from "@yuneta/gobj-js";
19
- import {fmt_date_time} from "./yui_time.js";
19
+ import {fmt_date_time} from "./yui_date_text.js";
20
20
 
21
21
  /*
22
22
  * Path delimiter, identical to the kernel's `delimiter` in kwid.c.
@@ -0,0 +1,82 @@
1
+ /***********************************************************************
2
+ * yui_date_text.js
3
+ *
4
+ * A moment as a VIEW shows it as text, and the locale to show it
5
+ * in. A module of its own, with no i18n key, on purpose: the views
6
+ * that show a time (C_YUI_FORM, C_YUI_TREEDB_TOPIC_WITH_FORM,
7
+ * C_YUI_JSON, C_YUI_UPLOT) import it, and validate-locales follows
8
+ * the modules an app mounts -- importing yui_time.js for this made
9
+ * every app that shows a time owe the keys of the period picker
10
+ * (gobj-ui 7.26.52). yui_time.js re-exports both.
11
+ *
12
+ * Copyright (c) 2026, ArtGins.
13
+ * All Rights Reserved.
14
+ ***********************************************************************/
15
+
16
+ /***************************************************************
17
+ * The locale to format with.
18
+ *
19
+ * NEVER at module top level, and never `navigator.language` raw:
20
+ * Firefox can report the literal STRING "undefined", and every Intl
21
+ * constructor throws RangeError on it — a module that built its
22
+ * formatter on import took the whole bundle down with it (that is why
23
+ * gui_agent refuses to import the gobj-ui barrel).
24
+ ***************************************************************/
25
+ function safe_locale(locale)
26
+ {
27
+ if(typeof locale === "string" && locale && locale !== "undefined") {
28
+ return locale;
29
+ }
30
+ let nav = (typeof navigator !== "undefined") ? navigator.language : null;
31
+ if(typeof nav === "string" && nav && nav !== "undefined") {
32
+ return nav;
33
+ }
34
+ return "en";
35
+ }
36
+
37
+ /* The clock is always 24 hours: `hourCycle`, never `hour12: false`,
38
+ * which some engines read as "h24" and show midnight as 24:00:00. */
39
+ const DATE_TIME_OPTIONS = {
40
+ day: "numeric", month: "short", year: "numeric",
41
+ hour: "2-digit", minute: "2-digit", second: "2-digit",
42
+ hourCycle: "h23"
43
+ };
44
+
45
+ /***************************************************************
46
+ * A moment as a VIEW shows it as text: the day, the month and the
47
+ * year, then the clock of 24 hours with its seconds, in the APP's
48
+ * language -- `locale` is the language t() answers in (the views
49
+ * pass `i18next.language`), never the browser's:
50
+ *
51
+ * fmt_date_time(d, "es") -> "14 oct 2026, 15:05:09"
52
+ * fmt_date_time(d, "en") -> "Oct 14, 2026, 15:05:09"
53
+ *
54
+ * "" for anything that is not a valid Date. A locale Intl refuses
55
+ * gives the language-free "2026-10-14 15:05:09".
56
+ *
57
+ * The time cells of C_YUI_FORM and C_YUI_TREEDB_TOPIC_WITH_FORM and
58
+ * the reading C_YUI_JSON writes beside a time field all come from
59
+ * here, so the same moment reads the same in the three.
60
+ ***************************************************************/
61
+ function fmt_date_time(date, locale)
62
+ {
63
+ if(!(date instanceof Date) || isNaN(date.getTime())) {
64
+ return "";
65
+ }
66
+ try {
67
+ return new Intl.DateTimeFormat(safe_locale(locale), DATE_TIME_OPTIONS).format(date);
68
+ } catch(e) {
69
+ let pad = (n) => String(n).padStart(2, "0");
70
+ return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ` +
71
+ `${pad(date.getHours())}:${pad(date.getMinutes())}:${pad(date.getSeconds())}`;
72
+ }
73
+ }
74
+
75
+
76
+ /***************************************************************
77
+ * Exports
78
+ ***************************************************************/
79
+ export {
80
+ safe_locale,
81
+ fmt_date_time,
82
+ };
@@ -0,0 +1,69 @@
1
+ /****************************************************************************
2
+ * yui_tabulator_edit.js
3
+ *
4
+ * An open cell editor survives a FORCED redraw of its table.
5
+ *
6
+ * `table.redraw(true)` builds every row's cells again, the one
7
+ * being edited too, and leaves Tabulator's edit pointing at the
8
+ * cell it threw away (it ends the edit before a data refresh,
9
+ * not before a redraw). Tabulator issues one itself, from
10
+ * ResizeTable's IntersectionObserver, the first time a table
11
+ * built out of sight comes into view -- and a click on a cell
12
+ * of a table below the fold scrolls it in AND opens the editor
13
+ * in the same turn. Chromium blurs the box it takes out, the
14
+ * editor's blur ends the edit on the dead cell, and Tabulator
15
+ * throws in Validate.editorClear ("reading 'remove'"); Firefox
16
+ * does not blur, and throws at the next edit. Any editor, ours
17
+ * (form_time_cell_editor.js) or Tabulator's own.
18
+ *
19
+ * So the edit is ended BEFORE the forced redraw, while its cell
20
+ * is alive, and opened again on the new cell of the same row
21
+ * and column after it. What was typed in the box is lost; the
22
+ * editor stays open under the reader.
23
+ *
24
+ * Copyright (c) 2026, ArtGins.
25
+ * All Rights Reserved.
26
+ ****************************************************************************/
27
+ import {log_warning} from "@yuneta/gobj-js";
28
+
29
+ /************************************************************
30
+ * Wrap `tabulator.redraw` so that a forced redraw ends the
31
+ * open edit first and opens it again after.
32
+ ************************************************************/
33
+ function yui_tabulator_keep_edit_on_redraw(tabulator)
34
+ {
35
+ let editing = null;
36
+ tabulator.on("cellEditing", function(cell) {
37
+ editing = cell;
38
+ });
39
+ tabulator.on("cellEdited", function() {
40
+ editing = null;
41
+ });
42
+ tabulator.on("cellEditCancelled", function() {
43
+ editing = null;
44
+ });
45
+
46
+ let redraw = tabulator.redraw.bind(tabulator);
47
+ tabulator.redraw = function(force) {
48
+ let cell = editing;
49
+ /* A success() with the value unchanged fires no cellEdited:
50
+ * the cell's class says whether it is still being edited. */
51
+ let $cell = cell? cell.getElement() : null;
52
+ if(!force || !$cell || !$cell.classList.contains("tabulator-editing")) {
53
+ return redraw(force);
54
+ }
55
+ let row = cell.getRow();
56
+ let field = cell.getField();
57
+ cell.cancelEdit();
58
+ let ret = redraw(force);
59
+ let again = row.getCell(field);
60
+ if(!again) {
61
+ log_warning(`yui_tabulator_keep_edit_on_redraw: no cell '${field}' after the redraw`);
62
+ return ret;
63
+ }
64
+ again.edit(true);
65
+ return ret;
66
+ };
67
+ }
68
+
69
+ export {yui_tabulator_keep_edit_on_redraw};
package/src/yui_time.js CHANGED
@@ -44,6 +44,11 @@
44
44
  * All Rights Reserved.
45
45
  ***********************************************************************/
46
46
 
47
+ /* The text of a moment lives in a module of its own, which carries no
48
+ * i18n key: a view that formats a time must not make the validator ask
49
+ * an app for the keys of the period picker, which live here. */
50
+ import {safe_locale, fmt_date_time} from "./yui_date_text.js";
51
+
47
52
  /***************************************************************
48
53
  * Constants
49
54
  ***************************************************************/
@@ -111,27 +116,6 @@ export const YUI_TIME_I18N_KEYS = [
111
116
  ***************************/
112
117
 
113
118
 
114
- /***************************************************************
115
- * The locale to format with.
116
- *
117
- * NEVER at module top level, and never `navigator.language` raw:
118
- * Firefox can report the literal STRING "undefined", and every Intl
119
- * constructor throws RangeError on it — a module that built its
120
- * formatter on import took the whole bundle down with it (that is why
121
- * gui_agent refuses to import the gobj-ui barrel).
122
- ***************************************************************/
123
- function safe_locale(locale)
124
- {
125
- if(typeof locale === "string" && locale && locale !== "undefined") {
126
- return locale;
127
- }
128
- let nav = (typeof navigator !== "undefined") ? navigator.language : null;
129
- if(typeof nav === "string" && nav && nav !== "undefined") {
130
- return nav;
131
- }
132
- return "en";
133
- }
134
-
135
119
  /***************************************************************
136
120
  * Translate through the APP's translator when it gave us one, and
137
121
  * degrade to the key itself otherwise — interpolating `{{x}}` by hand,
@@ -241,43 +225,6 @@ function fmt_epoch(value, ms)
241
225
  }
242
226
  }
243
227
 
244
- /* The clock is always 24 hours: `hourCycle`, never `hour12: false`,
245
- * which some engines read as "h24" and show midnight as 24:00:00. */
246
- const DATE_TIME_OPTIONS = {
247
- day: "numeric", month: "short", year: "numeric",
248
- hour: "2-digit", minute: "2-digit", second: "2-digit",
249
- hourCycle: "h23"
250
- };
251
-
252
- /***************************************************************
253
- * A moment as a VIEW shows it as text: the day, the month and the
254
- * year, then the clock of 24 hours with its seconds, in the APP's
255
- * language -- `locale` is the language t() answers in (the views
256
- * pass `i18next.language`), never the browser's:
257
- *
258
- * fmt_date_time(d, "es") -> "14 oct 2026, 15:05:09"
259
- * fmt_date_time(d, "en") -> "Oct 14, 2026, 15:05:09"
260
- *
261
- * "" for anything that is not a valid Date. A locale Intl refuses
262
- * gives the language-free "2026-10-14 15:05:09".
263
- *
264
- * The time cells of C_YUI_FORM and C_YUI_TREEDB_TOPIC_WITH_FORM and
265
- * the reading C_YUI_JSON writes beside a time field all come from
266
- * here, so the same moment reads the same in the three.
267
- ***************************************************************/
268
- function fmt_date_time(date, locale)
269
- {
270
- if(!(date instanceof Date) || isNaN(date.getTime())) {
271
- return "";
272
- }
273
- try {
274
- return new Intl.DateTimeFormat(safe_locale(locale), DATE_TIME_OPTIONS).format(date);
275
- } catch(e) {
276
- return epoch_to_local_input(date.getTime(), true).replace("T", " ");
277
- }
278
- }
279
-
280
-
281
228
  /***************************
282
229
  * Calendar atoms
283
230
  ***************************/
@@ -27,7 +27,7 @@
27
27
  * Copyright (c) 2026, ArtGins.
28
28
  * All Rights Reserved.
29
29
  ***********************************************************************/
30
- import {fmt_date_time, safe_locale} from "./yui_time.js";
30
+ import {fmt_date_time, safe_locale} from "./yui_date_text.js";
31
31
 
32
32
  /* The legend's stamp, as uPlot 1.6 writes it (_timeSeriesStamp). */
33
33
  const LEGEND_STAMP = "{YYYY}-{MM}-{DD} {h}:{mm}{aa}";