@yuneta/gobj-ui 7.26.53 → 7.26.55
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/README.md +36 -8
- package/dist/gobj-ui.cjs.js +108 -19
- package/dist/gobj-ui.es.js +108 -19
- package/package.json +2 -1
- package/scripts/validate-locales.mjs +59 -17
- package/src/c_yui_form.js +6 -2
- package/src/c_yui_treedb_topic_with_form.js +2 -0
- package/src/fmt_date_time.test.js +31 -2
- package/src/form_time_field.wiring.test.js +28 -0
- package/src/yui_date_text.js +30 -8
- package/src/yui_tabulator_edit.js +85 -0
- package/src/yui_tabulator_edit.test.js +132 -0
- package/src/yui_time.js +2 -7
- package/src/yui_uplot_time.js +2 -6
package/README.md
CHANGED
|
@@ -4199,6 +4199,10 @@ and reads back the bundle each host serves (`--check` only reads back,
|
|
|
4199
4199
|
`--only <name>` does one app, `--no-wait` skips the registry). The private
|
|
4200
4200
|
consumers are listed in `~/.yuneta/gobj-ui-consumers.json` (see
|
|
4201
4201
|
`scripts/gobj-ui-consumers.example.json`); the demo (`test-app/`) is built in.
|
|
4202
|
+
It is built from the working tree, so it goes out only from a clean tree whose
|
|
4203
|
+
HEAD is the commit `origin/main` holds on the remote; otherwise it is `NOT
|
|
4204
|
+
DEPLOYED`, with the reason, and the round exits 1 (since `7.26.55`; up to
|
|
4205
|
+
`7.26.54` any copy of the repo, on any commit, deployed the public demo).
|
|
4202
4206
|
|
|
4203
4207
|
An app whose range cannot be raised safely is refused and left as it was --
|
|
4204
4208
|
every package.json of it, since all are checked before any is written: a
|
|
@@ -4256,7 +4260,10 @@ one of `@yuneta/gobj-ui` on the same HEAD read the library's states -- and
|
|
|
4256
4260
|
said "already" for an app born with both new ranges whose number had gone out
|
|
4257
4261
|
with the runtime's old range (deploying a new bundle under that number), or
|
|
4258
4262
|
raised a version for nothing. A file of another format (one of those rounds)
|
|
4259
|
-
is not read, and is written again; the 64 entries used last are kept.
|
|
4263
|
+
is not read, and is written again; the 64 entries used last are kept. An
|
|
4264
|
+
entry that is not a list of `{specs: [string], versions: [string]}` is said,
|
|
4265
|
+
read again from git and written again (since `7.26.55`; up to `7.26.54` an
|
|
4266
|
+
entry `[null]` refused the app on every round, naming no file). A
|
|
4260
4267
|
package.json born with the range in the ROOT of a
|
|
4261
4268
|
history joined to another one (`--allow-unrelated-histories`) is asked of the
|
|
4262
4269
|
other history, by version, as one born in a commit with parents is. The
|
|
@@ -4606,7 +4613,11 @@ This tree asks for "admin" (a root with children and no `label`), for
|
|
|
4606
4613
|
dependency of this package since `7.26.29`: an app need not declare it). A
|
|
4607
4614
|
LOCALE is not a source: it is parsed, and then imported, so its top-level code
|
|
4608
4615
|
runs -- the app's own code, but code, and in a process of its own (since
|
|
4609
|
-
`7.26.51`), so
|
|
4616
|
+
`7.26.51`), so what a locale does by ACCIDENT does not reach the verdict:
|
|
4617
|
+
ending the process, an exit handler, a timer, a report of its own written to
|
|
4618
|
+
the channel or a `toJSON` on a prototype (refused or never read since
|
|
4619
|
+
`7.26.55`). That process is no sandbox against a locale written to cheat it.
|
|
4620
|
+
Comments are not code. A key is read
|
|
4610
4621
|
where it is WRITTEN -- given to a translator, as an `i18n` or `data-i18n*`
|
|
4611
4622
|
value of an object literal, by `setAttribute()`, or (since `7.26.29`) written
|
|
4612
4623
|
as a member, `attrs.i18n = "save"`, `attrs["data-i18n-title"] = "save"` -- and
|
|
@@ -5574,8 +5585,9 @@ nothing else should.
|
|
|
5574
5585
|
- `epoch_to_local_input` / `local_input_to_epoch` / `fmt_epoch` / `epoch_to_ms`
|
|
5575
5586
|
/ `ms_to_epoch` — every conversion crosses the producer's unit flag
|
|
5576
5587
|
(`ms`: seconds unless a topic's `system_flag` says milliseconds).
|
|
5577
|
-
- `fmt_date_time(date, locale)`
|
|
5578
|
-
|
|
5588
|
+
- `fmt_date_time(date, locale)` and `safe_locale(locale)` are re-exported
|
|
5589
|
+
here, but they live in `yui_date_text.js`: import them from THERE (see
|
|
5590
|
+
*Dates: a time shown as text*).
|
|
5579
5591
|
- `period_bounds` / `period_shift` / `period_start` / `period_label` /
|
|
5580
5592
|
`infer_period` / `is_current_period` — the algebra of **periods**.
|
|
5581
5593
|
|
|
@@ -5633,20 +5645,36 @@ scripts with the UI around it.
|
|
|
5633
5645
|
|
|
5634
5646
|
**Every time a view shows as text is in the APP's language, with a clock of 24
|
|
5635
5647
|
hours** (7.26.52). One function writes it, `fmt_date_time(date, locale)` in
|
|
5636
|
-
`
|
|
5637
|
-
and the views pass it `i18next.language`, never `navigator.language
|
|
5648
|
+
`yui_date_text.js` -- day, short month, year, then hours, minutes and seconds --,
|
|
5649
|
+
and the views pass it `i18next.language`, never `navigator.language`. Import it
|
|
5650
|
+
from `yui_date_text.js`, not from `yui_time.js`: `validate-locales` follows the
|
|
5651
|
+
modules an app imports, and `yui_time.js` makes the app owe every key of the
|
|
5652
|
+
period picker.
|
|
5638
5653
|
|
|
5639
5654
|
```js
|
|
5640
|
-
import {fmt_date_time, safe_locale} from "@yuneta/gobj-ui/src/
|
|
5655
|
+
import {fmt_date_time, safe_locale} from "@yuneta/gobj-ui/src/yui_date_text.js";
|
|
5641
5656
|
import i18next from "i18next";
|
|
5642
5657
|
|
|
5643
5658
|
fmt_date_time(new Date(2026, 9, 14, 15, 5, 9), safe_locale(i18next.language));
|
|
5644
5659
|
// es "14 oct 2026, 15:05:09"
|
|
5645
5660
|
// en "Oct 14, 2026, 15:05:09" (en-US too: 24 hours, no AM/PM)
|
|
5646
5661
|
// midnight "00:00:00", never "24:00:00" (hourCycle "h23", not hour12: false)
|
|
5647
|
-
// not a valid Date -> ""
|
|
5662
|
+
// not a valid Date -> ""
|
|
5648
5663
|
```
|
|
5649
5664
|
|
|
5665
|
+
Three facts the text does not show:
|
|
5666
|
+
|
|
5667
|
+
- **The zone is the browser's**, and the text names no zone and no offset. Two
|
|
5668
|
+
readers in two zones see two different clocks for the same record.
|
|
5669
|
+
- **The hour that repeats in autumn reads the same in its two passes**: in
|
|
5670
|
+
Europe/Madrid, `1792888200` and `1792891800` both read
|
|
5671
|
+
`25 oct 2026, 02:30:00`.
|
|
5672
|
+
- **A locale the environment cannot use writes in the environment's
|
|
5673
|
+
language.** A well-formed one Intl does not know (`xx`, `cimode`, `dev`) does
|
|
5674
|
+
it by Intl's own rule, silently. A malformed one Intl refuses (`en_US`) does
|
|
5675
|
+
it through `date_time_format()` (`yui_date_text.js`), which says it once per
|
|
5676
|
+
locale in a WARNING. The ticks of a chart's time axis fall back the same way.
|
|
5677
|
+
|
|
5650
5678
|
What writes it, and follows the language button (`EV_LANGUAGE_CHANGED`):
|
|
5651
5679
|
|
|
5652
5680
|
| View | Where | Up to 7.26.51 |
|
package/dist/gobj-ui.cjs.js
CHANGED
|
@@ -9712,6 +9712,28 @@ function safe_locale(locale) {
|
|
|
9712
9712
|
if (typeof nav === "string" && nav && nav !== "undefined") return nav;
|
|
9713
9713
|
return "en";
|
|
9714
9714
|
}
|
|
9715
|
+
var __refused_locales__ = /* @__PURE__ */ new Set();
|
|
9716
|
+
/***************************************************************
|
|
9717
|
+
* An Intl.DateTimeFormat of `locale` with `options`. A locale
|
|
9718
|
+
* Intl refuses (a malformed tag: "en_US") falls back to the
|
|
9719
|
+
* environment's -- what Intl itself gives for a well-formed
|
|
9720
|
+
* one it does not know ("xx") -- and is said in a WARNING, once
|
|
9721
|
+
* per locale. fmt_date_time() and the ticks of a uPlot time axis
|
|
9722
|
+
* (yui_uplot_time.js) both go through it, so they fall back the
|
|
9723
|
+
* same way.
|
|
9724
|
+
***************************************************************/
|
|
9725
|
+
function date_time_format(locale, options) {
|
|
9726
|
+
let loc = safe_locale(locale);
|
|
9727
|
+
try {
|
|
9728
|
+
return new Intl.DateTimeFormat(loc, options);
|
|
9729
|
+
} catch (e) {
|
|
9730
|
+
if (!__refused_locales__.has(loc)) {
|
|
9731
|
+
__refused_locales__.add(loc);
|
|
9732
|
+
(0, _yuneta_gobj_js.log_warning)(`date_time_format: locale '${loc}' refused by Intl (${e}), using the environment's`);
|
|
9733
|
+
}
|
|
9734
|
+
return new Intl.DateTimeFormat(void 0, options);
|
|
9735
|
+
}
|
|
9736
|
+
}
|
|
9715
9737
|
var DATE_TIME_OPTIONS = {
|
|
9716
9738
|
day: "numeric",
|
|
9717
9739
|
month: "short",
|
|
@@ -9731,7 +9753,7 @@ var DATE_TIME_OPTIONS = {
|
|
|
9731
9753
|
* fmt_date_time(d, "en") -> "Oct 14, 2026, 15:05:09"
|
|
9732
9754
|
*
|
|
9733
9755
|
* "" for anything that is not a valid Date. A locale Intl refuses
|
|
9734
|
-
*
|
|
9756
|
+
* writes in the environment's (date_time_format).
|
|
9735
9757
|
*
|
|
9736
9758
|
* The time cells of C_YUI_FORM and C_YUI_TREEDB_TOPIC_WITH_FORM and
|
|
9737
9759
|
* the reading C_YUI_JSON writes beside a time field all come from
|
|
@@ -9739,12 +9761,7 @@ var DATE_TIME_OPTIONS = {
|
|
|
9739
9761
|
***************************************************************/
|
|
9740
9762
|
function fmt_date_time(date, locale) {
|
|
9741
9763
|
if (!(date instanceof Date) || isNaN(date.getTime())) return "";
|
|
9742
|
-
|
|
9743
|
-
return new Intl.DateTimeFormat(safe_locale(locale), DATE_TIME_OPTIONS).format(date);
|
|
9744
|
-
} catch (e) {
|
|
9745
|
-
let pad = (n) => String(n).padStart(2, "0");
|
|
9746
|
-
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ${pad(date.getHours())}:${pad(date.getMinutes())}:${pad(date.getSeconds())}`;
|
|
9747
|
-
}
|
|
9764
|
+
return date_time_format(locale, DATE_TIME_OPTIONS).format(date);
|
|
9748
9765
|
}
|
|
9749
9766
|
/************************************************************
|
|
9750
9767
|
* JSON type discriminator (viewer vocabulary)
|
|
@@ -10322,6 +10339,84 @@ function form_time_cell_editor(real_type) {
|
|
|
10322
10339
|
};
|
|
10323
10340
|
}
|
|
10324
10341
|
//#endregion
|
|
10342
|
+
//#region src/yui_tabulator_edit.js
|
|
10343
|
+
/****************************************************************************
|
|
10344
|
+
* yui_tabulator_edit.js
|
|
10345
|
+
*
|
|
10346
|
+
* An open cell editor survives a FORCED redraw of its table,
|
|
10347
|
+
* and the other calls that build its cells again.
|
|
10348
|
+
*
|
|
10349
|
+
* `table.redraw(true)` builds every row's cells again, the one
|
|
10350
|
+
* being edited too, and leaves Tabulator's edit pointing at the
|
|
10351
|
+
* cell it threw away (it ends the edit before a data refresh,
|
|
10352
|
+
* not before a redraw). Tabulator issues one itself, from
|
|
10353
|
+
* ResizeTable's IntersectionObserver, the first time a table
|
|
10354
|
+
* built out of sight comes into view -- and a click on a cell
|
|
10355
|
+
* of a table below the fold scrolls it in AND opens the editor
|
|
10356
|
+
* in the same turn. Chromium blurs the box it takes out, the
|
|
10357
|
+
* editor's blur ends the edit on the dead cell, and Tabulator
|
|
10358
|
+
* throws in Validate.editorClear ("reading 'remove'"); Firefox
|
|
10359
|
+
* does not blur, and throws at the next edit. Any editor, ours
|
|
10360
|
+
* (form_time_cell_editor.js) or Tabulator's own.
|
|
10361
|
+
*
|
|
10362
|
+
* `setColumns()` (a language change of
|
|
10363
|
+
* C_YUI_TREEDB_TOPIC_WITH_FORM runs it) and `setHeight`,
|
|
10364
|
+
* `setMaxHeight` and `setMinHeight` build the cells again the
|
|
10365
|
+
* same way, and Tabulator throws the same.
|
|
10366
|
+
*
|
|
10367
|
+
* So the edit is ended BEFORE each of those calls, while its cell
|
|
10368
|
+
* is alive, and opened again on the new cell of the same row
|
|
10369
|
+
* and column after it. What was typed in the box is lost; the
|
|
10370
|
+
* editor stays open under the reader.
|
|
10371
|
+
*
|
|
10372
|
+
* Copyright (c) 2026, ArtGins.
|
|
10373
|
+
* All Rights Reserved.
|
|
10374
|
+
****************************************************************************/
|
|
10375
|
+
/************************************************************
|
|
10376
|
+
* Wrap the calls of `tabulator` that build the cells again --
|
|
10377
|
+
* a forced `redraw`, `setColumns` and the three height setters
|
|
10378
|
+
* -- so that each ends the open edit first and opens it again
|
|
10379
|
+
* after.
|
|
10380
|
+
************************************************************/
|
|
10381
|
+
function yui_tabulator_keep_edit_on_redraw(tabulator) {
|
|
10382
|
+
let editing = null;
|
|
10383
|
+
tabulator.on("cellEditing", function(cell) {
|
|
10384
|
+
editing = cell;
|
|
10385
|
+
});
|
|
10386
|
+
tabulator.on("cellEdited", function() {
|
|
10387
|
+
editing = null;
|
|
10388
|
+
});
|
|
10389
|
+
tabulator.on("cellEditCancelled", function() {
|
|
10390
|
+
editing = null;
|
|
10391
|
+
});
|
|
10392
|
+
function keep_edit_around(name, rebuilds) {
|
|
10393
|
+
let original = tabulator[name].bind(tabulator);
|
|
10394
|
+
tabulator[name] = function(...args) {
|
|
10395
|
+
let cell = editing;
|
|
10396
|
+
let $cell = cell ? cell.getElement() : null;
|
|
10397
|
+
if (!rebuilds(args) || !$cell || !$cell.classList.contains("tabulator-editing")) return original(...args);
|
|
10398
|
+
let row = cell.getRow();
|
|
10399
|
+
let field = cell.getField();
|
|
10400
|
+
cell.cancelEdit();
|
|
10401
|
+
let ret = original(...args);
|
|
10402
|
+
let again = row.getCell(field);
|
|
10403
|
+
if (!again) {
|
|
10404
|
+
(0, _yuneta_gobj_js.log_warning)(`yui_tabulator_keep_edit_on_redraw: no cell '${field}' after ${name}()`);
|
|
10405
|
+
return ret;
|
|
10406
|
+
}
|
|
10407
|
+
again.edit(true);
|
|
10408
|
+
return ret;
|
|
10409
|
+
};
|
|
10410
|
+
}
|
|
10411
|
+
keep_edit_around("redraw", (args) => !!args[0]);
|
|
10412
|
+
for (const name of [
|
|
10413
|
+
"setColumns",
|
|
10414
|
+
"setHeight",
|
|
10415
|
+
"setMaxHeight",
|
|
10416
|
+
"setMinHeight"
|
|
10417
|
+
]) keep_edit_around(name, () => true);
|
|
10418
|
+
}
|
|
10419
|
+
//#endregion
|
|
10325
10420
|
//#region src/form_json_field.js
|
|
10326
10421
|
/***********************************************************************
|
|
10327
10422
|
* form_json_field.js
|
|
@@ -12631,6 +12726,7 @@ function create_tabulator$1(gobj, $extend, name, template, rows) {
|
|
|
12631
12726
|
visible: (0, _yuneta_gobj_js.gobj_read_bool_attr)(gobj, "selectable")
|
|
12632
12727
|
};
|
|
12633
12728
|
let tabulator = new tabulator_tables.TabulatorFull($extend, tabulator_settings);
|
|
12729
|
+
yui_tabulator_keep_edit_on_redraw(tabulator);
|
|
12634
12730
|
tabulator.on("dataChanged", function() {
|
|
12635
12731
|
if (gobj.priv.loading_rows > 0) return;
|
|
12636
12732
|
(0, _yuneta_gobj_js.gobj_send_event)(gobj, "EV_RECORD_CHANGED", {}, gobj);
|
|
@@ -13236,10 +13332,10 @@ function set_form_values(gobj, template, $form, record) {
|
|
|
13236
13332
|
switch (input_type) {
|
|
13237
13333
|
case "datetime-local":
|
|
13238
13334
|
$input.value = date_to_datetime_local(value);
|
|
13239
|
-
$input.yui_time_kept = {
|
|
13335
|
+
$input.yui_time_kept = $input.value !== "" ? {
|
|
13240
13336
|
value: stored,
|
|
13241
13337
|
shown: $input.value
|
|
13242
|
-
};
|
|
13338
|
+
} : null;
|
|
13243
13339
|
break;
|
|
13244
13340
|
case "color":
|
|
13245
13341
|
$input.value = convertColor(value);
|
|
@@ -15155,11 +15251,7 @@ function intl(locale, opts) {
|
|
|
15155
15251
|
let key = locale + "|" + JSON.stringify(opts);
|
|
15156
15252
|
let f = __formatters__.get(key);
|
|
15157
15253
|
if (!f) {
|
|
15158
|
-
|
|
15159
|
-
f = new Intl.DateTimeFormat(locale, opts);
|
|
15160
|
-
} catch (e) {
|
|
15161
|
-
f = new Intl.DateTimeFormat("en", opts);
|
|
15162
|
-
}
|
|
15254
|
+
f = date_time_format(locale, opts);
|
|
15163
15255
|
__formatters__.set(key, f);
|
|
15164
15256
|
}
|
|
15165
15257
|
return f;
|
|
@@ -33023,6 +33115,7 @@ function create_tabulator(gobj) {
|
|
|
33023
33115
|
return;
|
|
33024
33116
|
}
|
|
33025
33117
|
let tabulator = new tabulator_tables.TabulatorFull($table_el, Object.assign({}, tabulator_settings, yui_tabulator_lang(i18next.t), { placeholder: (0, i18next.t)("no data available", { defaultValue: "No data available" }) }));
|
|
33118
|
+
yui_tabulator_keep_edit_on_redraw(tabulator);
|
|
33026
33119
|
if (with_checkbox) $table_el.classList.add("yui-no-row-hover");
|
|
33027
33120
|
function update_rowcount(explicit_count) {
|
|
33028
33121
|
let $rc = tabulator.element && tabulator.element.querySelector(".yui-tabulator-rowcount");
|
|
@@ -83171,11 +83264,7 @@ function tr(t, key, params) {
|
|
|
83171
83264
|
* the library has no business owning.
|
|
83172
83265
|
***************************************************************/
|
|
83173
83266
|
function fmt_intl(date, locale, opts) {
|
|
83174
|
-
|
|
83175
|
-
return new Intl.DateTimeFormat(safe_locale(locale), opts).format(date);
|
|
83176
|
-
} catch (e) {
|
|
83177
|
-
return date.toDateString();
|
|
83178
|
-
}
|
|
83267
|
+
return date_time_format(locale, opts).format(date);
|
|
83179
83268
|
}
|
|
83180
83269
|
/***************************
|
|
83181
83270
|
* Epoch <-> clock
|
package/dist/gobj-ui.es.js
CHANGED
|
@@ -9707,6 +9707,28 @@ function safe_locale(locale) {
|
|
|
9707
9707
|
if (typeof nav === "string" && nav && nav !== "undefined") return nav;
|
|
9708
9708
|
return "en";
|
|
9709
9709
|
}
|
|
9710
|
+
var __refused_locales__ = /* @__PURE__ */ new Set();
|
|
9711
|
+
/***************************************************************
|
|
9712
|
+
* An Intl.DateTimeFormat of `locale` with `options`. A locale
|
|
9713
|
+
* Intl refuses (a malformed tag: "en_US") falls back to the
|
|
9714
|
+
* environment's -- what Intl itself gives for a well-formed
|
|
9715
|
+
* one it does not know ("xx") -- and is said in a WARNING, once
|
|
9716
|
+
* per locale. fmt_date_time() and the ticks of a uPlot time axis
|
|
9717
|
+
* (yui_uplot_time.js) both go through it, so they fall back the
|
|
9718
|
+
* same way.
|
|
9719
|
+
***************************************************************/
|
|
9720
|
+
function date_time_format(locale, options) {
|
|
9721
|
+
let loc = safe_locale(locale);
|
|
9722
|
+
try {
|
|
9723
|
+
return new Intl.DateTimeFormat(loc, options);
|
|
9724
|
+
} catch (e) {
|
|
9725
|
+
if (!__refused_locales__.has(loc)) {
|
|
9726
|
+
__refused_locales__.add(loc);
|
|
9727
|
+
log_warning(`date_time_format: locale '${loc}' refused by Intl (${e}), using the environment's`);
|
|
9728
|
+
}
|
|
9729
|
+
return new Intl.DateTimeFormat(void 0, options);
|
|
9730
|
+
}
|
|
9731
|
+
}
|
|
9710
9732
|
var DATE_TIME_OPTIONS = {
|
|
9711
9733
|
day: "numeric",
|
|
9712
9734
|
month: "short",
|
|
@@ -9726,7 +9748,7 @@ var DATE_TIME_OPTIONS = {
|
|
|
9726
9748
|
* fmt_date_time(d, "en") -> "Oct 14, 2026, 15:05:09"
|
|
9727
9749
|
*
|
|
9728
9750
|
* "" for anything that is not a valid Date. A locale Intl refuses
|
|
9729
|
-
*
|
|
9751
|
+
* writes in the environment's (date_time_format).
|
|
9730
9752
|
*
|
|
9731
9753
|
* The time cells of C_YUI_FORM and C_YUI_TREEDB_TOPIC_WITH_FORM and
|
|
9732
9754
|
* the reading C_YUI_JSON writes beside a time field all come from
|
|
@@ -9734,12 +9756,7 @@ var DATE_TIME_OPTIONS = {
|
|
|
9734
9756
|
***************************************************************/
|
|
9735
9757
|
function fmt_date_time(date, locale) {
|
|
9736
9758
|
if (!(date instanceof Date) || isNaN(date.getTime())) return "";
|
|
9737
|
-
|
|
9738
|
-
return new Intl.DateTimeFormat(safe_locale(locale), DATE_TIME_OPTIONS).format(date);
|
|
9739
|
-
} catch (e) {
|
|
9740
|
-
let pad = (n) => String(n).padStart(2, "0");
|
|
9741
|
-
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ${pad(date.getHours())}:${pad(date.getMinutes())}:${pad(date.getSeconds())}`;
|
|
9742
|
-
}
|
|
9759
|
+
return date_time_format(locale, DATE_TIME_OPTIONS).format(date);
|
|
9743
9760
|
}
|
|
9744
9761
|
/************************************************************
|
|
9745
9762
|
* JSON type discriminator (viewer vocabulary)
|
|
@@ -10317,6 +10334,84 @@ function form_time_cell_editor(real_type) {
|
|
|
10317
10334
|
};
|
|
10318
10335
|
}
|
|
10319
10336
|
//#endregion
|
|
10337
|
+
//#region src/yui_tabulator_edit.js
|
|
10338
|
+
/****************************************************************************
|
|
10339
|
+
* yui_tabulator_edit.js
|
|
10340
|
+
*
|
|
10341
|
+
* An open cell editor survives a FORCED redraw of its table,
|
|
10342
|
+
* and the other calls that build its cells again.
|
|
10343
|
+
*
|
|
10344
|
+
* `table.redraw(true)` builds every row's cells again, the one
|
|
10345
|
+
* being edited too, and leaves Tabulator's edit pointing at the
|
|
10346
|
+
* cell it threw away (it ends the edit before a data refresh,
|
|
10347
|
+
* not before a redraw). Tabulator issues one itself, from
|
|
10348
|
+
* ResizeTable's IntersectionObserver, the first time a table
|
|
10349
|
+
* built out of sight comes into view -- and a click on a cell
|
|
10350
|
+
* of a table below the fold scrolls it in AND opens the editor
|
|
10351
|
+
* in the same turn. Chromium blurs the box it takes out, the
|
|
10352
|
+
* editor's blur ends the edit on the dead cell, and Tabulator
|
|
10353
|
+
* throws in Validate.editorClear ("reading 'remove'"); Firefox
|
|
10354
|
+
* does not blur, and throws at the next edit. Any editor, ours
|
|
10355
|
+
* (form_time_cell_editor.js) or Tabulator's own.
|
|
10356
|
+
*
|
|
10357
|
+
* `setColumns()` (a language change of
|
|
10358
|
+
* C_YUI_TREEDB_TOPIC_WITH_FORM runs it) and `setHeight`,
|
|
10359
|
+
* `setMaxHeight` and `setMinHeight` build the cells again the
|
|
10360
|
+
* same way, and Tabulator throws the same.
|
|
10361
|
+
*
|
|
10362
|
+
* So the edit is ended BEFORE each of those calls, while its cell
|
|
10363
|
+
* is alive, and opened again on the new cell of the same row
|
|
10364
|
+
* and column after it. What was typed in the box is lost; the
|
|
10365
|
+
* editor stays open under the reader.
|
|
10366
|
+
*
|
|
10367
|
+
* Copyright (c) 2026, ArtGins.
|
|
10368
|
+
* All Rights Reserved.
|
|
10369
|
+
****************************************************************************/
|
|
10370
|
+
/************************************************************
|
|
10371
|
+
* Wrap the calls of `tabulator` that build the cells again --
|
|
10372
|
+
* a forced `redraw`, `setColumns` and the three height setters
|
|
10373
|
+
* -- so that each ends the open edit first and opens it again
|
|
10374
|
+
* after.
|
|
10375
|
+
************************************************************/
|
|
10376
|
+
function yui_tabulator_keep_edit_on_redraw(tabulator) {
|
|
10377
|
+
let editing = null;
|
|
10378
|
+
tabulator.on("cellEditing", function(cell) {
|
|
10379
|
+
editing = cell;
|
|
10380
|
+
});
|
|
10381
|
+
tabulator.on("cellEdited", function() {
|
|
10382
|
+
editing = null;
|
|
10383
|
+
});
|
|
10384
|
+
tabulator.on("cellEditCancelled", function() {
|
|
10385
|
+
editing = null;
|
|
10386
|
+
});
|
|
10387
|
+
function keep_edit_around(name, rebuilds) {
|
|
10388
|
+
let original = tabulator[name].bind(tabulator);
|
|
10389
|
+
tabulator[name] = function(...args) {
|
|
10390
|
+
let cell = editing;
|
|
10391
|
+
let $cell = cell ? cell.getElement() : null;
|
|
10392
|
+
if (!rebuilds(args) || !$cell || !$cell.classList.contains("tabulator-editing")) return original(...args);
|
|
10393
|
+
let row = cell.getRow();
|
|
10394
|
+
let field = cell.getField();
|
|
10395
|
+
cell.cancelEdit();
|
|
10396
|
+
let ret = original(...args);
|
|
10397
|
+
let again = row.getCell(field);
|
|
10398
|
+
if (!again) {
|
|
10399
|
+
log_warning(`yui_tabulator_keep_edit_on_redraw: no cell '${field}' after ${name}()`);
|
|
10400
|
+
return ret;
|
|
10401
|
+
}
|
|
10402
|
+
again.edit(true);
|
|
10403
|
+
return ret;
|
|
10404
|
+
};
|
|
10405
|
+
}
|
|
10406
|
+
keep_edit_around("redraw", (args) => !!args[0]);
|
|
10407
|
+
for (const name of [
|
|
10408
|
+
"setColumns",
|
|
10409
|
+
"setHeight",
|
|
10410
|
+
"setMaxHeight",
|
|
10411
|
+
"setMinHeight"
|
|
10412
|
+
]) keep_edit_around(name, () => true);
|
|
10413
|
+
}
|
|
10414
|
+
//#endregion
|
|
10320
10415
|
//#region src/form_json_field.js
|
|
10321
10416
|
/***********************************************************************
|
|
10322
10417
|
* form_json_field.js
|
|
@@ -12626,6 +12721,7 @@ function create_tabulator$1(gobj, $extend, name, template, rows) {
|
|
|
12626
12721
|
visible: gobj_read_bool_attr(gobj, "selectable")
|
|
12627
12722
|
};
|
|
12628
12723
|
let tabulator = new TabulatorFull($extend, tabulator_settings);
|
|
12724
|
+
yui_tabulator_keep_edit_on_redraw(tabulator);
|
|
12629
12725
|
tabulator.on("dataChanged", function() {
|
|
12630
12726
|
if (gobj.priv.loading_rows > 0) return;
|
|
12631
12727
|
gobj_send_event(gobj, "EV_RECORD_CHANGED", {}, gobj);
|
|
@@ -13231,10 +13327,10 @@ function set_form_values(gobj, template, $form, record) {
|
|
|
13231
13327
|
switch (input_type) {
|
|
13232
13328
|
case "datetime-local":
|
|
13233
13329
|
$input.value = date_to_datetime_local(value);
|
|
13234
|
-
$input.yui_time_kept = {
|
|
13330
|
+
$input.yui_time_kept = $input.value !== "" ? {
|
|
13235
13331
|
value: stored,
|
|
13236
13332
|
shown: $input.value
|
|
13237
|
-
};
|
|
13333
|
+
} : null;
|
|
13238
13334
|
break;
|
|
13239
13335
|
case "color":
|
|
13240
13336
|
$input.value = convertColor(value);
|
|
@@ -15150,11 +15246,7 @@ function intl(locale, opts) {
|
|
|
15150
15246
|
let key = locale + "|" + JSON.stringify(opts);
|
|
15151
15247
|
let f = __formatters__.get(key);
|
|
15152
15248
|
if (!f) {
|
|
15153
|
-
|
|
15154
|
-
f = new Intl.DateTimeFormat(locale, opts);
|
|
15155
|
-
} catch (e) {
|
|
15156
|
-
f = new Intl.DateTimeFormat("en", opts);
|
|
15157
|
-
}
|
|
15249
|
+
f = date_time_format(locale, opts);
|
|
15158
15250
|
__formatters__.set(key, f);
|
|
15159
15251
|
}
|
|
15160
15252
|
return f;
|
|
@@ -33018,6 +33110,7 @@ function create_tabulator(gobj) {
|
|
|
33018
33110
|
return;
|
|
33019
33111
|
}
|
|
33020
33112
|
let tabulator = new TabulatorFull($table_el, Object.assign({}, tabulator_settings, yui_tabulator_lang(t), { placeholder: t("no data available", { defaultValue: "No data available" }) }));
|
|
33113
|
+
yui_tabulator_keep_edit_on_redraw(tabulator);
|
|
33021
33114
|
if (with_checkbox) $table_el.classList.add("yui-no-row-hover");
|
|
33022
33115
|
function update_rowcount(explicit_count) {
|
|
33023
33116
|
let $rc = tabulator.element && tabulator.element.querySelector(".yui-tabulator-rowcount");
|
|
@@ -83166,11 +83259,7 @@ function tr(t, key, params) {
|
|
|
83166
83259
|
* the library has no business owning.
|
|
83167
83260
|
***************************************************************/
|
|
83168
83261
|
function fmt_intl(date, locale, opts) {
|
|
83169
|
-
|
|
83170
|
-
return new Intl.DateTimeFormat(safe_locale(locale), opts).format(date);
|
|
83171
|
-
} catch (e) {
|
|
83172
|
-
return date.toDateString();
|
|
83173
|
-
}
|
|
83262
|
+
return date_time_format(locale, opts).format(date);
|
|
83174
83263
|
}
|
|
83175
83264
|
/***************************
|
|
83176
83265
|
* Epoch <-> clock
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yuneta/gobj-ui",
|
|
3
|
-
"version": "7.26.
|
|
3
|
+
"version": "7.26.55",
|
|
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
|
},
|
|
@@ -341,6 +341,7 @@
|
|
|
341
341
|
***********************************************************************/
|
|
342
342
|
import {readdirSync, readFileSync, existsSync, statSync, realpathSync} from "fs";
|
|
343
343
|
import {spawnSync} from "child_process";
|
|
344
|
+
import {randomBytes} from "crypto";
|
|
344
345
|
import {resolve, relative} from "path";
|
|
345
346
|
import {pathToFileURL, fileURLToPath} from "url";
|
|
346
347
|
import {I18N_KEY_FUNCTIONS} from "../src/i18n_key_functions.js";
|
|
@@ -581,6 +582,13 @@ function load_locales(locales_dir)
|
|
|
581
582
|
* in the locales' process, is a violation; that process ending
|
|
582
583
|
* before its report, or not reporting in LOCALES_TIMEOUT_MS, aborts
|
|
583
584
|
* the run: no language could be checked.
|
|
585
|
+
*
|
|
586
|
+
* The report must carry a nonce the process reads on its stdin
|
|
587
|
+
* before it imports any locale, so a report a locale writes to the
|
|
588
|
+
* channel itself is refused (up to gobj-ui 7.26.54 it was the
|
|
589
|
+
* verdict). This stops accidents and the shapes named here, not
|
|
590
|
+
* deliberate malice: a locale is the app's own code, and the
|
|
591
|
+
* process is no sandbox.
|
|
584
592
|
***************************************************************/
|
|
585
593
|
const LOCALES_TIMEOUT_MS = 60000;
|
|
586
594
|
|
|
@@ -590,9 +598,11 @@ function import_locales(locales_dir, codes)
|
|
|
590
598
|
dir: locales_dir.href,
|
|
591
599
|
codes: codes.map((code) => [code, locale_export_names(code)])
|
|
592
600
|
});
|
|
601
|
+
let nonce = randomBytes(16).toString("hex");
|
|
593
602
|
let r = spawnSync(process.execPath,
|
|
594
603
|
[...process.execArgv, "-e", `(${report_locales.toString()})(${request});`], {
|
|
595
|
-
|
|
604
|
+
input: nonce,
|
|
605
|
+
stdio: ["pipe", "inherit", "inherit", "pipe"],
|
|
596
606
|
timeout: LOCALES_TIMEOUT_MS,
|
|
597
607
|
killSignal: "SIGKILL",
|
|
598
608
|
maxBuffer: 1 << 30
|
|
@@ -615,7 +625,8 @@ function import_locales(locales_dir, codes)
|
|
|
615
625
|
report = null;
|
|
616
626
|
}
|
|
617
627
|
}
|
|
618
|
-
if(r.status !== 0 || !report ||
|
|
628
|
+
if(r.status !== 0 || !report || report.nonce !== nonce ||
|
|
629
|
+
typeof report.locales !== "object" || !Array.isArray(report.problems)) {
|
|
619
630
|
let how = r.signal? `killed by ${r.signal}` : `exit code ${r.status}`;
|
|
620
631
|
abort(`${AT} ended (${how}) before it reported what they export` +
|
|
621
632
|
`${text? ", or reported what is not its report" : ""}: ${WHY} (a top-level await that ` +
|
|
@@ -635,9 +646,12 @@ function import_locales(locales_dir, codes)
|
|
|
635
646
|
/***************************************************************
|
|
636
647
|
* The code of the locales' process (import_locales()), run there
|
|
637
648
|
* from its text: it can use nothing of this module but its
|
|
638
|
-
* argument. What it calls after the
|
|
639
|
-
* them, so a locale that replaces
|
|
640
|
-
* JSON.stringify does not reach the report
|
|
649
|
+
* argument and the nonce on its stdin. What it calls after the
|
|
650
|
+
* locales ran is taken BEFORE them, so a locale that replaces
|
|
651
|
+
* process.reallyExit or JSON.stringify does not reach the report,
|
|
652
|
+
* and the report is written by hand from strings (JSON.stringify of
|
|
653
|
+
* a primitive string reads no toJSON): a toJSON a locale puts on
|
|
654
|
+
* Object.prototype or Array.prototype is never called. It reports after a
|
|
641
655
|
* timer of 0 and an immediate: a promise a locale rejects in such
|
|
642
656
|
* a timer, with nothing to handle it, is told first. Its own end is
|
|
643
657
|
* process.reallyExit(0): no exit handler of a locale runs, and a
|
|
@@ -645,47 +659,75 @@ function import_locales(locales_dir, codes)
|
|
|
645
659
|
***************************************************************/
|
|
646
660
|
async function report_locales(request)
|
|
647
661
|
{
|
|
648
|
-
const {writeSync} = await import("node:fs");
|
|
662
|
+
const {writeSync, readFileSync} = await import("node:fs");
|
|
663
|
+
const nonce = readFileSync(0, "utf8");
|
|
649
664
|
const really_exit = process.reallyExit.bind(process);
|
|
650
665
|
const stringify = JSON.stringify;
|
|
651
666
|
const keys_of = Object.keys;
|
|
652
667
|
const set_timeout = setTimeout;
|
|
653
668
|
const set_immediate = setImmediate;
|
|
654
669
|
const buffer_from = Buffer.from.bind(Buffer);
|
|
670
|
+
const define = Object.defineProperty;
|
|
671
|
+
const has_own = Object.hasOwn;
|
|
655
672
|
const problems = [];
|
|
673
|
+
const add_problem = (text) => {
|
|
674
|
+
define(problems, problems.length, {value: String(text), enumerable: true});
|
|
675
|
+
};
|
|
676
|
+
const list_text = (list) => {
|
|
677
|
+
let text = "[";
|
|
678
|
+
for(let i = 0; i < list.length; i++) {
|
|
679
|
+
text += (i? "," : "") + stringify(String(list[i]));
|
|
680
|
+
}
|
|
681
|
+
return text + "]";
|
|
682
|
+
};
|
|
656
683
|
process.on("unhandledRejection", (reason) => {
|
|
657
|
-
|
|
684
|
+
add_problem(`a promise was rejected and nothing handled it: ${(reason && reason.stack) || reason}`);
|
|
658
685
|
});
|
|
659
686
|
process.on("uncaughtException", (e) => {
|
|
660
|
-
|
|
687
|
+
add_problem(`an exception was thrown and nothing caught it: ${(e && e.stack) || e}`);
|
|
661
688
|
});
|
|
662
689
|
const locales = {};
|
|
663
|
-
|
|
690
|
+
const set_locale = (code, value) => {
|
|
691
|
+
define(locales, code, {value, enumerable: true});
|
|
692
|
+
};
|
|
693
|
+
for(let c = 0; c < request.codes.length; c++) {
|
|
694
|
+
const code = request.codes[c][0];
|
|
695
|
+
const names = request.codes[c][1];
|
|
664
696
|
try {
|
|
665
697
|
const mod = await import(new URL(`${code}.js`, request.dir).href);
|
|
666
698
|
let locale = null;
|
|
667
|
-
for(
|
|
668
|
-
if(mod[
|
|
669
|
-
locale = mod[
|
|
699
|
+
for(let n = 0; n < names.length; n++) {
|
|
700
|
+
if(mod[names[n]]) {
|
|
701
|
+
locale = mod[names[n]];
|
|
670
702
|
break;
|
|
671
703
|
}
|
|
672
704
|
}
|
|
673
705
|
locale = locale || mod.default;
|
|
674
706
|
if(!locale || !locale.translation || typeof locale.translation !== "object") {
|
|
675
|
-
|
|
707
|
+
set_locale(code, {none: true});
|
|
676
708
|
} else {
|
|
677
|
-
|
|
709
|
+
set_locale(code, {
|
|
678
710
|
keys: keys_of(locale.translation),
|
|
679
711
|
name: (typeof locale.name === "string" && locale.name)? locale.name : null
|
|
680
|
-
};
|
|
712
|
+
});
|
|
681
713
|
}
|
|
682
714
|
} catch(e) {
|
|
683
|
-
|
|
715
|
+
set_locale(code, {error: String((e && e.message) || e)});
|
|
684
716
|
}
|
|
685
717
|
}
|
|
686
718
|
set_timeout(() => {
|
|
687
719
|
set_immediate(() => {
|
|
688
|
-
|
|
720
|
+
let text = `{"nonce":${stringify(nonce)},"problems":${list_text(problems)},"locales":{`;
|
|
721
|
+
for(let i = 0; i < request.codes.length; i++) {
|
|
722
|
+
const code = request.codes[i][0];
|
|
723
|
+
const one = locales[code];
|
|
724
|
+
text += (i? "," : "") + stringify(code) + ":" + (
|
|
725
|
+
has_own(one, "none")? `{"none":true}` :
|
|
726
|
+
has_own(one, "error")? `{"error":${stringify(one.error)}}` :
|
|
727
|
+
`{"keys":${list_text(one.keys)},"name":${one.name === null? "null" : stringify(one.name)}}`
|
|
728
|
+
);
|
|
729
|
+
}
|
|
730
|
+
const buf = buffer_from(text + "}}\n", "utf8");
|
|
689
731
|
let done = 0;
|
|
690
732
|
while(done < buf.length) {
|
|
691
733
|
done += writeSync(3, buf, done, buf.length - done);
|
package/src/c_yui_form.js
CHANGED
|
@@ -100,6 +100,7 @@ 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 {yui_tabulator_keep_edit_on_redraw} from "./yui_tabulator_edit.js";
|
|
103
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 {
|
|
@@ -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
|
|
@@ -3524,9 +3526,11 @@ function set_form_values(gobj, template, $form, record)
|
|
|
3524
3526
|
/* value is a Date (see treedb_value_2_form_value).
|
|
3525
3527
|
* The text kept is the one READ BACK: the browser
|
|
3526
3528
|
* drops seconds of :00, so the text written never
|
|
3527
|
-
* matches it (get_form_values).
|
|
3529
|
+
* matches it (get_form_values). An empty box keeps
|
|
3530
|
+
* nothing: it is no time, whatever was stored. */
|
|
3528
3531
|
$input.value = date_to_datetime_local(value);
|
|
3529
|
-
$input.yui_time_kept =
|
|
3532
|
+
$input.yui_time_kept = ($input.value !== "")?
|
|
3533
|
+
{value: stored, shown: $input.value} : null;
|
|
3530
3534
|
break;
|
|
3531
3535
|
case "color":
|
|
3532
3536
|
$input.value = convertColor(value);
|
|
@@ -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,
|
|
@@ -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
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
* All Rights Reserved.
|
|
13
13
|
***********************************************************************/
|
|
14
14
|
import {describe, test, expect} from "vitest";
|
|
15
|
+
import {set_log_callback} from "@yuneta/gobj-js";
|
|
15
16
|
import {fmt_date_time, safe_locale} from "./yui_time.js";
|
|
16
17
|
import {time_value_to_text} from "./form_time_value.js";
|
|
17
18
|
import {format_epoch} from "./json_view_helpers.js";
|
|
@@ -72,8 +73,36 @@ describe("fmt_date_time", () => {
|
|
|
72
73
|
expect(fmt_date_time(D, "")).toBe(fallback);
|
|
73
74
|
});
|
|
74
75
|
|
|
75
|
-
test("a locale Intl refuses
|
|
76
|
-
|
|
76
|
+
test("a locale Intl refuses writes in the environment's, as one it does not know, and says so once", () => {
|
|
77
|
+
const warnings = [];
|
|
78
|
+
set_log_callback((level, msg) => {
|
|
79
|
+
if(String(level) === "warning" && /date_time_format/.test(String(msg))) {
|
|
80
|
+
warnings.push(String(msg));
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
try {
|
|
84
|
+
const env = fmt_date_time(D, "xx"); /* well-formed, unknown: Intl's own fallback */
|
|
85
|
+
expect(env).toBe(new Intl.DateTimeFormat(undefined, {
|
|
86
|
+
day: "numeric", month: "short", year: "numeric",
|
|
87
|
+
hour: "2-digit", minute: "2-digit", second: "2-digit", hourCycle: "h23"
|
|
88
|
+
}).format(D));
|
|
89
|
+
expect(warnings).toEqual([]);
|
|
90
|
+
expect(fmt_date_time(D, "xx_YY")).toBe(env);
|
|
91
|
+
expect(fmt_date_time(D, "xx_YY")).toBe(env);
|
|
92
|
+
expect(fmt_date_time(D, "zz_ZZ")).toBe(env);
|
|
93
|
+
expect(warnings.length).toBe(2);
|
|
94
|
+
expect(warnings[0]).toMatch(/'xx_YY'/);
|
|
95
|
+
expect(warnings[1]).toMatch(/'zz_ZZ'/);
|
|
96
|
+
|
|
97
|
+
/* The axis of a chart falls back the same way, and says it once. */
|
|
98
|
+
const month = yui_uplot_fmt_date(() => "yy_QQ")("{MMM}");
|
|
99
|
+
expect(month(D)).toBe(new Intl.DateTimeFormat(undefined, {month: "short"}).format(D));
|
|
100
|
+
expect(month(D)).toBe(new Intl.DateTimeFormat(undefined, {month: "short"}).format(D));
|
|
101
|
+
expect(warnings.length).toBe(3);
|
|
102
|
+
expect(warnings[2]).toMatch(/'yy_QQ'/);
|
|
103
|
+
} finally {
|
|
104
|
+
set_log_callback(null);
|
|
105
|
+
}
|
|
77
106
|
});
|
|
78
107
|
});
|
|
79
108
|
|
|
@@ -314,3 +314,31 @@ describe("a time in the repeated hour of autumn, saved with nothing touched", ()
|
|
|
314
314
|
});
|
|
315
315
|
});
|
|
316
316
|
});
|
|
317
|
+
|
|
318
|
+
describe("a stored value the box cannot show", () => {
|
|
319
|
+
test("is not saved back from the empty box: an empty box is no time", () => {
|
|
320
|
+
const app = gobj_create_pure_child("tapp6", "C_TEST_TIME_APP", {}, yuno);
|
|
321
|
+
gobj_start(app);
|
|
322
|
+
const form = gobj_create_pure_child("tform6", "C_YUI_FORM", {
|
|
323
|
+
template: {
|
|
324
|
+
as_epoch: {type: "integer", flag: ["writable", "persistent", "time"]},
|
|
325
|
+
as_text: {type: "string", flag: ["writable", "persistent", "time"]},
|
|
326
|
+
},
|
|
327
|
+
record: {as_epoch: "rubbish", as_text: "rubbish"},
|
|
328
|
+
editable: true,
|
|
329
|
+
}, app);
|
|
330
|
+
gobj_start(form);
|
|
331
|
+
|
|
332
|
+
expect(box(form, "as_epoch").value).toBe("");
|
|
333
|
+
expect(box(form, "as_text").value).toBe("");
|
|
334
|
+
gobj_send_event(form, "EV_SAVE_RECORD", {}, form);
|
|
335
|
+
expect(saved[0].as_epoch).toBe(null);
|
|
336
|
+
expect(saved[0].as_text).toBe(null);
|
|
337
|
+
|
|
338
|
+
/* A date typed and cleared again: the box is empty too. */
|
|
339
|
+
box(form, "as_epoch").value = WALL;
|
|
340
|
+
box(form, "as_epoch").value = "";
|
|
341
|
+
gobj_send_event(form, "EV_SAVE_RECORD", {}, form);
|
|
342
|
+
expect(saved[1].as_epoch).toBe(null);
|
|
343
|
+
});
|
|
344
|
+
});
|
package/src/yui_date_text.js
CHANGED
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
* Copyright (c) 2026, ArtGins.
|
|
13
13
|
* All Rights Reserved.
|
|
14
14
|
***********************************************************************/
|
|
15
|
+
import {log_warning} from "@yuneta/gobj-js";
|
|
15
16
|
|
|
16
17
|
/***************************************************************
|
|
17
18
|
* The locale to format with.
|
|
@@ -34,6 +35,32 @@ function safe_locale(locale)
|
|
|
34
35
|
return "en";
|
|
35
36
|
}
|
|
36
37
|
|
|
38
|
+
/* The locales Intl refused, said once each. */
|
|
39
|
+
const __refused_locales__ = new Set();
|
|
40
|
+
|
|
41
|
+
/***************************************************************
|
|
42
|
+
* An Intl.DateTimeFormat of `locale` with `options`. A locale
|
|
43
|
+
* Intl refuses (a malformed tag: "en_US") falls back to the
|
|
44
|
+
* environment's -- what Intl itself gives for a well-formed
|
|
45
|
+
* one it does not know ("xx") -- and is said in a WARNING, once
|
|
46
|
+
* per locale. fmt_date_time() and the ticks of a uPlot time axis
|
|
47
|
+
* (yui_uplot_time.js) both go through it, so they fall back the
|
|
48
|
+
* same way.
|
|
49
|
+
***************************************************************/
|
|
50
|
+
function date_time_format(locale, options)
|
|
51
|
+
{
|
|
52
|
+
let loc = safe_locale(locale);
|
|
53
|
+
try {
|
|
54
|
+
return new Intl.DateTimeFormat(loc, options);
|
|
55
|
+
} catch(e) {
|
|
56
|
+
if(!__refused_locales__.has(loc)) {
|
|
57
|
+
__refused_locales__.add(loc);
|
|
58
|
+
log_warning(`date_time_format: locale '${loc}' refused by Intl (${e}), using the environment's`);
|
|
59
|
+
}
|
|
60
|
+
return new Intl.DateTimeFormat(undefined, options);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
37
64
|
/* The clock is always 24 hours: `hourCycle`, never `hour12: false`,
|
|
38
65
|
* which some engines read as "h24" and show midnight as 24:00:00. */
|
|
39
66
|
const DATE_TIME_OPTIONS = {
|
|
@@ -52,7 +79,7 @@ const DATE_TIME_OPTIONS = {
|
|
|
52
79
|
* fmt_date_time(d, "en") -> "Oct 14, 2026, 15:05:09"
|
|
53
80
|
*
|
|
54
81
|
* "" for anything that is not a valid Date. A locale Intl refuses
|
|
55
|
-
*
|
|
82
|
+
* writes in the environment's (date_time_format).
|
|
56
83
|
*
|
|
57
84
|
* The time cells of C_YUI_FORM and C_YUI_TREEDB_TOPIC_WITH_FORM and
|
|
58
85
|
* the reading C_YUI_JSON writes beside a time field all come from
|
|
@@ -63,13 +90,7 @@ function fmt_date_time(date, locale)
|
|
|
63
90
|
if(!(date instanceof Date) || isNaN(date.getTime())) {
|
|
64
91
|
return "";
|
|
65
92
|
}
|
|
66
|
-
|
|
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
|
-
}
|
|
93
|
+
return date_time_format(locale, DATE_TIME_OPTIONS).format(date);
|
|
73
94
|
}
|
|
74
95
|
|
|
75
96
|
|
|
@@ -78,5 +99,6 @@ function fmt_date_time(date, locale)
|
|
|
78
99
|
***************************************************************/
|
|
79
100
|
export {
|
|
80
101
|
safe_locale,
|
|
102
|
+
date_time_format,
|
|
81
103
|
fmt_date_time,
|
|
82
104
|
};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/****************************************************************************
|
|
2
|
+
* yui_tabulator_edit.js
|
|
3
|
+
*
|
|
4
|
+
* An open cell editor survives a FORCED redraw of its table,
|
|
5
|
+
* and the other calls that build its cells again.
|
|
6
|
+
*
|
|
7
|
+
* `table.redraw(true)` builds every row's cells again, the one
|
|
8
|
+
* being edited too, and leaves Tabulator's edit pointing at the
|
|
9
|
+
* cell it threw away (it ends the edit before a data refresh,
|
|
10
|
+
* not before a redraw). Tabulator issues one itself, from
|
|
11
|
+
* ResizeTable's IntersectionObserver, the first time a table
|
|
12
|
+
* built out of sight comes into view -- and a click on a cell
|
|
13
|
+
* of a table below the fold scrolls it in AND opens the editor
|
|
14
|
+
* in the same turn. Chromium blurs the box it takes out, the
|
|
15
|
+
* editor's blur ends the edit on the dead cell, and Tabulator
|
|
16
|
+
* throws in Validate.editorClear ("reading 'remove'"); Firefox
|
|
17
|
+
* does not blur, and throws at the next edit. Any editor, ours
|
|
18
|
+
* (form_time_cell_editor.js) or Tabulator's own.
|
|
19
|
+
*
|
|
20
|
+
* `setColumns()` (a language change of
|
|
21
|
+
* C_YUI_TREEDB_TOPIC_WITH_FORM runs it) and `setHeight`,
|
|
22
|
+
* `setMaxHeight` and `setMinHeight` build the cells again the
|
|
23
|
+
* same way, and Tabulator throws the same.
|
|
24
|
+
*
|
|
25
|
+
* So the edit is ended BEFORE each of those calls, while its cell
|
|
26
|
+
* is alive, and opened again on the new cell of the same row
|
|
27
|
+
* and column after it. What was typed in the box is lost; the
|
|
28
|
+
* editor stays open under the reader.
|
|
29
|
+
*
|
|
30
|
+
* Copyright (c) 2026, ArtGins.
|
|
31
|
+
* All Rights Reserved.
|
|
32
|
+
****************************************************************************/
|
|
33
|
+
import {log_warning} from "@yuneta/gobj-js";
|
|
34
|
+
|
|
35
|
+
/************************************************************
|
|
36
|
+
* Wrap the calls of `tabulator` that build the cells again --
|
|
37
|
+
* a forced `redraw`, `setColumns` and the three height setters
|
|
38
|
+
* -- so that each ends the open edit first and opens it again
|
|
39
|
+
* after.
|
|
40
|
+
************************************************************/
|
|
41
|
+
function yui_tabulator_keep_edit_on_redraw(tabulator)
|
|
42
|
+
{
|
|
43
|
+
let editing = null;
|
|
44
|
+
tabulator.on("cellEditing", function(cell) {
|
|
45
|
+
editing = cell;
|
|
46
|
+
});
|
|
47
|
+
tabulator.on("cellEdited", function() {
|
|
48
|
+
editing = null;
|
|
49
|
+
});
|
|
50
|
+
tabulator.on("cellEditCancelled", function() {
|
|
51
|
+
editing = null;
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
function keep_edit_around(name, rebuilds)
|
|
55
|
+
{
|
|
56
|
+
let original = tabulator[name].bind(tabulator);
|
|
57
|
+
tabulator[name] = function(...args) {
|
|
58
|
+
let cell = editing;
|
|
59
|
+
/* A success() with the value unchanged fires no cellEdited:
|
|
60
|
+
* the cell's class says whether it is still being edited. */
|
|
61
|
+
let $cell = cell? cell.getElement() : null;
|
|
62
|
+
if(!rebuilds(args) || !$cell || !$cell.classList.contains("tabulator-editing")) {
|
|
63
|
+
return original(...args);
|
|
64
|
+
}
|
|
65
|
+
let row = cell.getRow();
|
|
66
|
+
let field = cell.getField();
|
|
67
|
+
cell.cancelEdit();
|
|
68
|
+
let ret = original(...args);
|
|
69
|
+
let again = row.getCell(field);
|
|
70
|
+
if(!again) {
|
|
71
|
+
log_warning(`yui_tabulator_keep_edit_on_redraw: no cell '${field}' after ${name}()`);
|
|
72
|
+
return ret;
|
|
73
|
+
}
|
|
74
|
+
again.edit(true);
|
|
75
|
+
return ret;
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
keep_edit_around("redraw", (args) => !!args[0]);
|
|
80
|
+
for(const name of ["setColumns", "setHeight", "setMaxHeight", "setMinHeight"]) {
|
|
81
|
+
keep_edit_around(name, () => true);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export {yui_tabulator_keep_edit_on_redraw};
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/***********************************************************************
|
|
2
|
+
* yui_tabulator_edit.test.js
|
|
3
|
+
*
|
|
4
|
+
* yui_tabulator_keep_edit_on_redraw(): every Tabulator call that
|
|
5
|
+
* builds the cells again -- a forced redraw, setColumns() and the
|
|
6
|
+
* three height setters -- ends the open edit BEFORE it, while its
|
|
7
|
+
* cell is alive, and opens it again on the new cell after it.
|
|
8
|
+
* Nothing else is touched. The table is a double that records the
|
|
9
|
+
* order of the calls; that the real Tabulator throws without this
|
|
10
|
+
* is proved in a browser by scripts/qa-cell-editor.mjs.
|
|
11
|
+
*
|
|
12
|
+
* Copyright (c) 2026, ArtGins.
|
|
13
|
+
* All Rights Reserved.
|
|
14
|
+
***********************************************************************/
|
|
15
|
+
import {describe, test, expect, beforeEach} from "vitest";
|
|
16
|
+
import {yui_tabulator_keep_edit_on_redraw} from "./yui_tabulator_edit.js";
|
|
17
|
+
|
|
18
|
+
let calls = [];
|
|
19
|
+
|
|
20
|
+
function make_cell(row, field, editing)
|
|
21
|
+
{
|
|
22
|
+
const cell = {
|
|
23
|
+
field,
|
|
24
|
+
classes: new Set(editing? ["tabulator-editing"] : []),
|
|
25
|
+
getElement() {
|
|
26
|
+
return {classList: {contains: (c) => cell.classes.has(c)}};
|
|
27
|
+
},
|
|
28
|
+
getRow() {
|
|
29
|
+
return row;
|
|
30
|
+
},
|
|
31
|
+
getField() {
|
|
32
|
+
return field;
|
|
33
|
+
},
|
|
34
|
+
cancelEdit() {
|
|
35
|
+
calls.push(`cancel ${field}`);
|
|
36
|
+
cell.classes.delete("tabulator-editing");
|
|
37
|
+
},
|
|
38
|
+
edit(force) {
|
|
39
|
+
calls.push(`edit ${field} ${force}`);
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
return cell;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function make_table()
|
|
46
|
+
{
|
|
47
|
+
const handlers = {};
|
|
48
|
+
const row = {
|
|
49
|
+
getCell(field) {
|
|
50
|
+
calls.push(`getCell ${field}`);
|
|
51
|
+
return field === "gone"? false : make_cell(row, field, false);
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
const table = {
|
|
55
|
+
row,
|
|
56
|
+
on(name, fn) {
|
|
57
|
+
handlers[name] = fn;
|
|
58
|
+
},
|
|
59
|
+
emit(name, cell) {
|
|
60
|
+
handlers[name](cell);
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
for(const name of ["redraw", "setColumns", "setHeight", "setMaxHeight", "setMinHeight"]) {
|
|
64
|
+
table[name] = function(...args) {
|
|
65
|
+
calls.push(`${name}(${args.join(",")})`);
|
|
66
|
+
return `${name} done`;
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
yui_tabulator_keep_edit_on_redraw(table);
|
|
70
|
+
return table;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
beforeEach(() => {
|
|
74
|
+
calls = [];
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
describe("an open edit around a call that builds the cells again", () => {
|
|
78
|
+
for(const [name, args] of [
|
|
79
|
+
["redraw", [true]],
|
|
80
|
+
["setColumns", [["defs"]]],
|
|
81
|
+
["setHeight", [300]],
|
|
82
|
+
["setMaxHeight", [400]],
|
|
83
|
+
["setMinHeight", [100]],
|
|
84
|
+
]) {
|
|
85
|
+
test(`${name}: ended before, opened again after, the answer passed on`, () => {
|
|
86
|
+
const table = make_table();
|
|
87
|
+
table.emit("cellEditing", make_cell(table.row, "when", true));
|
|
88
|
+
const ret = table[name](...args);
|
|
89
|
+
expect(ret).toBe(`${name} done`);
|
|
90
|
+
expect(calls).toEqual([
|
|
91
|
+
"cancel when",
|
|
92
|
+
`${name}(${args.join(",")})`,
|
|
93
|
+
"getCell when",
|
|
94
|
+
"edit when true",
|
|
95
|
+
]);
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
describe("what it leaves alone", () => {
|
|
101
|
+
test("a redraw that is not forced", () => {
|
|
102
|
+
const table = make_table();
|
|
103
|
+
table.emit("cellEditing", make_cell(table.row, "when", true));
|
|
104
|
+
table.redraw();
|
|
105
|
+
table.redraw(false);
|
|
106
|
+
expect(calls).toEqual(["redraw()", "redraw(false)"]);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
test("no edit open: never opened, ended, or ended without cellEdited", () => {
|
|
110
|
+
const table = make_table();
|
|
111
|
+
table.setColumns(["a"]);
|
|
112
|
+
const cell = make_cell(table.row, "when", true);
|
|
113
|
+
table.emit("cellEditing", cell);
|
|
114
|
+
table.emit("cellEdited", cell);
|
|
115
|
+
table.setHeight(10);
|
|
116
|
+
table.emit("cellEditing", cell);
|
|
117
|
+
table.emit("cellEditCancelled", cell);
|
|
118
|
+
table.redraw(true);
|
|
119
|
+
/* A success() with the value unchanged fires no cellEdited. */
|
|
120
|
+
table.emit("cellEditing", cell);
|
|
121
|
+
cell.classes.delete("tabulator-editing");
|
|
122
|
+
table.setMinHeight(5);
|
|
123
|
+
expect(calls).toEqual(["setColumns(a)", "setHeight(10)", "redraw(true)", "setMinHeight(5)"]);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
test("a column the new columns do not have: the edit stays closed", () => {
|
|
127
|
+
const table = make_table();
|
|
128
|
+
table.emit("cellEditing", make_cell(table.row, "gone", true));
|
|
129
|
+
expect(table.setColumns(["other"])).toBe("setColumns done");
|
|
130
|
+
expect(calls).toEqual(["cancel gone", "setColumns(other)", "getCell gone"]);
|
|
131
|
+
});
|
|
132
|
+
});
|
package/src/yui_time.js
CHANGED
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
/* The text of a moment lives in a module of its own, which carries no
|
|
48
48
|
* i18n key: a view that formats a time must not make the validator ask
|
|
49
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";
|
|
50
|
+
import {safe_locale, date_time_format, fmt_date_time} from "./yui_date_text.js";
|
|
51
51
|
|
|
52
52
|
/***************************************************************
|
|
53
53
|
* Constants
|
|
@@ -140,12 +140,7 @@ function tr(t, key, params)
|
|
|
140
140
|
***************************************************************/
|
|
141
141
|
function fmt_intl(date, locale, opts)
|
|
142
142
|
{
|
|
143
|
-
|
|
144
|
-
return new Intl.DateTimeFormat(safe_locale(locale), opts).format(date);
|
|
145
|
-
} catch(e) {
|
|
146
|
-
/* A locale Intl refuses is not worth a broken screen. */
|
|
147
|
-
return date.toDateString();
|
|
148
|
-
}
|
|
143
|
+
return date_time_format(locale, opts).format(date);
|
|
149
144
|
}
|
|
150
145
|
|
|
151
146
|
|
package/src/yui_uplot_time.js
CHANGED
|
@@ -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_date_text.js";
|
|
30
|
+
import {fmt_date_time, safe_locale, date_time_format} 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}";
|
|
@@ -43,11 +43,7 @@ function intl(locale, opts)
|
|
|
43
43
|
let key = locale + "|" + JSON.stringify(opts);
|
|
44
44
|
let f = __formatters__.get(key);
|
|
45
45
|
if(!f) {
|
|
46
|
-
|
|
47
|
-
f = new Intl.DateTimeFormat(locale, opts);
|
|
48
|
-
} catch(e) {
|
|
49
|
-
f = new Intl.DateTimeFormat("en", opts);
|
|
50
|
-
}
|
|
46
|
+
f = date_time_format(locale, opts);
|
|
51
47
|
__formatters__.set(key, f);
|
|
52
48
|
}
|
|
53
49
|
return f;
|