@yuneta/gobj-ui 7.26.52 → 7.26.53
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/dist/gobj-ui.cjs.js +664 -647
- package/dist/gobj-ui.es.js +664 -647
- package/package.json +1 -1
- package/src/c_yui_form.js +1 -1
- package/src/c_yui_json.js +1 -1
- package/src/c_yui_treedb_topic_with_form.js +1 -1
- package/src/form_time_value.js +1 -1
- package/src/json_view_helpers.js +1 -1
- package/src/yui_date_text.js +82 -0
- package/src/yui_time.js +5 -58
- package/src/yui_uplot_time.js +1 -1
package/package.json
CHANGED
package/src/c_yui_form.js
CHANGED
|
@@ -100,7 +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 {safe_locale} from "./
|
|
103
|
+
import {safe_locale} from "./yui_date_text.js";
|
|
104
104
|
import {parse_json_field, json_editor_value} from "./form_json_field.js";
|
|
105
105
|
import {
|
|
106
106
|
json_editor_menu_items,
|
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 "./
|
|
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";
|
|
@@ -99,7 +99,7 @@ import {
|
|
|
99
99
|
import {row_matches} from "./yui_row_search.js";
|
|
100
100
|
|
|
101
101
|
import i18next, {t} from "i18next";
|
|
102
|
-
import {safe_locale} from "./
|
|
102
|
+
import {safe_locale} from "./yui_date_text.js";
|
|
103
103
|
|
|
104
104
|
import {yui_toolbar_icon} from "./yui_toolbar.js";
|
|
105
105
|
|
package/src/form_time_value.js
CHANGED
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
* Copyright (c) 2026, ArtGins.
|
|
36
36
|
* All Rights Reserved.
|
|
37
37
|
****************************************************************************/
|
|
38
|
-
import {fmt_date_time} from "./
|
|
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,
|
package/src/json_view_helpers.js
CHANGED
|
@@ -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 "./
|
|
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
|
+
};
|
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
|
***************************/
|
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 "./
|
|
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}";
|