@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/dist/gobj-ui.cjs.js +727 -647
- package/dist/gobj-ui.es.js +727 -647
- package/package.json +2 -1
- package/src/c_yui_form.js +3 -1
- package/src/c_yui_json.js +1 -1
- package/src/c_yui_treedb_topic_with_form.js +3 -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_tabulator_edit.js +69 -0
- package/src/yui_time.js +5 -58
- package/src/yui_uplot_time.js +1 -1
package/dist/gobj-ui.cjs.js
CHANGED
|
@@ -9682,169 +9682,22 @@ function yui_icons_list() {
|
|
|
9682
9682
|
return list;
|
|
9683
9683
|
}
|
|
9684
9684
|
//#endregion
|
|
9685
|
-
//#region src/
|
|
9685
|
+
//#region src/yui_date_text.js
|
|
9686
9686
|
/***********************************************************************
|
|
9687
|
-
*
|
|
9688
|
-
*
|
|
9689
|
-
* Time, without a DOM: epochs, and the algebra of PERIODS.
|
|
9690
|
-
*
|
|
9691
|
-
* Two things live here, and they are the two halves of every date
|
|
9692
|
-
* UI the projects keep rewriting:
|
|
9693
|
-
*
|
|
9694
|
-
* 1) EPOCH <-> the local wall clock. A timestamp travels in the
|
|
9695
|
-
* producer's own unit — seconds, or milliseconds when a topic
|
|
9696
|
-
* says so — and every conversion crosses that `ms` flag. Getting
|
|
9697
|
-
* it wrong puts the same instant on two different clocks in one
|
|
9698
|
-
* screen (it did: a picker asking "from 18:55" local returned
|
|
9699
|
-
* rows a table labelled 16:55).
|
|
9700
|
-
*
|
|
9701
|
-
* 2) The PERIOD. A period is not an enum of five names: it is a
|
|
9702
|
-
* BUCKET, and a bucket is `count` of a `unit`:
|
|
9703
|
-
*
|
|
9704
|
-
* {id: "day", unit: "day", count: 1}
|
|
9705
|
-
* {id: "week", unit: "week", count: 1} ISO, Mon-first
|
|
9706
|
-
* {id: "bimester", unit: "month", count: 2}
|
|
9707
|
-
* {id: "quarter", unit: "month", count: 3}
|
|
9708
|
-
* {id: "semester", unit: "month", count: 6}
|
|
9709
|
-
* {id: "decade", unit: "year", count: 10}
|
|
9710
|
-
* {id: "15min", unit: "minute", count: 15}
|
|
9711
|
-
*
|
|
9712
|
-
* Given that pair, ONE implementation answers every question a
|
|
9713
|
-
* date navigator asks — where does the bucket holding this
|
|
9714
|
-
* instant start and end, what is the previous/next one, what do
|
|
9715
|
-
* I call it — so an app that wants quarters declares a quarter
|
|
9716
|
-
* instead of asking for a new component.
|
|
9717
|
-
*
|
|
9718
|
-
* Buckets are ALIGNED, never "count back from now": months align to
|
|
9719
|
-
* the year (which is why 2, 3, 4, 6 and 12 fall on clean calendar
|
|
9720
|
-
* boundaries), weeks to Monday, hours to local midnight. "Last 7
|
|
9721
|
-
* days" is a different animal — a rolling window — and it is not a
|
|
9722
|
-
* period: see `rolling_bounds()`.
|
|
9687
|
+
* yui_date_text.js
|
|
9723
9688
|
*
|
|
9724
|
-
*
|
|
9725
|
-
*
|
|
9726
|
-
*
|
|
9689
|
+
* A moment as a VIEW shows it as text, and the locale to show it
|
|
9690
|
+
* in. A module of its own, with no i18n key, on purpose: the views
|
|
9691
|
+
* that show a time (C_YUI_FORM, C_YUI_TREEDB_TOPIC_WITH_FORM,
|
|
9692
|
+
* C_YUI_JSON, C_YUI_UPLOT) import it, and validate-locales follows
|
|
9693
|
+
* the modules an app mounts -- importing yui_time.js for this made
|
|
9694
|
+
* every app that shows a time owe the keys of the period picker
|
|
9695
|
+
* (gobj-ui 7.26.52). yui_time.js re-exports both.
|
|
9727
9696
|
*
|
|
9728
9697
|
* Copyright (c) 2026, ArtGins.
|
|
9729
9698
|
* All Rights Reserved.
|
|
9730
9699
|
***********************************************************************/
|
|
9731
9700
|
/***************************************************************
|
|
9732
|
-
* Constants
|
|
9733
|
-
***************************************************************/
|
|
9734
|
-
var MS_DAY = 864e5;
|
|
9735
|
-
var PERIOD_UNITS = [
|
|
9736
|
-
"minute",
|
|
9737
|
-
"hour",
|
|
9738
|
-
"day",
|
|
9739
|
-
"week",
|
|
9740
|
-
"month",
|
|
9741
|
-
"year"
|
|
9742
|
-
];
|
|
9743
|
-
var YUI_PERIODS = {
|
|
9744
|
-
minute: {
|
|
9745
|
-
id: "minute",
|
|
9746
|
-
unit: "minute",
|
|
9747
|
-
count: 1
|
|
9748
|
-
},
|
|
9749
|
-
"5min": {
|
|
9750
|
-
id: "5min",
|
|
9751
|
-
unit: "minute",
|
|
9752
|
-
count: 5
|
|
9753
|
-
},
|
|
9754
|
-
"15min": {
|
|
9755
|
-
id: "15min",
|
|
9756
|
-
unit: "minute",
|
|
9757
|
-
count: 15
|
|
9758
|
-
},
|
|
9759
|
-
hour: {
|
|
9760
|
-
id: "hour",
|
|
9761
|
-
unit: "hour",
|
|
9762
|
-
count: 1
|
|
9763
|
-
},
|
|
9764
|
-
day: {
|
|
9765
|
-
id: "day",
|
|
9766
|
-
unit: "day",
|
|
9767
|
-
count: 1
|
|
9768
|
-
},
|
|
9769
|
-
week: {
|
|
9770
|
-
id: "week",
|
|
9771
|
-
unit: "week",
|
|
9772
|
-
count: 1
|
|
9773
|
-
},
|
|
9774
|
-
fortnight: {
|
|
9775
|
-
id: "fortnight",
|
|
9776
|
-
unit: "week",
|
|
9777
|
-
count: 2
|
|
9778
|
-
},
|
|
9779
|
-
month: {
|
|
9780
|
-
id: "month",
|
|
9781
|
-
unit: "month",
|
|
9782
|
-
count: 1
|
|
9783
|
-
},
|
|
9784
|
-
bimester: {
|
|
9785
|
-
id: "bimester",
|
|
9786
|
-
unit: "month",
|
|
9787
|
-
count: 2
|
|
9788
|
-
},
|
|
9789
|
-
quarter: {
|
|
9790
|
-
id: "quarter",
|
|
9791
|
-
unit: "month",
|
|
9792
|
-
count: 3
|
|
9793
|
-
},
|
|
9794
|
-
semester: {
|
|
9795
|
-
id: "semester",
|
|
9796
|
-
unit: "month",
|
|
9797
|
-
count: 6
|
|
9798
|
-
},
|
|
9799
|
-
year: {
|
|
9800
|
-
id: "year",
|
|
9801
|
-
unit: "year",
|
|
9802
|
-
count: 1
|
|
9803
|
-
},
|
|
9804
|
-
decade: {
|
|
9805
|
-
id: "decade",
|
|
9806
|
-
unit: "year",
|
|
9807
|
-
count: 10
|
|
9808
|
-
}
|
|
9809
|
-
};
|
|
9810
|
-
var YUI_PERIODS_DEFAULT = [
|
|
9811
|
-
"hour",
|
|
9812
|
-
"day",
|
|
9813
|
-
"week",
|
|
9814
|
-
"month",
|
|
9815
|
-
"year"
|
|
9816
|
-
];
|
|
9817
|
-
var YUI_ROLLING = {
|
|
9818
|
-
"1h": {
|
|
9819
|
-
id: "1h",
|
|
9820
|
-
secs: 3600,
|
|
9821
|
-
label: "last hour"
|
|
9822
|
-
},
|
|
9823
|
-
"6h": {
|
|
9824
|
-
id: "6h",
|
|
9825
|
-
secs: 21600,
|
|
9826
|
-
label: "last 6h"
|
|
9827
|
-
},
|
|
9828
|
-
"24h": {
|
|
9829
|
-
id: "24h",
|
|
9830
|
-
secs: 86400,
|
|
9831
|
-
label: "last 24h"
|
|
9832
|
-
},
|
|
9833
|
-
"7d": {
|
|
9834
|
-
id: "7d",
|
|
9835
|
-
secs: 604800,
|
|
9836
|
-
label: "last 7 days"
|
|
9837
|
-
},
|
|
9838
|
-
"30d": {
|
|
9839
|
-
id: "30d",
|
|
9840
|
-
secs: 2592e3,
|
|
9841
|
-
label: "last 30 days"
|
|
9842
|
-
}
|
|
9843
|
-
};
|
|
9844
|
-
/***************************
|
|
9845
|
-
* Locale / i18n
|
|
9846
|
-
***************************/
|
|
9847
|
-
/***************************************************************
|
|
9848
9701
|
* The locale to format with.
|
|
9849
9702
|
*
|
|
9850
9703
|
* NEVER at module top level, and never `navigator.language` raw:
|
|
@@ -9859,78 +9712,6 @@ function safe_locale(locale) {
|
|
|
9859
9712
|
if (typeof nav === "string" && nav && nav !== "undefined") return nav;
|
|
9860
9713
|
return "en";
|
|
9861
9714
|
}
|
|
9862
|
-
/***************************************************************
|
|
9863
|
-
* Translate through the APP's translator when it gave us one, and
|
|
9864
|
-
* degrade to the key itself otherwise — interpolating `{{x}}` by hand,
|
|
9865
|
-
* so a label never renders raw mustaches at a caller that has no i18n.
|
|
9866
|
-
***************************************************************/
|
|
9867
|
-
function tr(t, key, params) {
|
|
9868
|
-
if (typeof t === "function") return t(key, params);
|
|
9869
|
-
let s = key;
|
|
9870
|
-
for (let k in params || {}) s = s.replaceAll(`{{${k}}}`, String(params[k]));
|
|
9871
|
-
return s;
|
|
9872
|
-
}
|
|
9873
|
-
/***************************************************************
|
|
9874
|
-
* Intl formatters, built PER CALL (see safe_locale). They are cheap
|
|
9875
|
-
* next to a repaint, and caching them would need a locale-change hook
|
|
9876
|
-
* the library has no business owning.
|
|
9877
|
-
***************************************************************/
|
|
9878
|
-
function fmt_intl(date, locale, opts) {
|
|
9879
|
-
try {
|
|
9880
|
-
return new Intl.DateTimeFormat(safe_locale(locale), opts).format(date);
|
|
9881
|
-
} catch (e) {
|
|
9882
|
-
return date.toDateString();
|
|
9883
|
-
}
|
|
9884
|
-
}
|
|
9885
|
-
/***************************
|
|
9886
|
-
* Epoch <-> clock
|
|
9887
|
-
***************************/
|
|
9888
|
-
/***************************************************************
|
|
9889
|
-
* Epoch in the producer's unit -> milliseconds, and back.
|
|
9890
|
-
* `ms` true means the value already IS milliseconds.
|
|
9891
|
-
***************************************************************/
|
|
9892
|
-
function epoch_to_ms(value, ms) {
|
|
9893
|
-
if (!value) return 0;
|
|
9894
|
-
return ms ? value : value * 1e3;
|
|
9895
|
-
}
|
|
9896
|
-
function ms_to_epoch(value_ms, ms) {
|
|
9897
|
-
if (!value_ms) return 0;
|
|
9898
|
-
return ms ? value_ms : Math.floor(value_ms / 1e3);
|
|
9899
|
-
}
|
|
9900
|
-
/***************************************************************
|
|
9901
|
-
* The LOCAL wall-clock string an `<input type="datetime-local">` takes
|
|
9902
|
-
* ("YYYY-MM-DDTHH:MM:SS", which needs step=1 to keep the seconds), and
|
|
9903
|
-
* the parse back. Empty / unparseable -> 0, which is exactly how a
|
|
9904
|
-
* match condition reads an absent bound.
|
|
9905
|
-
***************************************************************/
|
|
9906
|
-
function epoch_to_local_input(value, ms) {
|
|
9907
|
-
if (!value) return "";
|
|
9908
|
-
let d = new Date(epoch_to_ms(value, ms));
|
|
9909
|
-
let pad = (n) => String(n).padStart(2, "0");
|
|
9910
|
-
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}T${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}`;
|
|
9911
|
-
}
|
|
9912
|
-
function local_input_to_epoch(v, ms) {
|
|
9913
|
-
if (!v) return 0;
|
|
9914
|
-
let parsed = Date.parse(v);
|
|
9915
|
-
if (Number.isNaN(parsed)) return 0;
|
|
9916
|
-
return ms_to_epoch(parsed, ms);
|
|
9917
|
-
}
|
|
9918
|
-
/***************************************************************
|
|
9919
|
-
* A timestamp for a table cell: the local wall clock, space-separated,
|
|
9920
|
-
* keeping the milliseconds when the producer bothered to send them (a
|
|
9921
|
-
* topic that sets sf_t_ms usually appends several records inside the
|
|
9922
|
-
* same second, and a column that hides that shows a column of ties).
|
|
9923
|
-
***************************************************************/
|
|
9924
|
-
function fmt_epoch(value, ms) {
|
|
9925
|
-
if (!value) return "";
|
|
9926
|
-
try {
|
|
9927
|
-
let s = epoch_to_local_input(value, ms).replace("T", " ");
|
|
9928
|
-
if (ms) s += `.${String(value % 1e3).padStart(3, "0")}`;
|
|
9929
|
-
return s;
|
|
9930
|
-
} catch (e) {
|
|
9931
|
-
return String(value);
|
|
9932
|
-
}
|
|
9933
|
-
}
|
|
9934
9715
|
var DATE_TIME_OPTIONS = {
|
|
9935
9716
|
day: "numeric",
|
|
9936
9717
|
month: "short",
|
|
@@ -9961,439 +9742,105 @@ function fmt_date_time(date, locale) {
|
|
|
9961
9742
|
try {
|
|
9962
9743
|
return new Intl.DateTimeFormat(safe_locale(locale), DATE_TIME_OPTIONS).format(date);
|
|
9963
9744
|
} catch (e) {
|
|
9964
|
-
|
|
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())}`;
|
|
9965
9747
|
}
|
|
9966
9748
|
}
|
|
9967
|
-
|
|
9968
|
-
*
|
|
9969
|
-
|
|
9970
|
-
|
|
9971
|
-
|
|
9972
|
-
|
|
9973
|
-
|
|
9974
|
-
|
|
9975
|
-
|
|
9976
|
-
|
|
9977
|
-
|
|
9978
|
-
|
|
9979
|
-
|
|
9980
|
-
let d = /* @__PURE__ */ new Date(n * MS_DAY);
|
|
9981
|
-
return new Date(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate());
|
|
9982
|
-
}
|
|
9983
|
-
/***************************************************************
|
|
9984
|
-
* The Monday of the week a date falls in (ISO: the week starts on
|
|
9985
|
-
* Monday, and Sunday closes it).
|
|
9986
|
-
***************************************************************/
|
|
9987
|
-
function start_of_iso_week(d) {
|
|
9988
|
-
let day = d.getDay();
|
|
9989
|
-
let back = day === 0 ? 6 : day - 1;
|
|
9990
|
-
return new Date(d.getFullYear(), d.getMonth(), d.getDate() - back);
|
|
9991
|
-
}
|
|
9992
|
-
/***************************************************************
|
|
9993
|
-
* The ISO week a date belongs to: {week, year}. The YEAR is the ISO
|
|
9994
|
-
* week-year, not the calendar year — 2026-12-31 lives in week 1 of
|
|
9995
|
-
* 2027, and a label that said "week 1 2026" would name a week six
|
|
9996
|
-
* months away.
|
|
9997
|
-
***************************************************************/
|
|
9998
|
-
function iso_week(d) {
|
|
9999
|
-
let monday = start_of_iso_week(d);
|
|
10000
|
-
let thursday = new Date(monday.getFullYear(), monday.getMonth(), monday.getDate() + 3);
|
|
10001
|
-
let jan1 = new Date(thursday.getFullYear(), 0, 1);
|
|
10002
|
-
return {
|
|
10003
|
-
week: Math.floor((day_number(thursday) - day_number(jan1)) / 7) + 1,
|
|
10004
|
-
year: thursday.getFullYear()
|
|
10005
|
-
};
|
|
10006
|
-
}
|
|
10007
|
-
/***************************************************************
|
|
10008
|
-
* The index of the ISO week a date falls in, counting weeks from the
|
|
10009
|
-
* Monday of the epoch week. It is what aligns a MULTI-week bucket (a
|
|
10010
|
-
* fortnight) to a Monday instead of to whatever day 1970-01-01 was.
|
|
10011
|
-
***************************************************************/
|
|
10012
|
-
function week_index(d) {
|
|
10013
|
-
return Math.floor((day_number(start_of_iso_week(d)) + 3) / 7);
|
|
10014
|
-
}
|
|
10015
|
-
/***************************
|
|
10016
|
-
* Period algebra
|
|
10017
|
-
***************************/
|
|
10018
|
-
/***************************************************************
|
|
10019
|
-
* Normalize whatever a caller hands us into a spec: an id of the
|
|
10020
|
-
* catalog, or a spec of its own. Returns null for anything that is not
|
|
10021
|
-
* a bucket (a "span" / "custom" mode of a navigator has no algebra).
|
|
10022
|
-
***************************************************************/
|
|
10023
|
-
function period_spec(period) {
|
|
10024
|
-
if (!period) return null;
|
|
10025
|
-
let spec = typeof period === "string" ? YUI_PERIODS[period] : period;
|
|
10026
|
-
if (!spec || !spec.unit) return null;
|
|
10027
|
-
if (PERIOD_UNITS.indexOf(spec.unit) < 0) return null;
|
|
10028
|
-
let count = parseInt(spec.count, 10);
|
|
10029
|
-
if (!(count > 0)) count = 1;
|
|
10030
|
-
return {
|
|
10031
|
-
id: spec.id || spec.unit,
|
|
10032
|
-
unit: spec.unit,
|
|
10033
|
-
count
|
|
10034
|
-
};
|
|
9749
|
+
/************************************************************
|
|
9750
|
+
* JSON type discriminator (viewer vocabulary)
|
|
9751
|
+
************************************************************/
|
|
9752
|
+
function json_type(value) {
|
|
9753
|
+
if (value === null) return "null";
|
|
9754
|
+
if (Array.isArray(value)) return "array";
|
|
9755
|
+
switch (typeof value) {
|
|
9756
|
+
case "string": return "string";
|
|
9757
|
+
case "number": return "number";
|
|
9758
|
+
case "boolean": return "boolean";
|
|
9759
|
+
case "object": return "object";
|
|
9760
|
+
default: return "unknown";
|
|
9761
|
+
}
|
|
10035
9762
|
}
|
|
10036
|
-
|
|
10037
|
-
*
|
|
9763
|
+
/************************************************************
|
|
9764
|
+
* Detect a kw_collapse() sentinel.
|
|
10038
9765
|
*
|
|
10039
|
-
*
|
|
10040
|
-
*
|
|
10041
|
-
*
|
|
9766
|
+
* The kernel replaces an over-limit dict with:
|
|
9767
|
+
* { "__collapsed__": { "path": ..., "size": N } }
|
|
9768
|
+
* and an over-limit array with:
|
|
9769
|
+
* [ { "__collapsed__": { "path": ..., "size": N } } ]
|
|
10042
9770
|
*
|
|
10043
|
-
*
|
|
10044
|
-
|
|
10045
|
-
|
|
10046
|
-
|
|
10047
|
-
|
|
10048
|
-
|
|
10049
|
-
|
|
10050
|
-
|
|
10051
|
-
|
|
10052
|
-
|
|
10053
|
-
|
|
10054
|
-
|
|
10055
|
-
if (!spec) return null;
|
|
10056
|
-
let d = new Date(anchor_ms);
|
|
10057
|
-
let n = spec.count;
|
|
10058
|
-
switch (spec.unit) {
|
|
10059
|
-
case "minute": {
|
|
10060
|
-
let m = Math.floor(d.getMinutes() / n) * n;
|
|
10061
|
-
return new Date(d.getFullYear(), d.getMonth(), d.getDate(), d.getHours(), m);
|
|
10062
|
-
}
|
|
10063
|
-
case "hour": {
|
|
10064
|
-
let h = Math.floor(d.getHours() / n) * n;
|
|
10065
|
-
return new Date(d.getFullYear(), d.getMonth(), d.getDate(), h);
|
|
10066
|
-
}
|
|
10067
|
-
case "day": return date_from_day_number(Math.floor(day_number(d) / n) * n);
|
|
10068
|
-
case "week": return date_from_day_number(Math.floor(week_index(d) / n) * n * 7 - 3);
|
|
10069
|
-
case "month": {
|
|
10070
|
-
let mi = d.getFullYear() * 12 + d.getMonth();
|
|
10071
|
-
let s = Math.floor(mi / n) * n;
|
|
10072
|
-
return new Date(Math.floor(s / 12), s % 12, 1);
|
|
9771
|
+
* Returns { size, path, is_array } or null.
|
|
9772
|
+
************************************************************/
|
|
9773
|
+
function is_collapsed(value) {
|
|
9774
|
+
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
9775
|
+
let keys = Object.keys(value);
|
|
9776
|
+
if (keys.length === 1 && keys[0] === "__collapsed__") {
|
|
9777
|
+
let c = value.__collapsed__ || {};
|
|
9778
|
+
return {
|
|
9779
|
+
size: c.size,
|
|
9780
|
+
path: c.path,
|
|
9781
|
+
is_array: false
|
|
9782
|
+
};
|
|
10073
9783
|
}
|
|
10074
|
-
|
|
10075
|
-
|
|
10076
|
-
|
|
9784
|
+
return null;
|
|
9785
|
+
}
|
|
9786
|
+
if (Array.isArray(value) && value.length === 1) {
|
|
9787
|
+
let e = value[0];
|
|
9788
|
+
if (e && typeof e === "object" && !Array.isArray(e) && Object.keys(e).length === 1 && e.__collapsed__) {
|
|
9789
|
+
let c = e.__collapsed__ || {};
|
|
9790
|
+
return {
|
|
9791
|
+
size: c.size,
|
|
9792
|
+
path: c.path,
|
|
9793
|
+
is_array: true
|
|
9794
|
+
};
|
|
10077
9795
|
}
|
|
10078
|
-
default: return null;
|
|
10079
9796
|
}
|
|
9797
|
+
return null;
|
|
10080
9798
|
}
|
|
10081
|
-
|
|
10082
|
-
*
|
|
10083
|
-
|
|
10084
|
-
|
|
10085
|
-
|
|
10086
|
-
|
|
10087
|
-
|
|
10088
|
-
let spec = period_spec(period);
|
|
10089
|
-
if (!spec) return anchor_ms;
|
|
10090
|
-
let s = period_start(spec, anchor_ms);
|
|
10091
|
-
let step = spec.count * (delta || 0);
|
|
10092
|
-
switch (spec.unit) {
|
|
10093
|
-
case "minute": return new Date(s.getFullYear(), s.getMonth(), s.getDate(), s.getHours(), s.getMinutes() + step).getTime();
|
|
10094
|
-
case "hour": return new Date(s.getFullYear(), s.getMonth(), s.getDate(), s.getHours() + step).getTime();
|
|
10095
|
-
case "day": return new Date(s.getFullYear(), s.getMonth(), s.getDate() + step).getTime();
|
|
10096
|
-
case "week": return new Date(s.getFullYear(), s.getMonth(), s.getDate() + step * 7).getTime();
|
|
10097
|
-
case "month": return new Date(s.getFullYear(), s.getMonth() + step, 1).getTime();
|
|
10098
|
-
case "year": return new Date(s.getFullYear() + step, 0, 1).getTime();
|
|
10099
|
-
default: return anchor_ms;
|
|
10100
|
-
}
|
|
9799
|
+
/************************************************************
|
|
9800
|
+
* Join / split absolute path segments (kernel convention)
|
|
9801
|
+
************************************************************/
|
|
9802
|
+
function seg_join(segments) {
|
|
9803
|
+
return segments.map(function(s) {
|
|
9804
|
+
return String(s);
|
|
9805
|
+
}).join("`");
|
|
10101
9806
|
}
|
|
10102
|
-
|
|
10103
|
-
|
|
10104
|
-
|
|
10105
|
-
* `to` is INCLUSIVE — the last millisecond of the bucket, not the first
|
|
10106
|
-
* of the next one. Both ends of a match condition are inclusive, and an
|
|
10107
|
-
* exclusive end handed to one silently swallows the record that landed
|
|
10108
|
-
* exactly on the boundary.
|
|
10109
|
-
***************************************************************/
|
|
10110
|
-
function period_bounds(period, anchor_ms) {
|
|
10111
|
-
let spec = period_spec(period);
|
|
10112
|
-
if (!spec) return {
|
|
10113
|
-
from: 0,
|
|
10114
|
-
to: 0
|
|
10115
|
-
};
|
|
10116
|
-
return {
|
|
10117
|
-
from: period_start(spec, anchor_ms).getTime(),
|
|
10118
|
-
to: period_shift(spec, anchor_ms, 1) - 1
|
|
10119
|
-
};
|
|
9807
|
+
function seg_split(path) {
|
|
9808
|
+
if (path === "" || path === null || path === void 0) return [];
|
|
9809
|
+
return path.split("`");
|
|
10120
9810
|
}
|
|
10121
|
-
|
|
10122
|
-
*
|
|
10123
|
-
*
|
|
10124
|
-
|
|
10125
|
-
|
|
10126
|
-
|
|
10127
|
-
let
|
|
10128
|
-
|
|
10129
|
-
|
|
10130
|
-
|
|
10131
|
-
|
|
10132
|
-
|
|
10133
|
-
|
|
10134
|
-
to: ms_to_epoch(b.to, ms)
|
|
10135
|
-
};
|
|
9811
|
+
/************************************************************
|
|
9812
|
+
* Walk a JSON tree by absolute segments; undefined if the
|
|
9813
|
+
* path does not resolve.
|
|
9814
|
+
************************************************************/
|
|
9815
|
+
function get_by_segments(root, segments) {
|
|
9816
|
+
let v = root;
|
|
9817
|
+
for (let seg of segments) {
|
|
9818
|
+
if (v === null || v === void 0) return;
|
|
9819
|
+
if (Array.isArray(v)) v = v[Number(seg)];
|
|
9820
|
+
else if (typeof v === "object") v = v[seg];
|
|
9821
|
+
else return;
|
|
9822
|
+
}
|
|
9823
|
+
return v;
|
|
10136
9824
|
}
|
|
10137
|
-
|
|
10138
|
-
*
|
|
10139
|
-
* previous and no next, it just ends at `now`.
|
|
9825
|
+
/************************************************************
|
|
9826
|
+
* Set a value at absolute segments (mutates root).
|
|
10140
9827
|
*
|
|
10141
|
-
*
|
|
10142
|
-
*
|
|
10143
|
-
*
|
|
10144
|
-
|
|
10145
|
-
function
|
|
10146
|
-
|
|
10147
|
-
|
|
10148
|
-
|
|
10149
|
-
|
|
10150
|
-
|
|
10151
|
-
|
|
10152
|
-
|
|
10153
|
-
to: 0
|
|
10154
|
-
};
|
|
10155
|
-
}
|
|
10156
|
-
/***************************************************************
|
|
10157
|
-
* Is this the LAST bucket — the one `now` falls in? It is what greys
|
|
10158
|
-
* out the "next" arrow, and what tells the navigator it is already home.
|
|
10159
|
-
***************************************************************/
|
|
10160
|
-
function is_current_period(period, anchor_ms, now_ms) {
|
|
10161
|
-
let spec = period_spec(period);
|
|
10162
|
-
if (!spec) return false;
|
|
10163
|
-
let now = now_ms === void 0 ? Date.now() : now_ms;
|
|
10164
|
-
let a = period_start(spec, anchor_ms);
|
|
10165
|
-
let b = period_start(spec, now);
|
|
10166
|
-
return !!a && !!b && a.getTime() === b.getTime();
|
|
9828
|
+
* segments == [] means "replace the whole root" — the caller
|
|
9829
|
+
* must use the RETURNED value in that case (a primitive/array
|
|
9830
|
+
* root cannot be mutated in place).
|
|
9831
|
+
************************************************************/
|
|
9832
|
+
function set_by_segments(root, segments, new_value) {
|
|
9833
|
+
if (segments.length === 0) return new_value;
|
|
9834
|
+
let parent = get_by_segments(root, segments.slice(0, -1));
|
|
9835
|
+
if (parent === null || parent === void 0 || typeof parent !== "object") return root;
|
|
9836
|
+
let last = segments[segments.length - 1];
|
|
9837
|
+
if (Array.isArray(parent)) parent[Number(last)] = new_value;
|
|
9838
|
+
else parent[last] = new_value;
|
|
9839
|
+
return root;
|
|
10167
9840
|
}
|
|
10168
|
-
|
|
10169
|
-
*
|
|
10170
|
-
*
|
|
10171
|
-
* as the period the user picked instead of as a hand-typed range.
|
|
10172
|
-
*
|
|
10173
|
-
* `from`/`to` are in the CONSUMER's unit (`ms`), and so is the
|
|
10174
|
-
* comparison — that is the whole trap: a bucket ends on the last
|
|
10175
|
-
* MILLISECOND (…23:59:59.999), and a consumer that keeps seconds stored
|
|
10176
|
-
* it truncated (…23:59:59). Comparing in milliseconds, a week saved by a
|
|
10177
|
-
* seconds-based topic came back as "no bucket at all", every time.
|
|
10178
|
-
*
|
|
10179
|
-
* Only an EXACT match counts: both ends must land on the bucket's own
|
|
10180
|
-
* boundaries, as that consumer would have written them. `candidates` are
|
|
10181
|
-
* ids/specs, tried in order. Returns {period, anchor} (anchor in ms) or
|
|
10182
|
-
* null.
|
|
10183
|
-
***************************************************************/
|
|
10184
|
-
function infer_period(from, to, candidates, ms) {
|
|
10185
|
-
if (!from || !to || to <= from) return null;
|
|
10186
|
-
let from_ms = epoch_to_ms(from, ms);
|
|
10187
|
-
for (let candidate of candidates || Object.keys(YUI_PERIODS)) {
|
|
10188
|
-
let spec = period_spec(candidate);
|
|
10189
|
-
if (!spec) continue;
|
|
10190
|
-
let b = period_bounds_epoch(spec, from_ms, ms);
|
|
10191
|
-
if (b.from === from && b.to === to) return {
|
|
10192
|
-
period: spec,
|
|
10193
|
-
anchor: from_ms
|
|
10194
|
-
};
|
|
10195
|
-
}
|
|
10196
|
-
return null;
|
|
10197
|
-
}
|
|
10198
|
-
/***************************
|
|
10199
|
-
* Period labels
|
|
10200
|
-
***************************/
|
|
10201
|
-
/***************************************************************
|
|
10202
|
-
* The name of a GRANULARITY (what the segmented control shows):
|
|
10203
|
-
* the spec's own id as an i18n key, so an app that declares
|
|
10204
|
-
* {id: "quarter"} gets "Trimestre" the moment it adds the key.
|
|
10205
|
-
***************************************************************/
|
|
10206
|
-
function period_name(period, t) {
|
|
10207
|
-
let spec = period_spec(period);
|
|
10208
|
-
if (!spec) return tr(t, String(period && period.id || period || ""));
|
|
10209
|
-
return tr(t, spec.id);
|
|
10210
|
-
}
|
|
10211
|
-
/***************************************************************
|
|
10212
|
-
* The name of the bucket a navigator is PARKED on: what goes between
|
|
10213
|
-
* the two arrows.
|
|
10214
|
-
*
|
|
10215
|
-
* day -> "Today" / "Yesterday" / "13 jul 2026"
|
|
10216
|
-
* week -> "Week 27" (+ year when it is not this one)
|
|
10217
|
-
* month -> "July" (+ year when it is not this one)
|
|
10218
|
-
* quarter -> "Q3 2026" (unit month, count 3)
|
|
10219
|
-
* semester -> "H2 2026" (unit month, count 6)
|
|
10220
|
-
* year -> "2026"
|
|
10221
|
-
* decade -> "2020 – 2029"
|
|
10222
|
-
* any other -> the bucket's own edges: "1 jul – 31 aug 2026"
|
|
10223
|
-
*
|
|
10224
|
-
* The named ones are named because a range reads worse than a name;
|
|
10225
|
-
* everything an app invents falls back to the range, which is always
|
|
10226
|
-
* true and never wrong.
|
|
10227
|
-
***************************************************************/
|
|
10228
|
-
function period_label(period, anchor_ms, t, locale) {
|
|
10229
|
-
let spec = period_spec(period);
|
|
10230
|
-
if (!spec) return "";
|
|
10231
|
-
let loc = safe_locale(locale);
|
|
10232
|
-
let start = period_start(spec, anchor_ms);
|
|
10233
|
-
let end = new Date(period_bounds(spec, anchor_ms).to);
|
|
10234
|
-
let now = /* @__PURE__ */ new Date();
|
|
10235
|
-
let this_year = start.getFullYear() === now.getFullYear();
|
|
10236
|
-
if (spec.unit === "day" && spec.count === 1) {
|
|
10237
|
-
let diff = day_number(start) - day_number(now);
|
|
10238
|
-
if (diff === 0) return tr(t, "today");
|
|
10239
|
-
if (diff === -1) return tr(t, "yesterday");
|
|
10240
|
-
if (diff === 1) return tr(t, "tomorrow");
|
|
10241
|
-
return fmt_intl(start, loc, this_year ? {
|
|
10242
|
-
day: "numeric",
|
|
10243
|
-
month: "short"
|
|
10244
|
-
} : {
|
|
10245
|
-
day: "numeric",
|
|
10246
|
-
month: "short",
|
|
10247
|
-
year: "numeric"
|
|
10248
|
-
});
|
|
10249
|
-
}
|
|
10250
|
-
if (spec.unit === "hour" && spec.count === 1) {
|
|
10251
|
-
let hh = fmt_intl(start, loc, {
|
|
10252
|
-
hour: "2-digit",
|
|
10253
|
-
minute: "2-digit"
|
|
10254
|
-
});
|
|
10255
|
-
if (day_number(start) === day_number(now)) return hh;
|
|
10256
|
-
return `${hh} · ${fmt_intl(start, loc, {
|
|
10257
|
-
day: "numeric",
|
|
10258
|
-
month: "short"
|
|
10259
|
-
})}`;
|
|
10260
|
-
}
|
|
10261
|
-
if (spec.unit === "week" && spec.count === 1) {
|
|
10262
|
-
let away = week_index(start) - week_index(now);
|
|
10263
|
-
if (away === 0) return tr(t, "this week");
|
|
10264
|
-
if (away === -1) return tr(t, "last week");
|
|
10265
|
-
let w = iso_week(start);
|
|
10266
|
-
return w.year === now.getFullYear() ? tr(t, "week {{n}}", { n: w.week }) : tr(t, "week {{n}} {{y}}", {
|
|
10267
|
-
n: w.week,
|
|
10268
|
-
y: w.year
|
|
10269
|
-
});
|
|
10270
|
-
}
|
|
10271
|
-
if (spec.unit === "month" && spec.count === 1) return fmt_intl(start, loc, this_year ? { month: "long" } : {
|
|
10272
|
-
month: "long",
|
|
10273
|
-
year: "numeric"
|
|
10274
|
-
});
|
|
10275
|
-
if (spec.unit === "month" && (spec.count === 3 || spec.count === 6)) {
|
|
10276
|
-
let n = Math.floor(start.getMonth() / spec.count) + 1;
|
|
10277
|
-
return tr(t, spec.count === 3 ? "quarter {{n}} {{y}}" : "semester {{n}} {{y}}", {
|
|
10278
|
-
n,
|
|
10279
|
-
y: start.getFullYear()
|
|
10280
|
-
});
|
|
10281
|
-
}
|
|
10282
|
-
if (spec.unit === "year") {
|
|
10283
|
-
if (spec.count === 1) return String(start.getFullYear());
|
|
10284
|
-
return `${start.getFullYear()} – ${end.getFullYear()}`;
|
|
10285
|
-
}
|
|
10286
|
-
let opts = spec.unit === "minute" || spec.unit === "hour" ? {
|
|
10287
|
-
day: "numeric",
|
|
10288
|
-
month: "short",
|
|
10289
|
-
hour: "2-digit",
|
|
10290
|
-
minute: "2-digit"
|
|
10291
|
-
} : {
|
|
10292
|
-
day: "numeric",
|
|
10293
|
-
month: "short"
|
|
10294
|
-
};
|
|
10295
|
-
if (start.getFullYear() !== end.getFullYear()) {
|
|
10296
|
-
let y_opts = Object.assign({ year: "numeric" }, opts);
|
|
10297
|
-
return `${fmt_intl(start, loc, y_opts)} – ${fmt_intl(end, loc, y_opts)}`;
|
|
10298
|
-
}
|
|
10299
|
-
let span = `${fmt_intl(start, loc, opts)} – ${fmt_intl(end, loc, opts)}`;
|
|
10300
|
-
return this_year ? span : `${span} ${start.getFullYear()}`;
|
|
10301
|
-
}
|
|
10302
|
-
/************************************************************
|
|
10303
|
-
* JSON type discriminator (viewer vocabulary)
|
|
10304
|
-
************************************************************/
|
|
10305
|
-
function json_type(value) {
|
|
10306
|
-
if (value === null) return "null";
|
|
10307
|
-
if (Array.isArray(value)) return "array";
|
|
10308
|
-
switch (typeof value) {
|
|
10309
|
-
case "string": return "string";
|
|
10310
|
-
case "number": return "number";
|
|
10311
|
-
case "boolean": return "boolean";
|
|
10312
|
-
case "object": return "object";
|
|
10313
|
-
default: return "unknown";
|
|
10314
|
-
}
|
|
10315
|
-
}
|
|
10316
|
-
/************************************************************
|
|
10317
|
-
* Detect a kw_collapse() sentinel.
|
|
10318
|
-
*
|
|
10319
|
-
* The kernel replaces an over-limit dict with:
|
|
10320
|
-
* { "__collapsed__": { "path": ..., "size": N } }
|
|
10321
|
-
* and an over-limit array with:
|
|
10322
|
-
* [ { "__collapsed__": { "path": ..., "size": N } } ]
|
|
10323
|
-
*
|
|
10324
|
-
* Returns { size, path, is_array } or null.
|
|
10325
|
-
************************************************************/
|
|
10326
|
-
function is_collapsed(value) {
|
|
10327
|
-
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
10328
|
-
let keys = Object.keys(value);
|
|
10329
|
-
if (keys.length === 1 && keys[0] === "__collapsed__") {
|
|
10330
|
-
let c = value.__collapsed__ || {};
|
|
10331
|
-
return {
|
|
10332
|
-
size: c.size,
|
|
10333
|
-
path: c.path,
|
|
10334
|
-
is_array: false
|
|
10335
|
-
};
|
|
10336
|
-
}
|
|
10337
|
-
return null;
|
|
10338
|
-
}
|
|
10339
|
-
if (Array.isArray(value) && value.length === 1) {
|
|
10340
|
-
let e = value[0];
|
|
10341
|
-
if (e && typeof e === "object" && !Array.isArray(e) && Object.keys(e).length === 1 && e.__collapsed__) {
|
|
10342
|
-
let c = e.__collapsed__ || {};
|
|
10343
|
-
return {
|
|
10344
|
-
size: c.size,
|
|
10345
|
-
path: c.path,
|
|
10346
|
-
is_array: true
|
|
10347
|
-
};
|
|
10348
|
-
}
|
|
10349
|
-
}
|
|
10350
|
-
return null;
|
|
10351
|
-
}
|
|
10352
|
-
/************************************************************
|
|
10353
|
-
* Join / split absolute path segments (kernel convention)
|
|
10354
|
-
************************************************************/
|
|
10355
|
-
function seg_join(segments) {
|
|
10356
|
-
return segments.map(function(s) {
|
|
10357
|
-
return String(s);
|
|
10358
|
-
}).join("`");
|
|
10359
|
-
}
|
|
10360
|
-
function seg_split(path) {
|
|
10361
|
-
if (path === "" || path === null || path === void 0) return [];
|
|
10362
|
-
return path.split("`");
|
|
10363
|
-
}
|
|
10364
|
-
/************************************************************
|
|
10365
|
-
* Walk a JSON tree by absolute segments; undefined if the
|
|
10366
|
-
* path does not resolve.
|
|
10367
|
-
************************************************************/
|
|
10368
|
-
function get_by_segments(root, segments) {
|
|
10369
|
-
let v = root;
|
|
10370
|
-
for (let seg of segments) {
|
|
10371
|
-
if (v === null || v === void 0) return;
|
|
10372
|
-
if (Array.isArray(v)) v = v[Number(seg)];
|
|
10373
|
-
else if (typeof v === "object") v = v[seg];
|
|
10374
|
-
else return;
|
|
10375
|
-
}
|
|
10376
|
-
return v;
|
|
10377
|
-
}
|
|
10378
|
-
/************************************************************
|
|
10379
|
-
* Set a value at absolute segments (mutates root).
|
|
10380
|
-
*
|
|
10381
|
-
* segments == [] means "replace the whole root" — the caller
|
|
10382
|
-
* must use the RETURNED value in that case (a primitive/array
|
|
10383
|
-
* root cannot be mutated in place).
|
|
10384
|
-
************************************************************/
|
|
10385
|
-
function set_by_segments(root, segments, new_value) {
|
|
10386
|
-
if (segments.length === 0) return new_value;
|
|
10387
|
-
let parent = get_by_segments(root, segments.slice(0, -1));
|
|
10388
|
-
if (parent === null || parent === void 0 || typeof parent !== "object") return root;
|
|
10389
|
-
let last = segments[segments.length - 1];
|
|
10390
|
-
if (Array.isArray(parent)) parent[Number(last)] = new_value;
|
|
10391
|
-
else parent[last] = new_value;
|
|
10392
|
-
return root;
|
|
10393
|
-
}
|
|
10394
|
-
/************************************************************
|
|
10395
|
-
* Does `value` (or any loaded descendant / its own key)
|
|
10396
|
-
* contain the lower-cased search term?
|
|
9841
|
+
/************************************************************
|
|
9842
|
+
* Does `value` (or any loaded descendant / its own key)
|
|
9843
|
+
* contain the lower-cased search term?
|
|
10397
9844
|
*
|
|
10398
9845
|
* Collapsed (not-yet-loaded) subtrees can't be searched, so
|
|
10399
9846
|
* they never match on content — only their key can match,
|
|
@@ -10875,6 +10322,67 @@ function form_time_cell_editor(real_type) {
|
|
|
10875
10322
|
};
|
|
10876
10323
|
}
|
|
10877
10324
|
//#endregion
|
|
10325
|
+
//#region src/yui_tabulator_edit.js
|
|
10326
|
+
/****************************************************************************
|
|
10327
|
+
* yui_tabulator_edit.js
|
|
10328
|
+
*
|
|
10329
|
+
* An open cell editor survives a FORCED redraw of its table.
|
|
10330
|
+
*
|
|
10331
|
+
* `table.redraw(true)` builds every row's cells again, the one
|
|
10332
|
+
* being edited too, and leaves Tabulator's edit pointing at the
|
|
10333
|
+
* cell it threw away (it ends the edit before a data refresh,
|
|
10334
|
+
* not before a redraw). Tabulator issues one itself, from
|
|
10335
|
+
* ResizeTable's IntersectionObserver, the first time a table
|
|
10336
|
+
* built out of sight comes into view -- and a click on a cell
|
|
10337
|
+
* of a table below the fold scrolls it in AND opens the editor
|
|
10338
|
+
* in the same turn. Chromium blurs the box it takes out, the
|
|
10339
|
+
* editor's blur ends the edit on the dead cell, and Tabulator
|
|
10340
|
+
* throws in Validate.editorClear ("reading 'remove'"); Firefox
|
|
10341
|
+
* does not blur, and throws at the next edit. Any editor, ours
|
|
10342
|
+
* (form_time_cell_editor.js) or Tabulator's own.
|
|
10343
|
+
*
|
|
10344
|
+
* So the edit is ended BEFORE the forced redraw, while its cell
|
|
10345
|
+
* is alive, and opened again on the new cell of the same row
|
|
10346
|
+
* and column after it. What was typed in the box is lost; the
|
|
10347
|
+
* editor stays open under the reader.
|
|
10348
|
+
*
|
|
10349
|
+
* Copyright (c) 2026, ArtGins.
|
|
10350
|
+
* All Rights Reserved.
|
|
10351
|
+
****************************************************************************/
|
|
10352
|
+
/************************************************************
|
|
10353
|
+
* Wrap `tabulator.redraw` so that a forced redraw ends the
|
|
10354
|
+
* open edit first and opens it again after.
|
|
10355
|
+
************************************************************/
|
|
10356
|
+
function yui_tabulator_keep_edit_on_redraw(tabulator) {
|
|
10357
|
+
let editing = null;
|
|
10358
|
+
tabulator.on("cellEditing", function(cell) {
|
|
10359
|
+
editing = cell;
|
|
10360
|
+
});
|
|
10361
|
+
tabulator.on("cellEdited", function() {
|
|
10362
|
+
editing = null;
|
|
10363
|
+
});
|
|
10364
|
+
tabulator.on("cellEditCancelled", function() {
|
|
10365
|
+
editing = null;
|
|
10366
|
+
});
|
|
10367
|
+
let redraw = tabulator.redraw.bind(tabulator);
|
|
10368
|
+
tabulator.redraw = function(force) {
|
|
10369
|
+
let cell = editing;
|
|
10370
|
+
let $cell = cell ? cell.getElement() : null;
|
|
10371
|
+
if (!force || !$cell || !$cell.classList.contains("tabulator-editing")) return redraw(force);
|
|
10372
|
+
let row = cell.getRow();
|
|
10373
|
+
let field = cell.getField();
|
|
10374
|
+
cell.cancelEdit();
|
|
10375
|
+
let ret = redraw(force);
|
|
10376
|
+
let again = row.getCell(field);
|
|
10377
|
+
if (!again) {
|
|
10378
|
+
(0, _yuneta_gobj_js.log_warning)(`yui_tabulator_keep_edit_on_redraw: no cell '${field}' after the redraw`);
|
|
10379
|
+
return ret;
|
|
10380
|
+
}
|
|
10381
|
+
again.edit(true);
|
|
10382
|
+
return ret;
|
|
10383
|
+
};
|
|
10384
|
+
}
|
|
10385
|
+
//#endregion
|
|
10878
10386
|
//#region src/form_json_field.js
|
|
10879
10387
|
/***********************************************************************
|
|
10880
10388
|
* form_json_field.js
|
|
@@ -13184,6 +12692,7 @@ function create_tabulator$1(gobj, $extend, name, template, rows) {
|
|
|
13184
12692
|
visible: (0, _yuneta_gobj_js.gobj_read_bool_attr)(gobj, "selectable")
|
|
13185
12693
|
};
|
|
13186
12694
|
let tabulator = new tabulator_tables.TabulatorFull($extend, tabulator_settings);
|
|
12695
|
+
yui_tabulator_keep_edit_on_redraw(tabulator);
|
|
13187
12696
|
tabulator.on("dataChanged", function() {
|
|
13188
12697
|
if (gobj.priv.loading_rows > 0) return;
|
|
13189
12698
|
(0, _yuneta_gobj_js.gobj_send_event)(gobj, "EV_RECORD_CHANGED", {}, gobj);
|
|
@@ -33576,6 +33085,7 @@ function create_tabulator(gobj) {
|
|
|
33576
33085
|
return;
|
|
33577
33086
|
}
|
|
33578
33087
|
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" }) }));
|
|
33088
|
+
yui_tabulator_keep_edit_on_redraw(tabulator);
|
|
33579
33089
|
if (with_checkbox) $table_el.classList.add("yui-no-row-hover");
|
|
33580
33090
|
function update_rowcount(explicit_count) {
|
|
33581
33091
|
let $rc = tabulator.element && tabulator.element.querySelector(".yui-tabulator-rowcount");
|
|
@@ -83545,6 +83055,576 @@ function register_c_yui_schema_editor() {
|
|
|
83545
83055
|
return create_gclass$1(GCLASS_NAME$1);
|
|
83546
83056
|
}
|
|
83547
83057
|
//#endregion
|
|
83058
|
+
//#region src/yui_time.js
|
|
83059
|
+
/***********************************************************************
|
|
83060
|
+
* yui_time.js
|
|
83061
|
+
*
|
|
83062
|
+
* Time, without a DOM: epochs, and the algebra of PERIODS.
|
|
83063
|
+
*
|
|
83064
|
+
* Two things live here, and they are the two halves of every date
|
|
83065
|
+
* UI the projects keep rewriting:
|
|
83066
|
+
*
|
|
83067
|
+
* 1) EPOCH <-> the local wall clock. A timestamp travels in the
|
|
83068
|
+
* producer's own unit — seconds, or milliseconds when a topic
|
|
83069
|
+
* says so — and every conversion crosses that `ms` flag. Getting
|
|
83070
|
+
* it wrong puts the same instant on two different clocks in one
|
|
83071
|
+
* screen (it did: a picker asking "from 18:55" local returned
|
|
83072
|
+
* rows a table labelled 16:55).
|
|
83073
|
+
*
|
|
83074
|
+
* 2) The PERIOD. A period is not an enum of five names: it is a
|
|
83075
|
+
* BUCKET, and a bucket is `count` of a `unit`:
|
|
83076
|
+
*
|
|
83077
|
+
* {id: "day", unit: "day", count: 1}
|
|
83078
|
+
* {id: "week", unit: "week", count: 1} ISO, Mon-first
|
|
83079
|
+
* {id: "bimester", unit: "month", count: 2}
|
|
83080
|
+
* {id: "quarter", unit: "month", count: 3}
|
|
83081
|
+
* {id: "semester", unit: "month", count: 6}
|
|
83082
|
+
* {id: "decade", unit: "year", count: 10}
|
|
83083
|
+
* {id: "15min", unit: "minute", count: 15}
|
|
83084
|
+
*
|
|
83085
|
+
* Given that pair, ONE implementation answers every question a
|
|
83086
|
+
* date navigator asks — where does the bucket holding this
|
|
83087
|
+
* instant start and end, what is the previous/next one, what do
|
|
83088
|
+
* I call it — so an app that wants quarters declares a quarter
|
|
83089
|
+
* instead of asking for a new component.
|
|
83090
|
+
*
|
|
83091
|
+
* Buckets are ALIGNED, never "count back from now": months align to
|
|
83092
|
+
* the year (which is why 2, 3, 4, 6 and 12 fall on clean calendar
|
|
83093
|
+
* boundaries), weeks to Monday, hours to local midnight. "Last 7
|
|
83094
|
+
* days" is a different animal — a rolling window — and it is not a
|
|
83095
|
+
* period: see `rolling_bounds()`.
|
|
83096
|
+
*
|
|
83097
|
+
* Everything here is LOCAL time (the user reads a local clock) and
|
|
83098
|
+
* DST-safe: it never adds 86400000 ms to cross a day, it builds the
|
|
83099
|
+
* next date from calendar fields and lets the platform do it.
|
|
83100
|
+
*
|
|
83101
|
+
* Copyright (c) 2026, ArtGins.
|
|
83102
|
+
* All Rights Reserved.
|
|
83103
|
+
***********************************************************************/
|
|
83104
|
+
/***************************************************************
|
|
83105
|
+
* Constants
|
|
83106
|
+
***************************************************************/
|
|
83107
|
+
var MS_DAY = 864e5;
|
|
83108
|
+
var PERIOD_UNITS = [
|
|
83109
|
+
"minute",
|
|
83110
|
+
"hour",
|
|
83111
|
+
"day",
|
|
83112
|
+
"week",
|
|
83113
|
+
"month",
|
|
83114
|
+
"year"
|
|
83115
|
+
];
|
|
83116
|
+
var YUI_PERIODS = {
|
|
83117
|
+
minute: {
|
|
83118
|
+
id: "minute",
|
|
83119
|
+
unit: "minute",
|
|
83120
|
+
count: 1
|
|
83121
|
+
},
|
|
83122
|
+
"5min": {
|
|
83123
|
+
id: "5min",
|
|
83124
|
+
unit: "minute",
|
|
83125
|
+
count: 5
|
|
83126
|
+
},
|
|
83127
|
+
"15min": {
|
|
83128
|
+
id: "15min",
|
|
83129
|
+
unit: "minute",
|
|
83130
|
+
count: 15
|
|
83131
|
+
},
|
|
83132
|
+
hour: {
|
|
83133
|
+
id: "hour",
|
|
83134
|
+
unit: "hour",
|
|
83135
|
+
count: 1
|
|
83136
|
+
},
|
|
83137
|
+
day: {
|
|
83138
|
+
id: "day",
|
|
83139
|
+
unit: "day",
|
|
83140
|
+
count: 1
|
|
83141
|
+
},
|
|
83142
|
+
week: {
|
|
83143
|
+
id: "week",
|
|
83144
|
+
unit: "week",
|
|
83145
|
+
count: 1
|
|
83146
|
+
},
|
|
83147
|
+
fortnight: {
|
|
83148
|
+
id: "fortnight",
|
|
83149
|
+
unit: "week",
|
|
83150
|
+
count: 2
|
|
83151
|
+
},
|
|
83152
|
+
month: {
|
|
83153
|
+
id: "month",
|
|
83154
|
+
unit: "month",
|
|
83155
|
+
count: 1
|
|
83156
|
+
},
|
|
83157
|
+
bimester: {
|
|
83158
|
+
id: "bimester",
|
|
83159
|
+
unit: "month",
|
|
83160
|
+
count: 2
|
|
83161
|
+
},
|
|
83162
|
+
quarter: {
|
|
83163
|
+
id: "quarter",
|
|
83164
|
+
unit: "month",
|
|
83165
|
+
count: 3
|
|
83166
|
+
},
|
|
83167
|
+
semester: {
|
|
83168
|
+
id: "semester",
|
|
83169
|
+
unit: "month",
|
|
83170
|
+
count: 6
|
|
83171
|
+
},
|
|
83172
|
+
year: {
|
|
83173
|
+
id: "year",
|
|
83174
|
+
unit: "year",
|
|
83175
|
+
count: 1
|
|
83176
|
+
},
|
|
83177
|
+
decade: {
|
|
83178
|
+
id: "decade",
|
|
83179
|
+
unit: "year",
|
|
83180
|
+
count: 10
|
|
83181
|
+
}
|
|
83182
|
+
};
|
|
83183
|
+
var YUI_PERIODS_DEFAULT = [
|
|
83184
|
+
"hour",
|
|
83185
|
+
"day",
|
|
83186
|
+
"week",
|
|
83187
|
+
"month",
|
|
83188
|
+
"year"
|
|
83189
|
+
];
|
|
83190
|
+
var YUI_ROLLING = {
|
|
83191
|
+
"1h": {
|
|
83192
|
+
id: "1h",
|
|
83193
|
+
secs: 3600,
|
|
83194
|
+
label: "last hour"
|
|
83195
|
+
},
|
|
83196
|
+
"6h": {
|
|
83197
|
+
id: "6h",
|
|
83198
|
+
secs: 21600,
|
|
83199
|
+
label: "last 6h"
|
|
83200
|
+
},
|
|
83201
|
+
"24h": {
|
|
83202
|
+
id: "24h",
|
|
83203
|
+
secs: 86400,
|
|
83204
|
+
label: "last 24h"
|
|
83205
|
+
},
|
|
83206
|
+
"7d": {
|
|
83207
|
+
id: "7d",
|
|
83208
|
+
secs: 604800,
|
|
83209
|
+
label: "last 7 days"
|
|
83210
|
+
},
|
|
83211
|
+
"30d": {
|
|
83212
|
+
id: "30d",
|
|
83213
|
+
secs: 2592e3,
|
|
83214
|
+
label: "last 30 days"
|
|
83215
|
+
}
|
|
83216
|
+
};
|
|
83217
|
+
/***************************
|
|
83218
|
+
* Locale / i18n
|
|
83219
|
+
***************************/
|
|
83220
|
+
/***************************************************************
|
|
83221
|
+
* Translate through the APP's translator when it gave us one, and
|
|
83222
|
+
* degrade to the key itself otherwise — interpolating `{{x}}` by hand,
|
|
83223
|
+
* so a label never renders raw mustaches at a caller that has no i18n.
|
|
83224
|
+
***************************************************************/
|
|
83225
|
+
function tr(t, key, params) {
|
|
83226
|
+
if (typeof t === "function") return t(key, params);
|
|
83227
|
+
let s = key;
|
|
83228
|
+
for (let k in params || {}) s = s.replaceAll(`{{${k}}}`, String(params[k]));
|
|
83229
|
+
return s;
|
|
83230
|
+
}
|
|
83231
|
+
/***************************************************************
|
|
83232
|
+
* Intl formatters, built PER CALL (see safe_locale). They are cheap
|
|
83233
|
+
* next to a repaint, and caching them would need a locale-change hook
|
|
83234
|
+
* the library has no business owning.
|
|
83235
|
+
***************************************************************/
|
|
83236
|
+
function fmt_intl(date, locale, opts) {
|
|
83237
|
+
try {
|
|
83238
|
+
return new Intl.DateTimeFormat(safe_locale(locale), opts).format(date);
|
|
83239
|
+
} catch (e) {
|
|
83240
|
+
return date.toDateString();
|
|
83241
|
+
}
|
|
83242
|
+
}
|
|
83243
|
+
/***************************
|
|
83244
|
+
* Epoch <-> clock
|
|
83245
|
+
***************************/
|
|
83246
|
+
/***************************************************************
|
|
83247
|
+
* Epoch in the producer's unit -> milliseconds, and back.
|
|
83248
|
+
* `ms` true means the value already IS milliseconds.
|
|
83249
|
+
***************************************************************/
|
|
83250
|
+
function epoch_to_ms(value, ms) {
|
|
83251
|
+
if (!value) return 0;
|
|
83252
|
+
return ms ? value : value * 1e3;
|
|
83253
|
+
}
|
|
83254
|
+
function ms_to_epoch(value_ms, ms) {
|
|
83255
|
+
if (!value_ms) return 0;
|
|
83256
|
+
return ms ? value_ms : Math.floor(value_ms / 1e3);
|
|
83257
|
+
}
|
|
83258
|
+
/***************************************************************
|
|
83259
|
+
* The LOCAL wall-clock string an `<input type="datetime-local">` takes
|
|
83260
|
+
* ("YYYY-MM-DDTHH:MM:SS", which needs step=1 to keep the seconds), and
|
|
83261
|
+
* the parse back. Empty / unparseable -> 0, which is exactly how a
|
|
83262
|
+
* match condition reads an absent bound.
|
|
83263
|
+
***************************************************************/
|
|
83264
|
+
function epoch_to_local_input(value, ms) {
|
|
83265
|
+
if (!value) return "";
|
|
83266
|
+
let d = new Date(epoch_to_ms(value, ms));
|
|
83267
|
+
let pad = (n) => String(n).padStart(2, "0");
|
|
83268
|
+
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}T${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}`;
|
|
83269
|
+
}
|
|
83270
|
+
function local_input_to_epoch(v, ms) {
|
|
83271
|
+
if (!v) return 0;
|
|
83272
|
+
let parsed = Date.parse(v);
|
|
83273
|
+
if (Number.isNaN(parsed)) return 0;
|
|
83274
|
+
return ms_to_epoch(parsed, ms);
|
|
83275
|
+
}
|
|
83276
|
+
/***************************************************************
|
|
83277
|
+
* A timestamp for a table cell: the local wall clock, space-separated,
|
|
83278
|
+
* keeping the milliseconds when the producer bothered to send them (a
|
|
83279
|
+
* topic that sets sf_t_ms usually appends several records inside the
|
|
83280
|
+
* same second, and a column that hides that shows a column of ties).
|
|
83281
|
+
***************************************************************/
|
|
83282
|
+
function fmt_epoch(value, ms) {
|
|
83283
|
+
if (!value) return "";
|
|
83284
|
+
try {
|
|
83285
|
+
let s = epoch_to_local_input(value, ms).replace("T", " ");
|
|
83286
|
+
if (ms) s += `.${String(value % 1e3).padStart(3, "0")}`;
|
|
83287
|
+
return s;
|
|
83288
|
+
} catch (e) {
|
|
83289
|
+
return String(value);
|
|
83290
|
+
}
|
|
83291
|
+
}
|
|
83292
|
+
/***************************
|
|
83293
|
+
* Calendar atoms
|
|
83294
|
+
***************************/
|
|
83295
|
+
/***************************************************************
|
|
83296
|
+
* The day number of a date, counting local calendar days from
|
|
83297
|
+
* 1970-01-01. Built from the FIELDS (Date.UTC of y/m/d), never from
|
|
83298
|
+
* the timestamp: a DST day is 23 or 25 hours long, so dividing a local
|
|
83299
|
+
* epoch by 86400000 drifts a day twice a year.
|
|
83300
|
+
***************************************************************/
|
|
83301
|
+
function day_number(d) {
|
|
83302
|
+
return Math.floor(Date.UTC(d.getFullYear(), d.getMonth(), d.getDate()) / MS_DAY);
|
|
83303
|
+
}
|
|
83304
|
+
function date_from_day_number(n) {
|
|
83305
|
+
let d = /* @__PURE__ */ new Date(n * MS_DAY);
|
|
83306
|
+
return new Date(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate());
|
|
83307
|
+
}
|
|
83308
|
+
/***************************************************************
|
|
83309
|
+
* The Monday of the week a date falls in (ISO: the week starts on
|
|
83310
|
+
* Monday, and Sunday closes it).
|
|
83311
|
+
***************************************************************/
|
|
83312
|
+
function start_of_iso_week(d) {
|
|
83313
|
+
let day = d.getDay();
|
|
83314
|
+
let back = day === 0 ? 6 : day - 1;
|
|
83315
|
+
return new Date(d.getFullYear(), d.getMonth(), d.getDate() - back);
|
|
83316
|
+
}
|
|
83317
|
+
/***************************************************************
|
|
83318
|
+
* The ISO week a date belongs to: {week, year}. The YEAR is the ISO
|
|
83319
|
+
* week-year, not the calendar year — 2026-12-31 lives in week 1 of
|
|
83320
|
+
* 2027, and a label that said "week 1 2026" would name a week six
|
|
83321
|
+
* months away.
|
|
83322
|
+
***************************************************************/
|
|
83323
|
+
function iso_week(d) {
|
|
83324
|
+
let monday = start_of_iso_week(d);
|
|
83325
|
+
let thursday = new Date(monday.getFullYear(), monday.getMonth(), monday.getDate() + 3);
|
|
83326
|
+
let jan1 = new Date(thursday.getFullYear(), 0, 1);
|
|
83327
|
+
return {
|
|
83328
|
+
week: Math.floor((day_number(thursday) - day_number(jan1)) / 7) + 1,
|
|
83329
|
+
year: thursday.getFullYear()
|
|
83330
|
+
};
|
|
83331
|
+
}
|
|
83332
|
+
/***************************************************************
|
|
83333
|
+
* The index of the ISO week a date falls in, counting weeks from the
|
|
83334
|
+
* Monday of the epoch week. It is what aligns a MULTI-week bucket (a
|
|
83335
|
+
* fortnight) to a Monday instead of to whatever day 1970-01-01 was.
|
|
83336
|
+
***************************************************************/
|
|
83337
|
+
function week_index(d) {
|
|
83338
|
+
return Math.floor((day_number(start_of_iso_week(d)) + 3) / 7);
|
|
83339
|
+
}
|
|
83340
|
+
/***************************
|
|
83341
|
+
* Period algebra
|
|
83342
|
+
***************************/
|
|
83343
|
+
/***************************************************************
|
|
83344
|
+
* Normalize whatever a caller hands us into a spec: an id of the
|
|
83345
|
+
* catalog, or a spec of its own. Returns null for anything that is not
|
|
83346
|
+
* a bucket (a "span" / "custom" mode of a navigator has no algebra).
|
|
83347
|
+
***************************************************************/
|
|
83348
|
+
function period_spec(period) {
|
|
83349
|
+
if (!period) return null;
|
|
83350
|
+
let spec = typeof period === "string" ? YUI_PERIODS[period] : period;
|
|
83351
|
+
if (!spec || !spec.unit) return null;
|
|
83352
|
+
if (PERIOD_UNITS.indexOf(spec.unit) < 0) return null;
|
|
83353
|
+
let count = parseInt(spec.count, 10);
|
|
83354
|
+
if (!(count > 0)) count = 1;
|
|
83355
|
+
return {
|
|
83356
|
+
id: spec.id || spec.unit,
|
|
83357
|
+
unit: spec.unit,
|
|
83358
|
+
count
|
|
83359
|
+
};
|
|
83360
|
+
}
|
|
83361
|
+
/***************************************************************
|
|
83362
|
+
* The START of the bucket that holds `anchor_ms`, as a local Date.
|
|
83363
|
+
*
|
|
83364
|
+
* Alignment is what makes a bucket a bucket. Each unit floors against
|
|
83365
|
+
* the natural origin of the unit above it, so the boundaries are the
|
|
83366
|
+
* ones a human already has in their head:
|
|
83367
|
+
*
|
|
83368
|
+
* minute -> the hour (a 15min bucket starts at :00/:15/:30/:45)
|
|
83369
|
+
* hour -> local midnight (a 6h bucket starts at 00/06/12/18)
|
|
83370
|
+
* day -> 1970-01-01 (count=1 is the plain day; a 10-day
|
|
83371
|
+
* bucket has no calendar origin to
|
|
83372
|
+
* align to, so it aligns to the epoch)
|
|
83373
|
+
* week -> the epoch week, Monday-first (ISO)
|
|
83374
|
+
* month -> January (which is why 2/3/4/6/12 give calendar
|
|
83375
|
+
* bimesters, quarters and semesters)
|
|
83376
|
+
* year -> year 0 (a decade starts at 2020, not 2021)
|
|
83377
|
+
***************************************************************/
|
|
83378
|
+
function period_start(period, anchor_ms) {
|
|
83379
|
+
let spec = period_spec(period);
|
|
83380
|
+
if (!spec) return null;
|
|
83381
|
+
let d = new Date(anchor_ms);
|
|
83382
|
+
let n = spec.count;
|
|
83383
|
+
switch (spec.unit) {
|
|
83384
|
+
case "minute": {
|
|
83385
|
+
let m = Math.floor(d.getMinutes() / n) * n;
|
|
83386
|
+
return new Date(d.getFullYear(), d.getMonth(), d.getDate(), d.getHours(), m);
|
|
83387
|
+
}
|
|
83388
|
+
case "hour": {
|
|
83389
|
+
let h = Math.floor(d.getHours() / n) * n;
|
|
83390
|
+
return new Date(d.getFullYear(), d.getMonth(), d.getDate(), h);
|
|
83391
|
+
}
|
|
83392
|
+
case "day": return date_from_day_number(Math.floor(day_number(d) / n) * n);
|
|
83393
|
+
case "week": return date_from_day_number(Math.floor(week_index(d) / n) * n * 7 - 3);
|
|
83394
|
+
case "month": {
|
|
83395
|
+
let mi = d.getFullYear() * 12 + d.getMonth();
|
|
83396
|
+
let s = Math.floor(mi / n) * n;
|
|
83397
|
+
return new Date(Math.floor(s / 12), s % 12, 1);
|
|
83398
|
+
}
|
|
83399
|
+
case "year": {
|
|
83400
|
+
let y = Math.floor(d.getFullYear() / n) * n;
|
|
83401
|
+
return new Date(y, 0, 1);
|
|
83402
|
+
}
|
|
83403
|
+
default: return null;
|
|
83404
|
+
}
|
|
83405
|
+
}
|
|
83406
|
+
/***************************************************************
|
|
83407
|
+
* The start of the bucket `delta` buckets away (delta may be negative).
|
|
83408
|
+
* Calendar arithmetic, never millisecond arithmetic: `new Date(y, m+3, 1)`
|
|
83409
|
+
* overflows the year by itself, and stepping a day across a DST change
|
|
83410
|
+
* keeps landing on midnight.
|
|
83411
|
+
***************************************************************/
|
|
83412
|
+
function period_shift(period, anchor_ms, delta) {
|
|
83413
|
+
let spec = period_spec(period);
|
|
83414
|
+
if (!spec) return anchor_ms;
|
|
83415
|
+
let s = period_start(spec, anchor_ms);
|
|
83416
|
+
let step = spec.count * (delta || 0);
|
|
83417
|
+
switch (spec.unit) {
|
|
83418
|
+
case "minute": return new Date(s.getFullYear(), s.getMonth(), s.getDate(), s.getHours(), s.getMinutes() + step).getTime();
|
|
83419
|
+
case "hour": return new Date(s.getFullYear(), s.getMonth(), s.getDate(), s.getHours() + step).getTime();
|
|
83420
|
+
case "day": return new Date(s.getFullYear(), s.getMonth(), s.getDate() + step).getTime();
|
|
83421
|
+
case "week": return new Date(s.getFullYear(), s.getMonth(), s.getDate() + step * 7).getTime();
|
|
83422
|
+
case "month": return new Date(s.getFullYear(), s.getMonth() + step, 1).getTime();
|
|
83423
|
+
case "year": return new Date(s.getFullYear() + step, 0, 1).getTime();
|
|
83424
|
+
default: return anchor_ms;
|
|
83425
|
+
}
|
|
83426
|
+
}
|
|
83427
|
+
/***************************************************************
|
|
83428
|
+
* The bucket holding `anchor_ms`, as {from, to} in MILLISECONDS.
|
|
83429
|
+
*
|
|
83430
|
+
* `to` is INCLUSIVE — the last millisecond of the bucket, not the first
|
|
83431
|
+
* of the next one. Both ends of a match condition are inclusive, and an
|
|
83432
|
+
* exclusive end handed to one silently swallows the record that landed
|
|
83433
|
+
* exactly on the boundary.
|
|
83434
|
+
***************************************************************/
|
|
83435
|
+
function period_bounds(period, anchor_ms) {
|
|
83436
|
+
let spec = period_spec(period);
|
|
83437
|
+
if (!spec) return {
|
|
83438
|
+
from: 0,
|
|
83439
|
+
to: 0
|
|
83440
|
+
};
|
|
83441
|
+
return {
|
|
83442
|
+
from: period_start(spec, anchor_ms).getTime(),
|
|
83443
|
+
to: period_shift(spec, anchor_ms, 1) - 1
|
|
83444
|
+
};
|
|
83445
|
+
}
|
|
83446
|
+
/***************************************************************
|
|
83447
|
+
* The same bucket, in the unit the CONSUMER speaks (a tranger topic
|
|
83448
|
+
* keeps its timestamps in seconds, unless its system_flag says
|
|
83449
|
+
* milliseconds). This is the function a query builder calls.
|
|
83450
|
+
***************************************************************/
|
|
83451
|
+
function period_bounds_epoch(period, anchor_ms, ms) {
|
|
83452
|
+
let b = period_bounds(period, anchor_ms);
|
|
83453
|
+
if (!b.from) return {
|
|
83454
|
+
from: 0,
|
|
83455
|
+
to: 0
|
|
83456
|
+
};
|
|
83457
|
+
return {
|
|
83458
|
+
from: ms_to_epoch(b.from, ms),
|
|
83459
|
+
to: ms_to_epoch(b.to, ms)
|
|
83460
|
+
};
|
|
83461
|
+
}
|
|
83462
|
+
/***************************************************************
|
|
83463
|
+
* A ROLLING window: `secs` back from now. Not a bucket — it has no
|
|
83464
|
+
* previous and no next, it just ends at `now`.
|
|
83465
|
+
*
|
|
83466
|
+
* The `to` end is left OPEN (0). An iterator with no upper bound keeps
|
|
83467
|
+
* matching the records that land while the card is on screen; pinning
|
|
83468
|
+
* it to "now" would freeze the window at the instant the user clicked.
|
|
83469
|
+
***************************************************************/
|
|
83470
|
+
function rolling_bounds(rolling, ms, now_ms) {
|
|
83471
|
+
let r = typeof rolling === "string" ? YUI_ROLLING[rolling] : rolling;
|
|
83472
|
+
if (!r || !r.secs) return {
|
|
83473
|
+
from: 0,
|
|
83474
|
+
to: 0
|
|
83475
|
+
};
|
|
83476
|
+
return {
|
|
83477
|
+
from: ms_to_epoch((now_ms === void 0 ? Date.now() : now_ms) - r.secs * 1e3, ms),
|
|
83478
|
+
to: 0
|
|
83479
|
+
};
|
|
83480
|
+
}
|
|
83481
|
+
/***************************************************************
|
|
83482
|
+
* Is this the LAST bucket — the one `now` falls in? It is what greys
|
|
83483
|
+
* out the "next" arrow, and what tells the navigator it is already home.
|
|
83484
|
+
***************************************************************/
|
|
83485
|
+
function is_current_period(period, anchor_ms, now_ms) {
|
|
83486
|
+
let spec = period_spec(period);
|
|
83487
|
+
if (!spec) return false;
|
|
83488
|
+
let now = now_ms === void 0 ? Date.now() : now_ms;
|
|
83489
|
+
let a = period_start(spec, anchor_ms);
|
|
83490
|
+
let b = period_start(spec, now);
|
|
83491
|
+
return !!a && !!b && a.getTime() === b.getTime();
|
|
83492
|
+
}
|
|
83493
|
+
/***************************************************************
|
|
83494
|
+
* Recognize the bucket a {from, to} pair came from, so a range that
|
|
83495
|
+
* travelled through a URL, a saved view or a backend answer comes back
|
|
83496
|
+
* as the period the user picked instead of as a hand-typed range.
|
|
83497
|
+
*
|
|
83498
|
+
* `from`/`to` are in the CONSUMER's unit (`ms`), and so is the
|
|
83499
|
+
* comparison — that is the whole trap: a bucket ends on the last
|
|
83500
|
+
* MILLISECOND (…23:59:59.999), and a consumer that keeps seconds stored
|
|
83501
|
+
* it truncated (…23:59:59). Comparing in milliseconds, a week saved by a
|
|
83502
|
+
* seconds-based topic came back as "no bucket at all", every time.
|
|
83503
|
+
*
|
|
83504
|
+
* Only an EXACT match counts: both ends must land on the bucket's own
|
|
83505
|
+
* boundaries, as that consumer would have written them. `candidates` are
|
|
83506
|
+
* ids/specs, tried in order. Returns {period, anchor} (anchor in ms) or
|
|
83507
|
+
* null.
|
|
83508
|
+
***************************************************************/
|
|
83509
|
+
function infer_period(from, to, candidates, ms) {
|
|
83510
|
+
if (!from || !to || to <= from) return null;
|
|
83511
|
+
let from_ms = epoch_to_ms(from, ms);
|
|
83512
|
+
for (let candidate of candidates || Object.keys(YUI_PERIODS)) {
|
|
83513
|
+
let spec = period_spec(candidate);
|
|
83514
|
+
if (!spec) continue;
|
|
83515
|
+
let b = period_bounds_epoch(spec, from_ms, ms);
|
|
83516
|
+
if (b.from === from && b.to === to) return {
|
|
83517
|
+
period: spec,
|
|
83518
|
+
anchor: from_ms
|
|
83519
|
+
};
|
|
83520
|
+
}
|
|
83521
|
+
return null;
|
|
83522
|
+
}
|
|
83523
|
+
/***************************
|
|
83524
|
+
* Period labels
|
|
83525
|
+
***************************/
|
|
83526
|
+
/***************************************************************
|
|
83527
|
+
* The name of a GRANULARITY (what the segmented control shows):
|
|
83528
|
+
* the spec's own id as an i18n key, so an app that declares
|
|
83529
|
+
* {id: "quarter"} gets "Trimestre" the moment it adds the key.
|
|
83530
|
+
***************************************************************/
|
|
83531
|
+
function period_name(period, t) {
|
|
83532
|
+
let spec = period_spec(period);
|
|
83533
|
+
if (!spec) return tr(t, String(period && period.id || period || ""));
|
|
83534
|
+
return tr(t, spec.id);
|
|
83535
|
+
}
|
|
83536
|
+
/***************************************************************
|
|
83537
|
+
* The name of the bucket a navigator is PARKED on: what goes between
|
|
83538
|
+
* the two arrows.
|
|
83539
|
+
*
|
|
83540
|
+
* day -> "Today" / "Yesterday" / "13 jul 2026"
|
|
83541
|
+
* week -> "Week 27" (+ year when it is not this one)
|
|
83542
|
+
* month -> "July" (+ year when it is not this one)
|
|
83543
|
+
* quarter -> "Q3 2026" (unit month, count 3)
|
|
83544
|
+
* semester -> "H2 2026" (unit month, count 6)
|
|
83545
|
+
* year -> "2026"
|
|
83546
|
+
* decade -> "2020 – 2029"
|
|
83547
|
+
* any other -> the bucket's own edges: "1 jul – 31 aug 2026"
|
|
83548
|
+
*
|
|
83549
|
+
* The named ones are named because a range reads worse than a name;
|
|
83550
|
+
* everything an app invents falls back to the range, which is always
|
|
83551
|
+
* true and never wrong.
|
|
83552
|
+
***************************************************************/
|
|
83553
|
+
function period_label(period, anchor_ms, t, locale) {
|
|
83554
|
+
let spec = period_spec(period);
|
|
83555
|
+
if (!spec) return "";
|
|
83556
|
+
let loc = safe_locale(locale);
|
|
83557
|
+
let start = period_start(spec, anchor_ms);
|
|
83558
|
+
let end = new Date(period_bounds(spec, anchor_ms).to);
|
|
83559
|
+
let now = /* @__PURE__ */ new Date();
|
|
83560
|
+
let this_year = start.getFullYear() === now.getFullYear();
|
|
83561
|
+
if (spec.unit === "day" && spec.count === 1) {
|
|
83562
|
+
let diff = day_number(start) - day_number(now);
|
|
83563
|
+
if (diff === 0) return tr(t, "today");
|
|
83564
|
+
if (diff === -1) return tr(t, "yesterday");
|
|
83565
|
+
if (diff === 1) return tr(t, "tomorrow");
|
|
83566
|
+
return fmt_intl(start, loc, this_year ? {
|
|
83567
|
+
day: "numeric",
|
|
83568
|
+
month: "short"
|
|
83569
|
+
} : {
|
|
83570
|
+
day: "numeric",
|
|
83571
|
+
month: "short",
|
|
83572
|
+
year: "numeric"
|
|
83573
|
+
});
|
|
83574
|
+
}
|
|
83575
|
+
if (spec.unit === "hour" && spec.count === 1) {
|
|
83576
|
+
let hh = fmt_intl(start, loc, {
|
|
83577
|
+
hour: "2-digit",
|
|
83578
|
+
minute: "2-digit"
|
|
83579
|
+
});
|
|
83580
|
+
if (day_number(start) === day_number(now)) return hh;
|
|
83581
|
+
return `${hh} · ${fmt_intl(start, loc, {
|
|
83582
|
+
day: "numeric",
|
|
83583
|
+
month: "short"
|
|
83584
|
+
})}`;
|
|
83585
|
+
}
|
|
83586
|
+
if (spec.unit === "week" && spec.count === 1) {
|
|
83587
|
+
let away = week_index(start) - week_index(now);
|
|
83588
|
+
if (away === 0) return tr(t, "this week");
|
|
83589
|
+
if (away === -1) return tr(t, "last week");
|
|
83590
|
+
let w = iso_week(start);
|
|
83591
|
+
return w.year === now.getFullYear() ? tr(t, "week {{n}}", { n: w.week }) : tr(t, "week {{n}} {{y}}", {
|
|
83592
|
+
n: w.week,
|
|
83593
|
+
y: w.year
|
|
83594
|
+
});
|
|
83595
|
+
}
|
|
83596
|
+
if (spec.unit === "month" && spec.count === 1) return fmt_intl(start, loc, this_year ? { month: "long" } : {
|
|
83597
|
+
month: "long",
|
|
83598
|
+
year: "numeric"
|
|
83599
|
+
});
|
|
83600
|
+
if (spec.unit === "month" && (spec.count === 3 || spec.count === 6)) {
|
|
83601
|
+
let n = Math.floor(start.getMonth() / spec.count) + 1;
|
|
83602
|
+
return tr(t, spec.count === 3 ? "quarter {{n}} {{y}}" : "semester {{n}} {{y}}", {
|
|
83603
|
+
n,
|
|
83604
|
+
y: start.getFullYear()
|
|
83605
|
+
});
|
|
83606
|
+
}
|
|
83607
|
+
if (spec.unit === "year") {
|
|
83608
|
+
if (spec.count === 1) return String(start.getFullYear());
|
|
83609
|
+
return `${start.getFullYear()} – ${end.getFullYear()}`;
|
|
83610
|
+
}
|
|
83611
|
+
let opts = spec.unit === "minute" || spec.unit === "hour" ? {
|
|
83612
|
+
day: "numeric",
|
|
83613
|
+
month: "short",
|
|
83614
|
+
hour: "2-digit",
|
|
83615
|
+
minute: "2-digit"
|
|
83616
|
+
} : {
|
|
83617
|
+
day: "numeric",
|
|
83618
|
+
month: "short"
|
|
83619
|
+
};
|
|
83620
|
+
if (start.getFullYear() !== end.getFullYear()) {
|
|
83621
|
+
let y_opts = Object.assign({ year: "numeric" }, opts);
|
|
83622
|
+
return `${fmt_intl(start, loc, y_opts)} – ${fmt_intl(end, loc, y_opts)}`;
|
|
83623
|
+
}
|
|
83624
|
+
let span = `${fmt_intl(start, loc, opts)} – ${fmt_intl(end, loc, opts)}`;
|
|
83625
|
+
return this_year ? span : `${span} ${start.getFullYear()}`;
|
|
83626
|
+
}
|
|
83627
|
+
//#endregion
|
|
83548
83628
|
//#region src/c_yui_period.js
|
|
83549
83629
|
/***********************************************************************
|
|
83550
83630
|
* c_yui_period.js
|